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 #2

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions build/lib/compilation.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/lib/compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function generateApiProposalNames() {
eol = os.EOL;
}

const pattern = /vscode\.proposed\.([a-zA-Z]+)\.d\.ts$/;
const pattern = /vscode\.proposed\.([a-zA-Z\d]+)\.d\.ts$/;
const proposalNames = new Set<string>();

const input = es.through();
Expand Down
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just

Suggested change
args.push('--canUseWatchEvents'); // TODO check ts version
if (apiVersion.gte(API.v520)) {
args.push('--canUseWatchEvents');
}

Since versions made using fromVersionString throw away pre-releases tags.


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 */]);
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"
]
}
1 change: 1 addition & 0 deletions src/vs/workbench/api/browser/extensionHost.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import './mainThreadLocalization';
import './mainThreadBulkEdits';
import './mainThreadChatProvider';
import './mainThreadChatAgents';
import './mainThreadChatAgents2';
import './mainThreadChatVariables';
import './mainThreadCodeInsets';
import './mainThreadCLICommands';
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/api/browser/mainThreadChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape {
provideWelcomeMessage: (token) => {
return this._proxy.$provideWelcomeMessage(handle, token);
},
provideSampleQuestions: (token) => {
return this._proxy.$provideSampleQuestions(handle, token);
},
provideSlashCommands: (session, token) => {
return this._proxy.$provideSlashCommands(handle, session.id, token);
},
Expand Down
49 changes: 29 additions & 20 deletions src/vs/workbench/api/browser/mainThreadChatAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { DisposableMap } from 'vs/base/common/lifecycle';
import { revive } from 'vs/base/common/marshalling';
import { IProgress } from 'vs/platform/progress/common/progress';
import { ExtHostChatAgentsShape, ExtHostContext, MainContext, MainThreadChatAgentsShape } from 'vs/workbench/api/common/extHost.protocol';
import { IChatAgentMetadata, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
import { IChatAgentCommand, IChatAgentMetadata, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
import { IChatProgress } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatSlashFragment } from 'vs/workbench/contrib/chat/common/chatSlashCommands';
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';

Expand All @@ -16,7 +17,7 @@ import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/ext
export class MainThreadChatAgents implements MainThreadChatAgentsShape {

private readonly _agents = new DisposableMap<number>;
private readonly _pendingProgress = new Map<number, IProgress<IChatSlashFragment>>();
private readonly _pendingProgress = new Map<number, IProgress<IChatProgress>>();
private readonly _proxy: ExtHostChatAgentsShape;

constructor(
Expand All @@ -34,29 +35,37 @@ export class MainThreadChatAgents implements MainThreadChatAgentsShape {
this._agents.clearAndDisposeAll();
}

$registerAgent(handle: number, name: string, metadata: IChatAgentMetadata): void {
if (!this._chatAgentService.hasAgent(name)) {
// dynamic!
this._chatAgentService.registerAgentData({
id: name,
metadata: revive(metadata)
});
}

const d = this._chatAgentService.registerAgentCallback(name, async (prompt, progress, history, token) => {
const requestId = Math.random();
this._pendingProgress.set(requestId, progress);
try {
return await this._proxy.$invokeAgent(handle, requestId, prompt, { history }, token);
} finally {
this._pendingProgress.delete(requestId);
}
$registerAgent(handle: number, name: string, metadata: IChatAgentMetadata & { subCommands: IChatAgentCommand[] }): void {
const d = this._chatAgentService.registerAgent({
id: name,
metadata: revive(metadata),
invoke: async (request, progress, history, token) => {
const requestId = Math.random();
this._pendingProgress.set(requestId, progress);
try {
const result = await this._proxy.$invokeAgent(handle, requestId, request.message, { history }, token);
return {
followUp: result?.followUp ?? [],
};
} finally {
this._pendingProgress.delete(requestId);
}
},
async provideSlashCommands() {
return metadata.subCommands;
},
});
this._agents.set(handle, d);
}

async $handleProgressChunk(requestId: number, chunk: IChatSlashFragment): Promise<void> {
this._pendingProgress.get(requestId)?.report(revive(chunk));
// An extra step because TS really struggles with type inference in the Revived generic parameter?
const revived = revive<IChatSlashFragment>(chunk);
if (typeof revived.content === 'string') {
this._pendingProgress.get(requestId)?.report({ content: revived.content });
} else {
this._pendingProgress.get(requestId)?.report(revived.content);
}
}

$unregisterCommand(handle: number): void {
Expand Down
80 changes: 80 additions & 0 deletions src/vs/workbench/api/browser/mainThreadChatAgents2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { DisposableMap, IDisposable } from 'vs/base/common/lifecycle';
import { revive } from 'vs/base/common/marshalling';
import { IProgress } from 'vs/platform/progress/common/progress';
import { ExtHostChatAgentsShape2, ExtHostContext, IChatResponseProgressDto, IExtensionChatAgentMetadata, MainContext, MainThreadChatAgentsShape2 } from 'vs/workbench/api/common/extHost.protocol';
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
import { IChatProgress } from 'vs/workbench/contrib/chat/common/chatService';
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers';


type AgentData = {
dispose: () => void;
name: string;
hasSlashCommands?: boolean;
hasFollowups?: boolean;
};

@extHostNamedCustomer(MainContext.MainThreadChatAgents2)
export class MainThreadChatAgents implements MainThreadChatAgentsShape2, IDisposable {

private readonly _agents = new DisposableMap<number, AgentData>;
private readonly _pendingProgress = new Map<number, IProgress<IChatProgress>>();
private readonly _proxy: ExtHostChatAgentsShape2;

constructor(
extHostContext: IExtHostContext,
@IChatAgentService private readonly _chatAgentService: IChatAgentService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostChatAgents2);
}

$unregisterAgent(handle: number): void {
this._agents.deleteAndDispose(handle);
}

dispose(): void {
this._agents.clearAndDisposeAll();
}

$registerAgent(handle: number, name: string, metadata: IExtensionChatAgentMetadata): void {
const d = this._chatAgentService.registerAgent({
id: name,
metadata: revive(metadata),
invoke: async (request, progress, history, token) => {
const requestId = Math.random(); // Make this a guid
this._pendingProgress.set(requestId, progress);
try {
return await this._proxy.$invokeAgent(handle, requestId, request, { history }, token) ?? {};
} finally {
this._pendingProgress.delete(requestId);
}
},
provideSlashCommands: async (token) => {
if (!this._agents.get(handle)?.hasSlashCommands) {
return []; // safe an IPC call
}
return this._proxy.$provideSlashCommands(handle, token);
}
});
this._agents.set(handle, { name, dispose: d.dispose, hasSlashCommands: metadata.hasSlashCommands });
}

$updateAgent(handle: number, metadataUpdate: IExtensionChatAgentMetadata): void {
const data = this._agents.get(handle);
if (!data) {
throw new Error(`No agent with handle ${handle} registered`);
}
data.hasSlashCommands = metadataUpdate.hasSlashCommands;
this._chatAgentService.updateAgent(data.name, revive(metadataUpdate));
}

async $handleProgressChunk(requestId: number, chunk: IChatResponseProgressDto): Promise<void> {
// TODO copy/move $acceptResponseProgress from MainThreadChat
this._pendingProgress.get(requestId)?.report(revive(chunk) as any);
}
}
7 changes: 6 additions & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { ExtHostChatVariables } from 'vs/workbench/api/common/extHostChatVariabl
import { ExtHostRelatedInformation } from 'vs/workbench/api/common/extHostAiRelatedInformation';
import { ExtHostAiEmbeddingVector } from 'vs/workbench/api/common/extHostEmbeddingVector';
import { ExtHostChatAgents } from 'vs/workbench/api/common/extHostChatAgents';
import { ExtHostChatAgents2 } from 'vs/workbench/api/common/extHostChatAgents2';

export interface IExtensionRegistries {
mine: ExtensionDescriptionRegistry;
Expand Down Expand Up @@ -209,6 +210,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const extHostInteractiveEditor = rpcProtocol.set(ExtHostContext.ExtHostInlineChat, new ExtHostInteractiveEditor(rpcProtocol, extHostCommands, extHostDocuments, extHostLogService));
const extHostChatProvider = rpcProtocol.set(ExtHostContext.ExtHostChatProvider, new ExtHostChatProvider(rpcProtocol, extHostLogService));
const extHostChatAgents = rpcProtocol.set(ExtHostContext.ExtHostChatAgents, new ExtHostChatAgents(rpcProtocol, extHostChatProvider, extHostLogService));
const extHostChatAgents2 = rpcProtocol.set(ExtHostContext.ExtHostChatAgents2, new ExtHostChatAgents2(rpcProtocol, extHostChatProvider, extHostLogService));
const extHostChatVariables = rpcProtocol.set(ExtHostContext.ExtHostChatVariables, new ExtHostChatVariables(rpcProtocol));
const extHostChat = rpcProtocol.set(ExtHostContext.ExtHostChat, new ExtHostChat(rpcProtocol, extHostLogService));
const extHostAiRelatedInformation = rpcProtocol.set(ExtHostContext.ExtHostAiRelatedInformation, new ExtHostRelatedInformation(rpcProtocol));
Expand Down Expand Up @@ -1366,11 +1368,14 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension, 'mappedEditsProvider');
return extHostLanguageFeatures.registerMappedEditsProvider(extension, selector, provider);
},
createChatAgent(name: string, handler: vscode.ChatAgentHandler) {
checkProposedApiEnabled(extension, 'chatAgents2');
return extHostChatAgents2.createChatAgent(extension.identifier, name, handler);
},
registerAgent(name: string, agent: vscode.ChatAgent, metadata: vscode.ChatAgentMetadata) {
checkProposedApiEnabled(extension, 'chatAgents');
return extHostChatAgents.registerAgent(extension.identifier, name, agent, metadata);
}

};

return <typeof vscode>{
Expand Down
25 changes: 23 additions & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import * as tasks from 'vs/workbench/api/common/shared/tasks';
import { SaveReason } from 'vs/workbench/common/editor';
import { IRevealOptions, ITreeItem, IViewBadge } from 'vs/workbench/common/views';
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { IChatAgentMetadata } from 'vs/workbench/contrib/chat/common/chatAgents';
import { IChatAgentCommand, IChatAgentMetadata, IChatAgentRequest, IChatAgentResult } from 'vs/workbench/contrib/chat/common/chatAgents';
import { IChatMessage, IChatResponseFragment, IChatResponseProviderMetadata } from 'vs/workbench/contrib/chat/common/chatProvider';
import { IChatDynamicRequest, IChatFollowup, IChatReplyFollowup, IChatResponseErrorDetails, IChatUserActionEvent, ISlashCommand } from 'vs/workbench/contrib/chat/common/chatService';
import { IChatSlashFragment } from 'vs/workbench/contrib/chat/common/chatSlashCommands';
Expand Down Expand Up @@ -1147,15 +1147,33 @@ export interface ExtHostChatProviderShape {
}

export interface MainThreadChatAgentsShape extends IDisposable {
$registerAgent(handle: number, name: string, metadata: IChatAgentMetadata): void;
$registerAgent(handle: number, name: string, metadata: IChatAgentMetadata & { subCommands: IChatAgentCommand[] }): void;
$unregisterAgent(handle: number): void;
$handleProgressChunk(requestId: number, chunk: IChatSlashFragment): Promise<void>;
}

export interface IExtensionChatAgentMetadata extends Dto<IChatAgentMetadata> {
hasSlashCommands?: boolean;
hasFollowup?: boolean;
}

export interface MainThreadChatAgentsShape2 extends IDisposable {
$registerAgent(handle: number, name: string, metadata: IExtensionChatAgentMetadata): void;
$updateAgent(handle: number, metadataUpdate: IExtensionChatAgentMetadata): void;
$unregisterAgent(handle: number): void;
$handleProgressChunk(requestId: number, chunk: IChatResponseProgressDto): Promise<void>;
}

export interface ExtHostChatAgentsShape {
$invokeAgent(handle: number, requestId: number, prompt: string, context: { history: IChatMessage[] }, token: CancellationToken): Promise<any>;
}

export interface ExtHostChatAgentsShape2 {
$invokeAgent(handle: number, requestId: number, request: IChatAgentRequest, context: { history: IChatMessage[] }, token: CancellationToken): Promise<IChatAgentResult | undefined>;
$provideSlashCommands(handle: number, token: CancellationToken): Promise<IChatAgentCommand[]>;
$provideFollowups(handle: number, requestId: number, token: CancellationToken): Promise<IChatFollowup[]>;
}

export interface MainThreadChatVariablesShape extends IDisposable {
$registerVariable(handle: number, data: IChatVariableData): void;
$unregisterVariable(handle: number): void;
Expand Down Expand Up @@ -1241,6 +1259,7 @@ export interface MainThreadChatShape extends IDisposable {
export interface ExtHostChatShape {
$prepareChat(handle: number, initialState: any, token: CancellationToken): Promise<IChatDto | undefined>;
$provideWelcomeMessage(handle: number, token: CancellationToken): Promise<(string | IChatReplyFollowup[])[] | undefined>;
$provideSampleQuestions(handle: number, token: CancellationToken): Promise<IChatReplyFollowup[] | undefined>;
$provideFollowups(handle: number, sessionId: number, token: CancellationToken): Promise<IChatFollowup[] | undefined>;
$provideReply(handle: number, sessionId: number, request: IChatRequestDto, token: CancellationToken): Promise<IChatResponseDto | undefined>;
$removeRequest(handle: number, sessionId: number, requestId: string): void;
Expand Down Expand Up @@ -2664,6 +2683,7 @@ export const MainContext = {
MainThreadBulkEdits: createProxyIdentifier<MainThreadBulkEditsShape>('MainThreadBulkEdits'),
MainThreadChatProvider: createProxyIdentifier<MainThreadChatProviderShape>('MainThreadChatProvider'),
MainThreadChatAgents: createProxyIdentifier<MainThreadChatAgentsShape>('MainThreadChatAgents'),
MainThreadChatAgents2: createProxyIdentifier<MainThreadChatAgentsShape2>('MainThreadChatAgents2'),
MainThreadChatVariables: createProxyIdentifier<MainThreadChatVariablesShape>('MainThreadChatVariables'),
MainThreadClipboard: createProxyIdentifier<MainThreadClipboardShape>('MainThreadClipboard'),
MainThreadCommands: createProxyIdentifier<MainThreadCommandsShape>('MainThreadCommands'),
Expand Down Expand Up @@ -2785,6 +2805,7 @@ export const ExtHostContext = {
ExtHostInlineChat: createProxyIdentifier<ExtHostInlineChatShape>('ExtHostInlineChatShape'),
ExtHostChat: createProxyIdentifier<ExtHostChatShape>('ExtHostChat'),
ExtHostChatAgents: createProxyIdentifier<ExtHostChatAgentsShape>('ExtHostChatAgents'),
ExtHostChatAgents2: createProxyIdentifier<ExtHostChatAgentsShape2>('ExtHostChatAgents'),
ExtHostChatVariables: createProxyIdentifier<ExtHostChatVariablesShape>('ExtHostChatVariables'),
ExtHostChatProvider: createProxyIdentifier<ExtHostChatProviderShape>('ExtHostChatProvider'),
ExtHostAiRelatedInformation: createProxyIdentifier<ExtHostAiRelatedInformationShape>('ExtHostAiRelatedInformation'),
Expand Down
Loading