From 59f4a688d7dd8e5337cae7ead1f8ee5a8b2a33e4 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 24 May 2022 15:53:56 +0100 Subject: [PATCH 1/3] Use vscode-languageclient v8.0.0 --- package-lock.json | 70 +++++++++++++++++++++++------------------------ package.json | 2 +- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index db19787dc..5eb630181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@types/plist": "^3.0.2", "plist": "^3.0.5", - "vscode-languageclient": "^7.0.0" + "vscode-languageclient": "^8.0.0" }, "devDependencies": { "@types/glob": "^7.1.4", @@ -3673,39 +3673,39 @@ } }, "node_modules/vscode-jsonrpc": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz", - "integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.1.tgz", + "integrity": "sha512-N/WKvghIajmEvXpatSzvTvOIz61ZSmOSa4BRA4pTLi+1+jozquQKP/MkaylP9iB68k73Oua1feLQvH3xQuigiQ==", "engines": { - "node": ">=8.0.0 || >=10.0.0" + "node": ">=14.0.0" } }, "node_modules/vscode-languageclient": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-7.0.0.tgz", - "integrity": "sha512-P9AXdAPlsCgslpP9pRxYPqkNYV7Xq8300/aZDpO35j1fJm/ncize8iGswzYlcvFw5DQUx4eVk+KvfXdL0rehNg==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.1.tgz", + "integrity": "sha512-9XoE+HJfaWvu7Y75H3VmLo5WLCtsbxEgEhrLPqwt7eyoR49lUIyyrjb98Yfa50JCMqF2cePJAEVI6oe2o1sIhw==", "dependencies": { "minimatch": "^3.0.4", - "semver": "^7.3.4", - "vscode-languageserver-protocol": "3.16.0" + "semver": "^7.3.5", + "vscode-languageserver-protocol": "3.17.1" }, "engines": { - "vscode": "^1.52.0" + "vscode": "^1.67.0" } }, "node_modules/vscode-languageserver-protocol": { - "version": "3.16.0", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz", - "integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==", + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.1.tgz", + "integrity": "sha512-BNlAYgQoYwlSgDLJhSG+DeA8G1JyECqRzM2YO6tMmMji3Ad9Mw6AW7vnZMti90qlAKb0LqAlJfSVGEdqMMNzKg==", "dependencies": { - "vscode-jsonrpc": "6.0.0", - "vscode-languageserver-types": "3.16.0" + "vscode-jsonrpc": "8.0.1", + "vscode-languageserver-types": "3.17.1" } }, "node_modules/vscode-languageserver-types": { - "version": "3.16.0", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", - "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.1.tgz", + "integrity": "sha512-K3HqVRPElLZVVPtMeKlsyL9aK0GxGQpvtAUTfX4k7+iJ4mc1M+JM+zQwkgGy2LzY0f0IAafe8MKqIkJrxfGGjQ==" }, "node_modules/which": { "version": "2.0.2", @@ -6556,33 +6556,33 @@ } }, "vscode-jsonrpc": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz", - "integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==" + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-8.0.1.tgz", + "integrity": "sha512-N/WKvghIajmEvXpatSzvTvOIz61ZSmOSa4BRA4pTLi+1+jozquQKP/MkaylP9iB68k73Oua1feLQvH3xQuigiQ==" }, "vscode-languageclient": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-7.0.0.tgz", - "integrity": "sha512-P9AXdAPlsCgslpP9pRxYPqkNYV7Xq8300/aZDpO35j1fJm/ncize8iGswzYlcvFw5DQUx4eVk+KvfXdL0rehNg==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-8.0.1.tgz", + "integrity": "sha512-9XoE+HJfaWvu7Y75H3VmLo5WLCtsbxEgEhrLPqwt7eyoR49lUIyyrjb98Yfa50JCMqF2cePJAEVI6oe2o1sIhw==", "requires": { "minimatch": "^3.0.4", - "semver": "^7.3.4", - "vscode-languageserver-protocol": "3.16.0" + "semver": "^7.3.5", + "vscode-languageserver-protocol": "3.17.1" } }, "vscode-languageserver-protocol": { - "version": "3.16.0", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz", - "integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==", + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.1.tgz", + "integrity": "sha512-BNlAYgQoYwlSgDLJhSG+DeA8G1JyECqRzM2YO6tMmMji3Ad9Mw6AW7vnZMti90qlAKb0LqAlJfSVGEdqMMNzKg==", "requires": { - "vscode-jsonrpc": "6.0.0", - "vscode-languageserver-types": "3.16.0" + "vscode-jsonrpc": "8.0.1", + "vscode-languageserver-types": "3.17.1" } }, "vscode-languageserver-types": { - "version": "3.16.0", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", - "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" + "version": "3.17.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.1.tgz", + "integrity": "sha512-K3HqVRPElLZVVPtMeKlsyL9aK0GxGQpvtAUTfX4k7+iJ4mc1M+JM+zQwkgGy2LzY0f0IAafe8MKqIkJrxfGGjQ==" }, "which": { "version": "2.0.2", diff --git a/package.json b/package.json index 8b7fcdb06..92e9b05d0 100644 --- a/package.json +++ b/package.json @@ -396,6 +396,6 @@ "dependencies": { "@types/plist": "^3.0.2", "plist": "^3.0.5", - "vscode-languageclient": "^7.0.0" + "vscode-languageclient": "^8.0.0" } } From 24cb8c15ef47d68c203812c6a28da010b8afe59a Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 24 May 2022 15:56:20 +0100 Subject: [PATCH 2/3] Fixup LanguageClientManager for v8 client - client.onReady() does not exist anymore instead client.start is async so store promise returned by client.start and use that instead of onReady(). - Create a new client when restarting. Stopping, setting the workspace folder and starting doesn't work anymore --- src/sourcekit-lsp/LanguageClientManager.ts | 71 +++++++++------------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/src/sourcekit-lsp/LanguageClientManager.ts b/src/sourcekit-lsp/LanguageClientManager.ts index 8622e8f13..c98426259 100644 --- a/src/sourcekit-lsp/LanguageClientManager.ts +++ b/src/sourcekit-lsp/LanguageClientManager.ts @@ -70,9 +70,10 @@ export class LanguageClientManager { private onChangeConfig: vscode.Disposable; private inlayHints?: vscode.Disposable; private supportsDidChangedWatchedFiles: boolean; - private startedPromise?: Promise; + private restartedPromise?: Promise; private currentWorkspaceFolder?: vscode.Uri; private waitingOnRestartCount: number; + private clientReadyPromise?: Promise; public documentSymbolWatcher?: ( document: vscode.TextDocument, symbols: vscode.DocumentSymbol[] | null | undefined @@ -154,7 +155,7 @@ export class LanguageClientManager { async setLanguageClientFolder(uri?: vscode.Uri, forceRestart = false) { if (this.languageClient === undefined) { this.currentWorkspaceFolder = uri; - this.startedPromise = this.setupLanguageClient(uri); + this.restartedPromise = this.setupLanguageClient(uri); return; } else { if (uri === undefined || (this.currentWorkspaceFolder === uri && !forceRestart)) { @@ -164,9 +165,9 @@ export class LanguageClientManager { this.waitingOnRestartCount += 1; // if in the middle of a restart then we have to wait until that // restart has finished - if (this.startedPromise) { + if (this.restartedPromise) { try { - await this.startedPromise; + await this.restartedPromise; } catch (error) { //ignore error } @@ -186,24 +187,10 @@ export class LanguageClientManager { if (client) { this.cancellationToken?.cancel(); this.cancellationToken?.dispose(); - this.startedPromise = client + this.restartedPromise = client .stop() .then(async () => { - // if force restart is set then rebuild client completely - // before starting otherwise just set the workspace folder - // and call `startClient` - if (forceRestart) { - await this.setupLanguageClient(uri); - } else { - // change workspace folder and restart - const workspaceFolder = { - uri: uri, - name: FolderContext.uriName(uri), - index: 0, - }; - client.clientOptions.workspaceFolder = workspaceFolder; - await this.startClient(client); - } + await this.setupLanguageClient(uri); }) .catch(reason => { this.workspaceContext.outputChannel.log(`${reason}`); @@ -230,7 +217,7 @@ export class LanguageClientManager { if (!this.languageClient) { throw LanguageClientError.LanguageClientUnavailable; } - return await this.languageClient.onReady().then(() => { + return await this.clientReadyPromise?.then(() => { if (!this.languageClient || !this.cancellationToken) { throw LanguageClientError.LanguageClientUnavailable; } @@ -255,12 +242,12 @@ export class LanguageClientManager { return false; } - private async setupLanguageClient(folder?: vscode.Uri): Promise { - const client = await this.createLSPClient(folder); - await this.startClient(client); + private setupLanguageClient(folder?: vscode.Uri): Promise { + const client = this.createLSPClient(folder); + return this.startClient(client); } - private async createLSPClient(folder?: vscode.Uri): Promise { + private createLSPClient(folder?: vscode.Uri): langclient.LanguageClient { const lspConfig = configuration.lsp; const serverPathConfig = lspConfig.serverPath; const serverPath = @@ -332,9 +319,7 @@ export class LanguageClientManager { ); } - private async startClient(client: langclient.LanguageClient) { - client.start(); - + private startClient(client: langclient.LanguageClient): Promise { if (client.clientOptions.workspaceFolder) { this.workspaceContext.outputChannel.log( `SourceKit-LSP setup for ${FolderContext.uriName( @@ -345,24 +330,24 @@ export class LanguageClientManager { this.workspaceContext.outputChannel.log(`SourceKit-LSP setup`); } + // start client + this.clientReadyPromise = client + .start() + .then(() => { + this.inlayHints = activateInlayHints(client); + }) + .catch(reason => { + this.workspaceContext.outputChannel.log(`${reason}`); + // if language client failed to initialise then shutdown and set to undefined + this.languageClient?.stop(); + this.languageClient = undefined; + throw reason; + }); + this.languageClient = client; this.cancellationToken = new vscode.CancellationTokenSource(); - return new Promise((resolve, reject) => { - client - .onReady() - .then(() => { - this.inlayHints = activateInlayHints(client); - resolve(); - }) - .catch(reason => { - this.workspaceContext.outputChannel.log(`${reason}`); - // if language client failed to initialise then shutdown and set to undefined - this.languageClient?.stop(); - this.languageClient = undefined; - reject(reason); - }); - }); + return this.clientReadyPromise; } } From 08dc95173e319d0b8ba60bf1102d3d2cb9222c1c Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 24 May 2022 15:56:33 +0100 Subject: [PATCH 3/3] Delete DocumentSymbols.ts It is no longer used --- src/sourcekit-lsp/DocumentSymbols.ts | 43 ---------------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/sourcekit-lsp/DocumentSymbols.ts diff --git a/src/sourcekit-lsp/DocumentSymbols.ts b/src/sourcekit-lsp/DocumentSymbols.ts deleted file mode 100644 index 6f76ec4f7..000000000 --- a/src/sourcekit-lsp/DocumentSymbols.ts +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the VSCode Swift open source project -// -// Copyright (c) 2021 the VSCode Swift project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of VSCode Swift project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -import * as vscode from "vscode"; -import * as langclient from "vscode-languageclient/node"; -import { LanguageClientManager } from "./LanguageClientManager"; - -export async function getFileSymbols( - uri: vscode.Uri, - languageClientManager: LanguageClientManager -): Promise { - return await languageClientManager.useLanguageClient(async (client, cancellationToken) => { - const params = { - textDocument: langclient.TextDocumentIdentifier.create(uri.toString(true)), - }; - const response = await client.sendRequest( - langclient.DocumentSymbolRequest.type, - params, - cancellationToken - ); - if (!response) { - return undefined; - } - if (response.length === 0) { - return []; - } - const symbols = response as langclient.DocumentSymbol[]; - if (symbols) { - return client.protocol2CodeConverter.asDocumentSymbols(symbols); - } - }); -}