Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vscode watches for tsserver #193848

Merged
merged 28 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dc7891d
Use vscode watches for tsserver
sheetalkamat Jun 15, 2023
3a9bcf6
Merge branch 'main' into canUseWatchEvents
sheetalkamat Oct 11, 2023
e1ea8a5
Merge branch 'main' into canUseWatchEvents
bpasero Oct 12, 2023
a936df4
towards using new proposed watch API
bpasero Oct 12, 2023
bf56b37
Add setting and make sure to clear watchers
mjbvz Oct 18, 2023
90373b6
Merge branch 'main' into canUseWatchEvents
sheetalkamat Oct 18, 2023
9dea1ae
Merge branch 'main' into canUseWatchEvents
bpasero Feb 27, 2024
77d693d
fix bad merge
bpasero Feb 27, 2024
6ffc534
fix bad merge
bpasero Feb 27, 2024
5b070e4
more disposables work
bpasero Feb 27, 2024
c2d1bbd
use relative pattern everywhere
bpasero Feb 27, 2024
a3b6e59
Merge branch 'main' into canUseWatchEvents
bpasero Mar 10, 2024
ed23de6
Merge branch 'main' into canUseWatchEvents
bpasero Mar 13, 2024
5042fc0
Merge branch 'main' into canUseWatchEvents
bpasero Mar 13, 2024
dc712dc
Merge branch 'main' into canUseWatchEvents
bpasero Mar 14, 2024
18aca9d
Merge branch 'main' into canUseWatchEvents
bpasero Mar 23, 2024
a37cfa4
Add ignoreUpdate
sheetalkamat Mar 26, 2024
7273ebb
Merge branch 'main' into canUseWatchEvents
bpasero Mar 27, 2024
24679a7
Protocol changes for tsserver to batch the notifications
sheetalkamat Mar 27, 2024
342f77c
Merge branch 'main' into canUseWatchEvents
bpasero Mar 28, 2024
04bb6f6
add event aggregation
bpasero Mar 28, 2024
5ffe264
Update version numbers
mjbvz Mar 28, 2024
56b4e35
Aggregate events over multiple watchers
sheetalkamat Apr 2, 2024
f6ba53d
Merge branch 'main' into canUseWatchEvents
bpasero Apr 7, 2024
a16c6aa
Merge branch 'main' into canUseWatchEvents
bpasero Apr 9, 2024
1cd941e
:lipstick:
bpasero Apr 9, 2024
0a0d36e
fix todo
bpasero Apr 9, 2024
0dbdd58
enable in workspace
bpasero Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license": "MIT",
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
"enabledApiProposals": [
"workspaceTrust"
"workspaceTrust",
"createFileSystemWatcher"
],
"capabilities": {
"virtualWorkspaces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export enum EventName {
surveyReady = 'surveyReady',
projectLoadingStart = 'projectLoadingStart',
projectLoadingFinish = 'projectLoadingFinish',
createFileWatcher = 'createFileWatcher',
createDirectoryWatcher = 'createDirectoryWatcher',
closeFileWatcher = 'closeFileWatcher',
}

export enum OrganizeImportsMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export class TypeScriptServerSpawner {
args.push('--locale', TypeScriptServerSpawner.getTsLocale(configuration));

args.push('--noGetErrOnBackgroundUpdate');
args.push('--canUseWatchEvents'); // TODO check ts version

args.push('--validateDefaultNpmLocation');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ interface NoResponseTsServerRequests {
'compilerOptionsForInferredProjects': [Proto.SetCompilerOptionsForInferredProjectsArgs, null];
'reloadProjects': [null, null];
'configurePlugin': [Proto.ConfigurePluginRequest, Proto.ConfigurePluginResponse];
'watchChange': [Proto.Request, null];
}

interface AsyncTsServerRequests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export default class TypeScriptServiceClient extends Disposable implements IType
private readonly versionProvider: ITypeScriptVersionProvider;
private readonly processFactory: TsServerProcessFactory;

private readonly watches = new Map<number, vscode.FileSystemWatcher>();

constructor(
private readonly context: vscode.ExtensionContext,
onCaseInsenitiveFileSystem: boolean,
Expand Down Expand Up @@ -973,6 +975,46 @@ export default class TypeScriptServiceClient extends Disposable implements IType
case EventName.projectLoadingFinish:
this.loadingIndicator.finishedLoadingProject((event as Proto.ProjectLoadingFinishEvent).body.projectName);
break;

case EventName.createDirectoryWatcher:
this.createFileSystemWatcher(event.body.id, new vscode.RelativePattern(vscode.Uri.file(event.body.path), event.body.recursive ? '**' : '*'), [ /* TODO need to fill in excludes list */]);
bpasero marked this conversation as resolved.
Show resolved Hide resolved
break;

case EventName.createFileWatcher:
this.createFileSystemWatcher(event.body.id, event.body.path, []);
break;

case EventName.closeFileWatcher:
this.closeFileSystemWatcher(event.body.id);
break;
}
}

private createFileSystemWatcher(
id: number,
pattern: vscode.GlobPattern,
excludes: string[]
) {
const watcher = typeof pattern === 'string' ? vscode.workspace.createFileSystemWatcher(pattern) : vscode.workspace.createFileSystemWatcher(pattern, { excludes });
watcher.onDidChange(changeFile =>
this.executeWithoutWaitingForResponse('watchChange', { id, path: changeFile.fsPath, eventType: 'update' })
);
watcher.onDidCreate(createFile =>
this.executeWithoutWaitingForResponse('watchChange', { id, path: createFile.fsPath, eventType: 'create' })
);
watcher.onDidDelete(deletedFile =>
this.executeWithoutWaitingForResponse('watchChange', { id, path: deletedFile.fsPath, eventType: 'delete' })
);
this.watches.set(id, watcher);
}

private closeFileSystemWatcher(
id: number,
) {
const existing = this.watches.get(id);
if (existing) {
existing.dispose();
this.watches.delete(id);
}
}

Expand Down
3 changes: 2 additions & 1 deletion extensions/typescript-language-features/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"include": [
"src/**/*",
"../../src/vscode-dts/vscode.d.ts",
"../../src/vscode-dts/vscode.proposed.workspaceTrust.d.ts"
"../../src/vscode-dts/vscode.proposed.workspaceTrust.d.ts",
"../../src/vscode-dts/vscode.proposed.createFileSystemWatcher.d.ts"
]
}
Loading