Fix some errors for project wide JS/TS IntelliSense (#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
This commit is contained in:
Matt Bierner 2023-05-25 18:43:46 -07:00 committed by GitHub
parent 110b68473b
commit ea7d830fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 14 deletions

View file

@ -19,13 +19,18 @@ export const memFs = 'memfs';
export const vscodeVfs = 'vscode-vfs';
export const officeScript = 'office-script';
export const semanticSupportedSchemes = isWeb() && vscode.workspace.workspaceFolders ?
vscode.workspace.workspaceFolders.map(folder => folder.uri.scheme) : [
export function getSemanticSupportedSchemes() {
if (isWeb() && vscode.workspace.workspaceFolders) {
return vscode.workspace.workspaceFolders.map(folder => folder.uri.scheme);
}
return [
file,
untitled,
walkThroughSnippet,
vscodeNotebookCell,
];
}
/**
* File scheme for which JS/TS language feature should be disabled

View file

@ -46,7 +46,7 @@ export default class LanguageProvider extends Disposable {
const syntax: vscode.DocumentFilter[] = [];
for (const language of this.description.languageIds) {
syntax.push({ language });
for (const scheme of fileSchemes.semanticSupportedSchemes) {
for (const scheme of fileSchemes.getSemanticSupportedSchemes()) {
semantic.push({ language, scheme });
}
}

View file

@ -719,15 +719,13 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
switch (capability) {
case ClientCapability.Semantic:
{
return fileSchemes.semanticSupportedSchemes.includes(resource.scheme);
}
case ClientCapability.Semantic: {
return fileSchemes.getSemanticSupportedSchemes().includes(resource.scheme);
}
case ClientCapability.Syntax:
case ClientCapability.EnhancedSyntax:
{
return true;
}
case ClientCapability.EnhancedSyntax: {
return true;
}
}
}

View file

@ -95,17 +95,26 @@ function createServerHost(extensionUri: URI, logger: ts.server.Logger, apiClient
const logNormal = log.bind(null, ts.server.LogLevel.normal);
const logVerbose = log.bind(null, ts.server.LogLevel.verbose);
const noopWatcher: ts.FileWatcher = { close() { } };
return {
watchFile(path: string, callback: ts.FileWatcherCallback, pollingInterval?: number, options?: ts.WatchOptions): ts.FileWatcher {
if (looksLikeLibDtsPath(path)) { // We don't support watching lib files on web since they are readonly
return { close() { } };
return noopWatcher;
}
logVerbose('fs.watchFile', { path });
let uri: URI;
try {
uri = toResource(path);
} catch (e) {
console.error(e);
return noopWatcher;
}
watchFiles.set(path, { path, callback, pollingInterval, options });
watchId++;
fsWatcher.postMessage({ type: 'watchFile', uri: toResource(path), id: watchId });
fsWatcher.postMessage({ type: 'watchFile', uri, id: watchId });
return {
close() {
logVerbose('fs.watchFile.close', { path });
@ -118,9 +127,17 @@ function createServerHost(extensionUri: URI, logger: ts.server.Logger, apiClient
watchDirectory(path: string, callback: ts.DirectoryWatcherCallback, recursive?: boolean, options?: ts.WatchOptions): ts.FileWatcher {
logVerbose('fs.watchDirectory', { path });
let uri: URI;
try {
uri = toResource(path);
} catch (e) {
console.error(e);
return noopWatcher;
}
watchDirectories.set(path, { path, callback, recursive, options });
watchId++;
fsWatcher.postMessage({ type: 'watchDirectory', recursive, uri: toResource(path), id: watchId });
fsWatcher.postMessage({ type: 'watchDirectory', recursive, uri, id: watchId });
return {
close() {
logVerbose('fs.watchDirectory.close', { path });