Skip to content

Commit 41dbfaa

Browse files
Update logic for symbolic links to be backwards compatible
1 parent 8beff52 commit 41dbfaa

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

libs/shared/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './lib/clean-path';
33
export * from './lib/completion-trigger-characters.interface';
44
export * from './lib/dot-idl-folder.interface';
55
export * from './lib/envi-opener.interface';
6+
export * from './lib/get-canonical-path';
67
export * from './lib/get-extension-path';
78
export * from './lib/get-fs-path';
89
export * from './lib/idl-commands.interface';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { existsSync, realpathSync } from 'fs';
2+
3+
/**
4+
* Gets the canonical path for a file
5+
*
6+
* Handles special logic with "realpathSync" that needs to
7+
* have a file that exists on disk.
8+
*/
9+
export function GetCanonicalPath(fsPath: string) {
10+
return existsSync(fsPath) ? realpathSync(fsPath) : fsPath;
11+
}

libs/shared/src/lib/get-fs-path.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { realpathSync } from 'fs';
21
import { URI } from 'vscode-uri';
32

43
import { CleanPath } from './clean-path';
4+
import { GetCanonicalPath } from './get-canonical-path';
55

66
/**
77
* Parses a VSCode URI and returns the fully-qualified filepath on disk.
88
*
99
* Resolves symbolic links to get true paths on disk.
1010
*/
1111
export function GetFSPath(uri: string) {
12-
return realpathSync(CleanPath(URI.parse(uri).fsPath));
12+
/**
13+
* Get cleaned path for fil eon disk
14+
*/
15+
const cleaned = CleanPath(URI.parse(uri).fsPath);
16+
17+
// return canonical path for file on disk
18+
return GetCanonicalPath(cleaned);
1319
}

libs/vscode/client/src/lib/start-language-server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ALL_DOCUMENT_SELECTORS,
33
CleanPath,
4+
GetCanonicalPath,
45
IDL_LANGUAGE_NAME,
56
NODE_MEMORY_CONFIG,
67
NOTIFY_FILES_GLOB_PATTERN,
@@ -12,7 +13,7 @@ import { LANGUAGE_SERVER_MESSAGE_LOOKUP } from '@idl/vscode/events/messages';
1213
import { VSCodeTelemetryLogger } from '@idl/vscode/shared';
1314
import { execSync } from 'child_process';
1415
import { compare } from 'compare-versions';
15-
import { lstatSync, realpathSync } from 'fs';
16+
import { lstatSync } from 'fs';
1617
import * as path from 'path';
1718
import { ExtensionContext, workspace } from 'vscode';
1819
import {
@@ -290,8 +291,8 @@ export async function StartLanguageServer(ctx: ExtensionContext) {
290291
{
291292
files: event.files.map((item) => {
292293
return {
293-
oldUri: realpathSync(CleanPath(item.oldUri.fsPath)),
294-
newUri: realpathSync(CleanPath(item.newUri.fsPath)),
294+
oldUri: GetCanonicalPath(CleanPath(item.oldUri.fsPath)),
295+
newUri: GetCanonicalPath(CleanPath(item.newUri.fsPath)),
295296
};
296297
}),
297298
}

libs/vscode/server/src/lib/helpers/resolve-fspath-and-code-for-uri.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { CleanPath, IDLFileHelper } from '@idl/shared';
2-
import { realpathSync } from 'fs';
1+
import { GetFSPath, IDLFileHelper } from '@idl/shared';
32
import { URI } from 'vscode-uri';
43

54
import { NOTEBOOK_MANAGER } from '../events/initialize-notebook-manager';
@@ -25,7 +24,7 @@ export async function ResolveFSPathAndCodeForURI(
2524
/**
2625
* Get official FSPath for root file
2726
*/
28-
const fsPath = realpathSync(CleanPath(parsed.fsPath));
27+
const fsPath = GetFSPath(url);
2928

3029
/**
3130
* Check if PRO code

0 commit comments

Comments
 (0)