From 84309083d13127ce78c9dc1ac24e2ace1cdc48aa Mon Sep 17 00:00:00 2001 From: Heyward Fann Date: Sat, 30 Jul 2022 00:43:59 +0800 Subject: [PATCH 01/18] feat(commands): Go to Source Definition (#384) --- package.json | 14 +++++++----- src/server/commands.ts | 50 +++++++++++++++++++++++++++++++++++++++++ src/server/index.ts | 3 ++- src/server/utils/api.ts | 1 + 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 749c97c..c8b6b4c 100644 --- a/package.json +++ b/package.json @@ -30,11 +30,10 @@ "onLanguage:jsx-tags", "onLanguage:jsonc", "onCommand:_typescript.configurePlugin", - "onCommand:typescript.reloadProjects", - "onCommand:javascript.reloadProjects", - "onCommand:javascript.goToProjectConfig", - "onCommand:typescript.goToProjectConfig", - "onCommand:typescript.openTsServerLog", + "onCommand:tsserver.reloadProjects", + "onCommand:tsserver.goToProjectConfig", + "onCommand:tsserver.openTsServerLog", + "onCommand:tsserver.goToSourceDefinition", "onCommand:tsserver.watchBuild" ], "contributes": { @@ -94,6 +93,11 @@ "category": "TSServer", "command": "tsserver.findAllFileReferences" }, + { + "command": "tsserver.goToSourceDefinition", + "title": "Go to Source Definition", + "category": "TSServer" + }, { "title": "Run `tsc --watch` for current project by use vim's job feature.", "category": "TSServer", diff --git a/src/server/commands.ts b/src/server/commands.ts index 6d99712..3e50184 100644 --- a/src/server/commands.ts +++ b/src/server/commands.ts @@ -218,6 +218,56 @@ export class FileReferencesCommand implements Command { } } +export class SourceDefinitionCommand implements Command { + public static readonly context = 'tsSupportsSourceDefinition' + public static readonly minVersion = API.v470 + + public readonly id = 'tsserver.goToSourceDefinition' + + public constructor(private readonly service: TsserverService) {} + + public async execute() { + const client = await this.service.getClientHost() + if (client.serviceClient.apiVersion.lt(SourceDefinitionCommand.minVersion)) { + window.showErrorMessage('Go to Source Definition failed. Requires TypeScript 4.7+.') + return + } + + const { document, position } = await workspace.getCurrentState() + if (client.serviceClient.modeIds.indexOf(document.languageId) == -1) { + window.showErrorMessage('Go to Source Definition failed. Unsupported file type.') + return + } + const openedFiledPath = client.serviceClient.toOpenedFilePath(document.uri) + if (!openedFiledPath) { + window.showErrorMessage('Go to Source Definition failed. Unknown file type.') + return + } + + await window.withProgress({ title: 'Finding source definitions' }, async (_progress, token) => { + + const args = typeConverters.Position.toFileLocationRequestArgs(openedFiledPath, position) + const response = await client.serviceClient.execute('findSourceDefinition', args, token) + if (response.type === 'response' && response.body) { + const locations: Location[] = (response as Proto.DefinitionResponse).body.map(reference => + typeConverters.Location.fromTextSpan(client.serviceClient.toResource(reference.file), reference)) + + if (locations.length) { + commands.executeCommand('editor.action.showReferences', document.uri, position, locations) + // if (locations.length === 1) { + // commands.executeCommand('vscode.open', locations[0].uri) + // } else { + // commands.executeCommand('editor.action.showReferences', document.uri, position, locations) + // } + return + } + } + + window.showErrorMessage('No source definitions found.') + }) + } +} + export function registCommand(cmd: Command): Disposable { let { id, execute } = cmd return commands.registerCommand(id as string, execute, cmd) diff --git a/src/server/index.ts b/src/server/index.ts index 2d42456..108bf75 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,7 +1,7 @@ import { commands, disposeAll, IServiceProvider, ServiceStat, workspace, WorkspaceConfiguration } from 'coc.nvim' import { Disposable, DocumentSelector, Emitter, Event } from 'vscode-languageserver-protocol' import { PluginManager } from '../utils/plugins' -import { AutoFixCommand, Command, ConfigurePluginCommand, FileReferencesCommand, OpenTsServerLogCommand, ReloadProjectsCommand, TypeScriptGoToProjectConfigCommand } from './commands' +import { AutoFixCommand, Command, ConfigurePluginCommand, FileReferencesCommand, OpenTsServerLogCommand, ReloadProjectsCommand, SourceDefinitionCommand, TypeScriptGoToProjectConfigCommand } from './commands' import { OrganizeImportsCommand, SourceImportsCommand } from './organizeImports' import TypeScriptServiceClientHost from './typescriptServiceClientHost' import { LanguageDescription, standardLanguageDescriptions } from './utils/languageDescription' @@ -69,6 +69,7 @@ export default class TsserverService implements IServiceProvider { registCommand(new TypeScriptGoToProjectConfigCommand(this)) registCommand(new OrganizeImportsCommand(this)) registCommand(new SourceImportsCommand(this)) + registCommand(new SourceDefinitionCommand(this)) registCommand({ id: 'tsserver.restart', execute: (): void => { diff --git a/src/server/utils/api.ts b/src/server/utils/api.ts index 0dce70a..8331a5a 100644 --- a/src/server/utils/api.ts +++ b/src/server/utils/api.ts @@ -44,6 +44,7 @@ export default class API { public static readonly v420 = API.fromSimpleString('4.2.0') public static readonly v430 = API.fromSimpleString('4.3.0') public static readonly v440 = API.fromSimpleString('4.4.0') + public static readonly v470 = API.fromSimpleString('4.7.0') public static fromVersionString(versionString: string): API { let version = semver.valid(versionString) From 8234e83f9270baecb4358b279e7e2ce258f2bee9 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Sat, 30 Jul 2022 00:46:28 +0800 Subject: [PATCH 02/18] Release 1.11.0 --- history.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/history.md b/history.md index a9a19c7..84ea422 100644 --- a/history.md +++ b/history.md @@ -1,3 +1,7 @@ +# 1.11.0 + +- Add command `tsserver.goToSourceDefinition`. + # 1.10.5 - Fix a fold issue #380 diff --git a/package.json b/package.json index c8b6b4c..6efb27e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.10.5", + "version": "1.11.0", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From 4571c863ad692d7002123fc6774338f6d5713b49 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Sun, 31 Jul 2022 18:34:26 +0800 Subject: [PATCH 03/18] avoid unload new document on rename --- src/server/features/updatePathOnRename.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/features/updatePathOnRename.ts b/src/server/features/updatePathOnRename.ts index fb783f3..c7500f3 100644 --- a/src/server/features/updatePathOnRename.ts +++ b/src/server/features/updatePathOnRename.ts @@ -61,11 +61,11 @@ export default class UpdateImportsOnFileRenameHandler { await workspace.nvim.command(`silent ${oldDocument.bufnr}bwipeout!`) } let document = workspace.getDocument(newUri) - if (document) { - await workspace.nvim.command(`silent ${document.bufnr}bwipeout!`) - await wait(30) + if (!document) { + document = await workspace.loadFile(newUri) + } else { + workspace.nvim.command('checktime', true) } - document = await workspace.loadFile(newUri) if (!document) return await wait(50) const edits = await this.getEditsForFileRename( From c4e4ef2a8cdbe341beb441f946adc7006ecc9942 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Sun, 31 Jul 2022 18:36:56 +0800 Subject: [PATCH 04/18] Release 1.11.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6efb27e..7214741 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.0", + "version": "1.11.1", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From ad249ad817bfdff13ec405e7e3782f34a082ce5d Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 8 Aug 2022 22:41:10 +0800 Subject: [PATCH 05/18] change minimal coc.nvim version to 0.0.82 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7214741..cf9e7ff 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "publisher": "chemzqm", "engines": { - "coc": "^0.0.80" + "coc": "^0.0.82" }, "repository": { "type": "git", From 4bc14d7ce252b6548113cfadb278fb51a247ea84 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 8 Aug 2022 22:41:36 +0800 Subject: [PATCH 06/18] Release 1.11.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf9e7ff..af8fc22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.1", + "version": "1.11.2", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From 156fe981c77725a90eb1591baba8304f3323a3f3 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 15 Aug 2022 16:28:28 +0800 Subject: [PATCH 07/18] fix watchBuild not work before service start Closes #390 --- src/server/features/watchBuild.ts | 126 --------------------- src/server/index.ts | 10 ++ src/server/typescriptServiceClientHost.ts | 2 - src/server/watchBuild.ts | 129 ++++++++++++++++++++++ 4 files changed, 139 insertions(+), 128 deletions(-) create mode 100644 src/server/watchBuild.ts diff --git a/src/server/features/watchBuild.ts b/src/server/features/watchBuild.ts index 7ea12c3..e69de29 100644 --- a/src/server/features/watchBuild.ts +++ b/src/server/features/watchBuild.ts @@ -1,126 +0,0 @@ -import { commands, Disposable, disposeAll, StatusBarItem, TaskOptions, Uri, window, workspace } from 'coc.nvim' -import path from 'path' -import TypeScriptServiceClient from '../typescriptServiceClient' - -const countRegex = /Found\s+(\d+)\s+error/ -const errorRegex = /^(.+)\((\d+),(\d+)\):\s(\w+)\sTS(\d+):\s*(.+)$/ - -export default class WatchProject implements Disposable { - private disposables: Disposable[] = [] - public static readonly id: string = 'tsserver.watchBuild' - public static readonly startTexts: string[] = ['Starting compilation in watch mode', 'Starting incremental compilation'] - private statusItem: StatusBarItem - private task: any - private options: TaskOptions - - public constructor( - private client: TypeScriptServiceClient - ) { - this.statusItem = window.createStatusBarItem(1, { progress: true }) - let task = this.task = workspace.createTask('TSC') - - this.disposables.push(commands.registerCommand(WatchProject.id, async () => { - let opts = this.options = await this.getOptions() - await this.start(opts) - })) - task.onExit(code => { - if (code != 0) { - window.showMessage(`TSC exit with code ${code}`, 'warning') - } - this.onStop() - }) - task.onStdout(lines => { - for (let line of lines) { - this.onLine(line) - } - }) - task.onStderr(lines => { - window.showMessage(`TSC error: ` + lines.join('\n'), 'error') - }) - this.disposables.push(Disposable.create(() => { - task.dispose() - })) - this.check().catch(_e => { - // noop - }) - } - - private async check(): Promise { - let running = await this.task.running - if (running) { - this.options = await this.getOptions() - this.statusItem.isProgress = false - this.statusItem.text = '?' - this.statusItem.show() - } else { - this.onStop() - } - } - - private async start(options: TaskOptions): Promise { - await this.task.start(options) - } - - private onStop(): void { - this.statusItem.hide() - } - - private onStart(): void { - this.statusItem.text = 'compiling' - this.statusItem.isProgress = true - this.statusItem.show() - workspace.nvim.call('setqflist', [[]], true) - } - - private onLine(line: string): void { - if (countRegex.test(line)) { - let ms = line.match(countRegex) - this.statusItem.text = ms[1] == '0' ? '✓' : '✗' - this.statusItem.isProgress = false - } else if (WatchProject.startTexts.findIndex(s => line.indexOf(s) !== -1) != -1) { - this.onStart() - } else { - let ms = line.match(errorRegex) - if (!ms) return - let fullpath = path.join(this.options.cwd, ms[1]) - let uri = Uri.file(fullpath).toString() - let doc = workspace.getDocument(uri) - let bufnr = doc ? doc.bufnr : null - let item = { - filename: fullpath, - lnum: Number(ms[2]), - col: Number(ms[3]), - text: `[tsc ${ms[5]}] ${ms[6]}`, - type: /error/i.test(ms[4]) ? 'E' : 'W' - } as any - if (bufnr) item.bufnr = bufnr - workspace.nvim.call('setqflist', [[item], 'a']) - } - } - - public async getOptions(): Promise { - let { tscPath } = this.client - if (!tscPath) { - window.showMessage(`Local & global tsc not found`, 'error') - return - } - - const tsconfigPath = workspace.getConfiguration('tsserver').get('tsconfigPath', 'tsconfig.json') - let find = await workspace.findUp([tsconfigPath]) - if (!find) { - window.showMessage(`${tsconfigPath} not found!`, 'error') - return - } - - let root = path.dirname(find) - return { - cmd: tscPath, - args: ['-p', tsconfigPath, '--watch', 'true', '--pretty', 'false'], - cwd: root - } - } - - public dispose(): void { - disposeAll(this.disposables) - } -} diff --git a/src/server/index.ts b/src/server/index.ts index 108bf75..032c0c2 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -3,6 +3,7 @@ import { Disposable, DocumentSelector, Emitter, Event } from 'vscode-languageser import { PluginManager } from '../utils/plugins' import { AutoFixCommand, Command, ConfigurePluginCommand, FileReferencesCommand, OpenTsServerLogCommand, ReloadProjectsCommand, SourceDefinitionCommand, TypeScriptGoToProjectConfigCommand } from './commands' import { OrganizeImportsCommand, SourceImportsCommand } from './organizeImports' +import WatchProject from './watchBuild' import TypeScriptServiceClientHost from './typescriptServiceClientHost' import { LanguageDescription, standardLanguageDescriptions } from './utils/languageDescription' @@ -43,6 +44,7 @@ export default class TsserverService implements IServiceProvider { this.selector = this.descriptions.reduce((arr, c) => { return arr.concat(c.languageIds) }, []) + console.log(111) this.registCommands() } @@ -61,6 +63,14 @@ export default class TsserverService implements IServiceProvider { let { id, execute } = cmd subscriptions.push(commands.registerCommand(id as string, execute, cmd)) } + let watchProject = new WatchProject(this) + subscriptions.push(watchProject) + registCommand({ + id: WatchProject.id, + execute: () => { + return watchProject.execute() + } + }) registCommand(new ConfigurePluginCommand(this.pluginManager)) registCommand(new AutoFixCommand(this)) registCommand(new ReloadProjectsCommand(this)) diff --git a/src/server/typescriptServiceClientHost.ts b/src/server/typescriptServiceClientHost.ts index 43e591f..e081079 100644 --- a/src/server/typescriptServiceClientHost.ts +++ b/src/server/typescriptServiceClientHost.ts @@ -8,7 +8,6 @@ import { flatten } from '../utils/arrays' import { PluginManager } from '../utils/plugins' import { DiagnosticKind } from './features/diagnostics' import FileConfigurationManager from './features/fileConfigurationManager' -import WatchBuild from './features/watchBuild' import WorkspaceSymbolProvider from './features/workspaceSymbols' import LanguageProvider from './languageProvider' import * as Proto from './protocol' @@ -66,7 +65,6 @@ export default class TypeScriptServiceClientHost implements Disposable { }, null, this.disposables) // features - this.disposables.push(new WatchBuild(this.client)) this.disposables.push(languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider(this.client, allModeIds))) this.client.onConfigDiagnosticsReceived(diag => { let { body } = diag diff --git a/src/server/watchBuild.ts b/src/server/watchBuild.ts new file mode 100644 index 0000000..fdb4a64 --- /dev/null +++ b/src/server/watchBuild.ts @@ -0,0 +1,129 @@ +import { Disposable, disposeAll, StatusBarItem, TaskOptions, Uri, window, workspace } from 'coc.nvim' +import path from 'path' +import type TsserverService from '../server' + +const countRegex = /Found\s+(\d+)\s+error/ +const errorRegex = /^(.+)\((\d+),(\d+)\):\s(\w+)\sTS(\d+):\s*(.+)$/ + +export default class WatchProject implements Disposable { + private disposables: Disposable[] = [] + public static readonly id: string = 'tsserver.watchBuild' + public static readonly startTexts: string[] = ['Starting compilation in watch mode', 'Starting incremental compilation'] + private statusItem: StatusBarItem + private task: any + private options: TaskOptions + + public constructor( + private readonly service: TsserverService + ) { + this.statusItem = window.createStatusBarItem(1, { progress: true }) + this.disposables.push(this.statusItem) + let task = this.task = workspace.createTask('TSC') + + task.onExit(code => { + if (code != 0) { + window.showMessage(`TSC exit with code ${code}`, 'warning') + } + this.onStop() + }) + task.onStdout(lines => { + for (let line of lines) { + this.onLine(line) + } + }) + task.onStderr(lines => { + window.showMessage(`TSC error: ` + lines.join('\n'), 'error') + }) + this.disposables.push(Disposable.create(() => { + task.dispose() + })) + this.check().catch(_e => { + // noop + }) + } + + public async execute(): Promise { + let opts = this.options = await this.getOptions() + await this.start(opts) + } + + private async check(): Promise { + let running = await this.task.running + if (running) { + this.options = await this.getOptions() + this.statusItem.isProgress = false + this.statusItem.text = '?' + this.statusItem.show() + } else { + this.onStop() + } + } + + private async start(options: TaskOptions): Promise { + await this.task.start(options) + } + + private onStop(): void { + this.statusItem.hide() + } + + private onStart(): void { + this.statusItem.text = 'compiling' + this.statusItem.isProgress = true + this.statusItem.show() + workspace.nvim.call('setqflist', [[]], true) + } + + private onLine(line: string): void { + if (countRegex.test(line)) { + let ms = line.match(countRegex) + this.statusItem.text = ms[1] == '0' ? '✓' : '✗' + this.statusItem.isProgress = false + } else if (WatchProject.startTexts.findIndex(s => line.indexOf(s) !== -1) != -1) { + this.onStart() + } else { + let ms = line.match(errorRegex) + if (!ms) return + let fullpath = path.join(this.options.cwd, ms[1]) + let uri = Uri.file(fullpath).toString() + let doc = workspace.getDocument(uri) + let bufnr = doc ? doc.bufnr : null + let item = { + filename: fullpath, + lnum: Number(ms[2]), + col: Number(ms[3]), + text: `[tsc ${ms[5]}] ${ms[6]}`, + type: /error/i.test(ms[4]) ? 'E' : 'W' + } as any + if (bufnr) item.bufnr = bufnr + workspace.nvim.call('setqflist', [[item], 'a']) + } + } + + public async getOptions(): Promise { + let client = await this.service.getClientHost() + let { tscPath } = client.serviceClient + if (!tscPath) { + window.showMessage(`Local & global tsc not found`, 'error') + return + } + + const tsconfigPath = workspace.getConfiguration('tsserver').get('tsconfigPath', 'tsconfig.json') + let find = await workspace.findUp([tsconfigPath]) + if (!find) { + window.showMessage(`${tsconfigPath} not found!`, 'error') + return + } + + let root = path.dirname(find) + return { + cmd: tscPath, + args: ['-p', tsconfigPath, '--watch', 'true', '--pretty', 'false'], + cwd: root + } + } + + public dispose(): void { + disposeAll(this.disposables) + } +} From 9860656a9eca52a54f81dae817ced7a8c768fe7f Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 15 Aug 2022 16:28:58 +0800 Subject: [PATCH 08/18] Release 1.11.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af8fc22..1edb6e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.2", + "version": "1.11.3", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From d4a7f4f38f9698e0b7afe498bbbb28fa7c85b7b2 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Thu, 25 Aug 2022 11:54:12 +0800 Subject: [PATCH 09/18] remove console.log --- src/server/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/index.ts b/src/server/index.ts index 032c0c2..1c808a8 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -44,7 +44,6 @@ export default class TsserverService implements IServiceProvider { this.selector = this.descriptions.reduce((arr, c) => { return arr.concat(c.languageIds) }, []) - console.log(111) this.registCommands() } From dea4c3a0c6380bf029d94b8f9f52eeb040c0e199 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Sat, 27 Aug 2022 12:28:53 +0800 Subject: [PATCH 10/18] ignore fugitive scheme Closes #395 --- src/server/features/bufferSyncSupport.ts | 8 ++++---- src/server/features/diagnostics.ts | 2 +- src/server/typescriptServiceClient.ts | 5 +++-- src/server/typescriptServiceClientHost.ts | 4 ++-- src/utils/fileSchemes.ts | 2 ++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/server/features/bufferSyncSupport.ts b/src/server/features/bufferSyncSupport.ts index a7ae050..1a8fecc 100644 --- a/src/server/features/bufferSyncSupport.ts +++ b/src/server/features/bufferSyncSupport.ts @@ -30,21 +30,21 @@ class CloseOperation { readonly type = BufferOperationType.Close; constructor( public readonly args: string - ) { } + ) {} } class OpenOperation { readonly type = BufferOperationType.Open; constructor( public readonly args: Proto.OpenRequestArgs - ) { } + ) {} } class ChangeOperation { readonly type = BufferOperationType.Change; constructor( public readonly args: Proto.FileCodeEdits - ) { } + ) {} } type BufferOperation = CloseOperation | OpenOperation | ChangeOperation @@ -59,7 +59,7 @@ class SyncedBuffer { public readonly filepath: string, private readonly client: ITypeScriptServiceClient, private readonly synchronizer: BufferSynchronizer, - ) { } + ) {} public open(): void { const args: Proto.OpenRequestArgs = { diff --git a/src/server/features/diagnostics.ts b/src/server/features/diagnostics.ts index 47f93af..9eb91b9 100644 --- a/src/server/features/diagnostics.ts +++ b/src/server/features/diagnostics.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { DiagnosticCollection, languages, workspace } from 'coc.nvim' +import { DiagnosticCollection, Uri, languages, workspace } from 'coc.nvim' import { Diagnostic, DiagnosticTag } from 'vscode-languageserver-protocol' import { ResourceMap } from './resourceMap' diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index 5c6c58c..54a172e 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -42,6 +42,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient private fileConfigurationManager: FileConfigurationManager private pathSeparator: string + private readonly emptyAuthority = 'ts-nul-authority' private tracer: Tracer private _configuration: TypeScriptServiceConfiguration private versionProvider: TypeScriptVersionProvider @@ -432,7 +433,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient public toResource(filepath: string): string { if (filepath.includes('zipfile:')) { - return filepath.replace(/.*zipfile:/, 'zipfile://'); + return filepath.replace(/.*zipfile:/, 'zipfile://') } if (this._apiVersion.gte(API.v213)) { if (filepath.startsWith(this.inMemoryResourcePrefix + 'untitled:')) { @@ -938,7 +939,7 @@ function getDiagnosticsKind(event: Proto.Event): DiagnosticKind { case 'suggestionDiag': return DiagnosticKind.Suggestion } - throw new Error('Unknown dignostics kind') + throw new Error('Unknown diagnostics kind') } const fenceCommands = new Set(['change', 'close', 'open']) diff --git a/src/server/typescriptServiceClientHost.ts b/src/server/typescriptServiceClientHost.ts index e081079..ed3585f 100644 --- a/src/server/typescriptServiceClientHost.ts +++ b/src/server/typescriptServiceClientHost.ts @@ -215,11 +215,11 @@ export default class TypeScriptServiceClientHost implements Disposable { language.diagnosticsReceived( kind, resource, - this.createMarkerDatas(diagnostics)) + this.createMarkerData(diagnostics)) } } - private createMarkerDatas(diagnostics: Proto.Diagnostic[]): (Diagnostic & { reportUnnecessary: any, reportDeprecated: any })[] { + private createMarkerData(diagnostics: Proto.Diagnostic[]): (Diagnostic & { reportUnnecessary: any, reportDeprecated: any })[] { return diagnostics.map(tsDiag => this.tsDiagnosticToLspDiagnostic(tsDiag)) } diff --git a/src/utils/fileSchemes.ts b/src/utils/fileSchemes.ts index ef1510d..e645ff4 100644 --- a/src/utils/fileSchemes.ts +++ b/src/utils/fileSchemes.ts @@ -6,6 +6,7 @@ export const file = 'file' export const untitled = 'untitled' export const git = 'git' +export const fugitive = 'fugitive' /** Live share scheme */ export const vsls = 'vsls' export const walkThroughSnippet = 'walkThroughSnippet' @@ -21,5 +22,6 @@ export const semanticSupportedSchemes = [ */ export const disabledSchemes = new Set([ git, + fugitive, vsls ]) From 35a9f254235273c244492a98dd1a661da00cc623 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Sat, 27 Aug 2022 12:29:29 +0800 Subject: [PATCH 11/18] Release 1.11.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1edb6e3..17c9ac6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.3", + "version": "1.11.4", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From 63e22e092cea9b6f5f0d3d83fba1f2f018c1049c Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 29 Aug 2022 18:21:23 +0800 Subject: [PATCH 12/18] fix configured tsserver.tsdk not used Use configured tsserver.tsdk when local tsserver not used. --- src/server/typescriptServiceClient.ts | 11 ++++++++++- src/server/utils/versionProvider.ts | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index 54a172e..605fefc 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -227,7 +227,16 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient if (this.tscPathVim) currentVersion = this.versionProvider.getVersionFromTscPath(this.tscPathVim) if (!currentVersion && !ignoreLocalTsserver) currentVersion = this.versionProvider.getLocalVersion() if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) { - this.info('Local tsserver not found, using bundled tsserver with coc-tsserver.') + if (ignoreLocalTsserver) { + this.info(`local tsserver is ignored, try global version`) + } else { + this.info(`local tsserver is not found, try global version`) + } + currentVersion = this.versionProvider.globalVersion + if (currentVersion) this.info('Local and global tsserver not found, using global tsserver from configuration') + } + if (!currentVersion || !fs.existsSync(currentVersion.tsServerPath)) { + this.info('Local and global tsserver not found, using bundled tsserver with coc-tsserver.') currentVersion = this.versionProvider.getDefaultVersion() } if (!currentVersion || !currentVersion.isValid) { diff --git a/src/server/utils/versionProvider.ts b/src/server/utils/versionProvider.ts index b488bef..3fbd2db 100644 --- a/src/server/utils/versionProvider.ts +++ b/src/server/utils/versionProvider.ts @@ -102,7 +102,11 @@ export class TypeScriptVersionProvider { public get globalVersion(): TypeScriptVersion | undefined { let { globalTsdk } = this.configuration - if (globalTsdk) return new TypeScriptVersion(workspace.expand(globalTsdk)) + let folder = workspace.expand(globalTsdk) + if (!path.isAbsolute(folder)) { + folder = path.join(workspace.root, folder) + } + if (globalTsdk) return new TypeScriptVersion(folder) return undefined } From 9bac05ab03a6df151929617957fa8626b1f3161e Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 29 Aug 2022 18:22:30 +0800 Subject: [PATCH 13/18] Release 1.11.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 17c9ac6..71433c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.4", + "version": "1.11.5", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From bbfe46c4aadaabe19a55a63dd957e3cac7f9cc74 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Thu, 1 Sep 2022 20:31:00 +0800 Subject: [PATCH 14/18] use LocationLink on getSymbolLocations --- src/server/features/definitionProvider.ts | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/server/features/definitionProvider.ts b/src/server/features/definitionProvider.ts index ea57402..178e863 100644 --- a/src/server/features/definitionProvider.ts +++ b/src/server/features/definitionProvider.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { TextDocument } from 'coc.nvim' +import { LocationLink, TextDocument } from 'coc.nvim' import { DefinitionProvider, CancellationToken, Definition, Location, Position, DefinitionLink, ImplementationProvider, TypeDefinitionProvider } from 'coc.nvim' import * as Proto from '../protocol' import { ITypeScriptServiceClient } from '../typescriptService' @@ -17,7 +17,7 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider, document: TextDocument, position: Position, token: CancellationToken - ): Promise { + ): Promise { const filepath = this.client.toPath(document.uri) if (!filepath) { return undefined @@ -29,12 +29,21 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider, ) try { const response = await this.client.execute(definitionType, args, token) - const locations: Proto.FileSpan[] = (response.type == 'response' && response.body) || [] - return locations.map(location => - typeConverters.Location.fromTextSpan( - this.client.toResource(location.file), - location - ) + if (response.type !== 'response' || !response.body) { + return undefined + } + const locations: Proto.FileSpanWithContext[] = (response.type == 'response' && response.body) || [] + return locations.map(location => { + const target = typeConverters.Location.fromTextSpan(this.client.toResource(location.file), location) + if (location.contextStart && location.contextEnd) { + return { + targetRange: typeConverters.Range.fromLocations(location.contextStart, location.contextEnd), + targetUri: target.uri, + targetSelectionRange: target.range, + } as any + } + return target + } ) } catch { return [] @@ -84,14 +93,14 @@ export default class TypeScriptDefinitionProvider implements DefinitionProvider, public provideTypeDefinition( document: TextDocument, position: Position, - token: CancellationToken): Promise { + token: CancellationToken): Promise { return this.getSymbolLocations('typeDefinition', document, position, token) } public provideImplementation( document: TextDocument, position: Position, - token: CancellationToken): Promise { + token: CancellationToken): Promise { return this.getSymbolLocations('implementation', document, position, token) } } From 2378693a15c0a164d87900724633c98e34e87266 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Thu, 1 Sep 2022 20:31:53 +0800 Subject: [PATCH 15/18] Release 1.11.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 71433c5..6e7898e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.5", + "version": "1.11.6", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm", From cf463c29efac7dddca86f4d4b749b20013f4c5bc Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Wed, 7 Sep 2022 13:22:44 +0800 Subject: [PATCH 16/18] fix typo --- src/server/features/documentSymbol.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/features/documentSymbol.ts b/src/server/features/documentSymbol.ts index 3a78abc..93cb6b5 100644 --- a/src/server/features/documentSymbol.ts +++ b/src/server/features/documentSymbol.ts @@ -86,7 +86,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP output: DocumentSymbol[], item: Proto.NavigationTree, ): boolean { - let shouldInclude = TypeScriptDocumentSymbolProvider.shouldInclueEntry(item) + let shouldInclude = TypeScriptDocumentSymbolProvider.shouldIncludeEntry(item) const children = new Set(item.childItems || []) for (const span of item.spans) { const range = typeConverters.Range.fromTextSpan(span) @@ -129,7 +129,7 @@ export default class TypeScriptDocumentSymbolProvider implements DocumentSymbolP return symbolInfo } - private static shouldInclueEntry( + private static shouldIncludeEntry( item: Proto.NavigationTree | Proto.NavigationBarItem ): boolean { if (item.kind === PConst.Kind.alias) { From 528209b91c32e016af013a2af47f1c0d26668b77 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 12 Sep 2022 12:09:05 +0800 Subject: [PATCH 17/18] fix snippet not work with optional property --- src/server/features/completionItemProvider.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/server/features/completionItemProvider.ts b/src/server/features/completionItemProvider.ts index 8280ee2..7d81387 100644 --- a/src/server/features/completionItemProvider.ts +++ b/src/server/features/completionItemProvider.ts @@ -225,8 +225,6 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP let { uri, position, source, name, data } = item.data const filepath = this.client.toPath(uri) if (!filepath) return undefined - let document = workspace.getDocument(uri) - if (!document) return undefined const args: Proto.CompletionDetailsRequestArgs = { ...typeConverters.Position.toFileLocationRequestArgs( filepath, @@ -259,11 +257,10 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP item.additionalTextEdits = additionalTextEdits if (detail && item.insertTextFormat == InsertTextFormat.Snippet) { const shouldCompleteFunction = await this.isValidFunctionCompletionContext(filepath, position, token) - if (shouldCompleteFunction && !item.insertText) { + if (shouldCompleteFunction) { this.createSnippetOfFunctionCall(item, detail) } } - return item } @@ -380,7 +377,7 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP let { displayParts } = detail const parameterListParts = getParameterListParts(displayParts) const snippet = new SnippetString() - snippet.appendText(`${item.insertText || item.label}(`) + snippet.appendText(`${item.insertText ?? item.label}(`) appendJoinedPlaceholders(snippet, parameterListParts.parts, ', ') if (parameterListParts.hasOptionalParameters) { snippet.appendTabstop() From e5e05794f6f475e57a468f5df05607ee512274f3 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Mon, 12 Sep 2022 14:13:51 +0800 Subject: [PATCH 18/18] Release 1.11.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6e7898e..c8feb67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coc-tsserver", - "version": "1.11.6", + "version": "1.11.7", "description": "tsserver extension for coc.nvim", "main": "lib/index.js", "publisher": "chemzqm",