Skip to content

Commit ea7d830

Browse files
authored
Fix some errors for project wide JS/TS IntelliSense (microsoft#183482)
- Don't compute `semanticSupportedSchemes` early, as this may be incorrect if the script is loaded before there are workspace folders - Handle exceptions when watching files by logging them but not crashing the server
1 parent 110b684 commit ea7d830

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

extensions/typescript-language-features/src/configuration/fileSchemes.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ export const memFs = 'memfs';
1919
export const vscodeVfs = 'vscode-vfs';
2020
export const officeScript = 'office-script';
2121

22-
export const semanticSupportedSchemes = isWeb() && vscode.workspace.workspaceFolders ?
23-
vscode.workspace.workspaceFolders.map(folder => folder.uri.scheme) : [
22+
export function getSemanticSupportedSchemes() {
23+
if (isWeb() && vscode.workspace.workspaceFolders) {
24+
return vscode.workspace.workspaceFolders.map(folder => folder.uri.scheme);
25+
}
26+
27+
return [
2428
file,
2529
untitled,
2630
walkThroughSnippet,
2731
vscodeNotebookCell,
2832
];
33+
}
2934

3035
/**
3136
* File scheme for which JS/TS language feature should be disabled

extensions/typescript-language-features/src/languageProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class LanguageProvider extends Disposable {
4646
const syntax: vscode.DocumentFilter[] = [];
4747
for (const language of this.description.languageIds) {
4848
syntax.push({ language });
49-
for (const scheme of fileSchemes.semanticSupportedSchemes) {
49+
for (const scheme of fileSchemes.getSemanticSupportedSchemes()) {
5050
semantic.push({ language, scheme });
5151
}
5252
}

extensions/typescript-language-features/src/typescriptServiceClient.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,13 @@ export default class TypeScriptServiceClient extends Disposable implements IType
719719
}
720720

721721
switch (capability) {
722-
case ClientCapability.Semantic:
723-
{
724-
return fileSchemes.semanticSupportedSchemes.includes(resource.scheme);
725-
}
722+
case ClientCapability.Semantic: {
723+
return fileSchemes.getSemanticSupportedSchemes().includes(resource.scheme);
724+
}
726725
case ClientCapability.Syntax:
727-
case ClientCapability.EnhancedSyntax:
728-
{
729-
return true;
730-
}
726+
case ClientCapability.EnhancedSyntax: {
727+
return true;
728+
}
731729
}
732730
}
733731

extensions/typescript-language-features/web/webServer.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,26 @@ function createServerHost(extensionUri: URI, logger: ts.server.Logger, apiClient
9595
const logNormal = log.bind(null, ts.server.LogLevel.normal);
9696
const logVerbose = log.bind(null, ts.server.LogLevel.verbose);
9797

98+
const noopWatcher: ts.FileWatcher = { close() { } };
9899
return {
99100
watchFile(path: string, callback: ts.FileWatcherCallback, pollingInterval?: number, options?: ts.WatchOptions): ts.FileWatcher {
100101
if (looksLikeLibDtsPath(path)) { // We don't support watching lib files on web since they are readonly
101-
return { close() { } };
102+
return noopWatcher;
102103
}
103104

104105
logVerbose('fs.watchFile', { path });
105106

107+
let uri: URI;
108+
try {
109+
uri = toResource(path);
110+
} catch (e) {
111+
console.error(e);
112+
return noopWatcher;
113+
}
114+
106115
watchFiles.set(path, { path, callback, pollingInterval, options });
107116
watchId++;
108-
fsWatcher.postMessage({ type: 'watchFile', uri: toResource(path), id: watchId });
117+
fsWatcher.postMessage({ type: 'watchFile', uri, id: watchId });
109118
return {
110119
close() {
111120
logVerbose('fs.watchFile.close', { path });
@@ -118,9 +127,17 @@ function createServerHost(extensionUri: URI, logger: ts.server.Logger, apiClient
118127
watchDirectory(path: string, callback: ts.DirectoryWatcherCallback, recursive?: boolean, options?: ts.WatchOptions): ts.FileWatcher {
119128
logVerbose('fs.watchDirectory', { path });
120129

130+
let uri: URI;
131+
try {
132+
uri = toResource(path);
133+
} catch (e) {
134+
console.error(e);
135+
return noopWatcher;
136+
}
137+
121138
watchDirectories.set(path, { path, callback, recursive, options });
122139
watchId++;
123-
fsWatcher.postMessage({ type: 'watchDirectory', recursive, uri: toResource(path), id: watchId });
140+
fsWatcher.postMessage({ type: 'watchDirectory', recursive, uri, id: watchId });
124141
return {
125142
close() {
126143
logVerbose('fs.watchDirectory.close', { path });

0 commit comments

Comments
 (0)