From 91fc042eb29dbc6ddaa7fc400099140974a6466b Mon Sep 17 00:00:00 2001 From: chemzqm Date: Mon, 23 Sep 2019 13:12:38 +0800 Subject: [PATCH] make useBatchedBufferSync used for update only Avoid issues with buffer reload by checktime. --- Readme.md | 2 +- package.json | 2 +- src/server/features/bufferSyncSupport.ts | 28 +++++------------------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/Readme.md b/Readme.md index a8651cc..9f1fcc5 100644 --- a/Readme.md +++ b/Readme.md @@ -74,6 +74,7 @@ this extension. - `tsserver.implicitProjectConfig.checkJs`:Enable checkJs for implicit project, default: `false` - `tsserver.implicitProjectConfig.experimentalDecorators`:Enable experimentalDecorators for implicit project, default: `false` - `tsserver.disableAutomaticTypeAcquisition`:Disable download of typings, default: `false` +- `tsserver.useBatchedBufferSync`: use batched buffer synchronize support. - `typescript.updateImportsOnFileMove.enable`:Enable update imports on file move., default: `true` - `typescript.implementationsCodeLens.enable`:Enable codeLens for implementations, default: `true` - `typescript.referencesCodeLens.enable`:Enable codeLens for references, default: `true` @@ -81,7 +82,6 @@ this extension. - `typescript.preferences.quoteStyle` default: `"single"` - `typescript.suggestionActions.enabled`:Enable/disable suggestion diagnostics for TypeScript files in the editor. Requires using TypeScript 2.8 or newer in the workspace., default: `true` - `typescript.validate.enable`:Enable/disable TypeScript validation., default: `true` -- `typescript.useBatchedBufferSync`: use batched buffer synchronize support. - `typescript.showUnused`: show unused variable hint, default: `true`. - `typescript.suggest.enabled` default: `true` - `typescript.suggest.paths`:Enable/disable suggest paths in import statement and require calls, default: `true` diff --git a/package.json b/package.json index d9d72f1..1bf7242 100644 --- a/package.json +++ b/package.json @@ -196,7 +196,7 @@ "default": false, "description": "Disable download of typings" }, - "typescript.useBatchedBufferSync": { + "tsserver.useBatchedBufferSync": { "type": "boolean", "default": true, "description": "Use batched buffer sync support." diff --git a/src/server/features/bufferSyncSupport.ts b/src/server/features/bufferSyncSupport.ts index 326c965..765cd32 100644 --- a/src/server/features/bufferSyncSupport.ts +++ b/src/server/features/bufferSyncSupport.ts @@ -46,30 +46,12 @@ class BufferSynchronizer { ) { } public open(args: Proto.OpenRequestArgs): void { - if (this.supportsBatching) { - this.updatePending(args.file, pending => { - if (!pending.openFiles) { - pending.openFiles = [] - } - pending.openFiles.push(args) - }) - } else { - this.client.executeWithoutWaitingForResponse('open', args) - } + this.client.executeWithoutWaitingForResponse('open', args) } public close(filepath: string): void { - if (this.supportsBatching) { - this.updatePending(filepath, pending => { - if (!pending.closedFiles) { - pending.closedFiles = [] - } - pending.closedFiles.push(filepath) - }) - } else { - const args: Proto.FileRequestArgs = { file: filepath } - this.client.executeWithoutWaitingForResponse('close', args) - } + const args: Proto.FileRequestArgs = { file: filepath } + this.client.executeWithoutWaitingForResponse('close', args) } public change(filepath: string, events: TextDocumentContentChangeEvent[]): void { @@ -116,7 +98,7 @@ class BufferSynchronizer { return } - if (this._pending.changedFiles || this._pending.closedFiles || this._pending.openFiles) { + if (this._pending.changedFiles) { this.client.executeWithoutWaitingForResponse('updateOpen', this._pending) this._pending = {} this._pendingFiles.clear() @@ -124,7 +106,7 @@ class BufferSynchronizer { } private get supportsBatching(): boolean { - return this.client.apiVersion.gte(API.v340) && workspace.getConfiguration('typescript').get('useBatchedBufferSync', true) + return this.client.apiVersion.gte(API.v340) && workspace.getConfiguration('tsserver').get('useBatchedBufferSync', true) } private updatePending(filepath: string, f: (pending: Proto.UpdateOpenRequestArgs) => void): void {