From 02f3fd68cdc83d83701b33110ba2cf790c711801 Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Fri, 8 Sep 2017 13:06:57 +0200 Subject: [PATCH] Move to latest version of the LSP libraries for the multi root example --- lsp-multi-root-sample/client/package.json | 4 +- lsp-multi-root-sample/client/src/extension.ts | 58 +++++++++---------- lsp-multi-root-sample/server/package.json | 2 +- lsp-multi-root-sample/server/src/server.ts | 6 +- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/lsp-multi-root-sample/client/package.json b/lsp-multi-root-sample/client/package.json index e9b6b3f8..a94b8bb7 100644 --- a/lsp-multi-root-sample/client/package.json +++ b/lsp-multi-root-sample/client/package.json @@ -10,7 +10,7 @@ "url": "https://github.com/Microsoft/vscode-extension-samples" }, "engines": { - "vscode": "^1.15.0" + "vscode": "^1.16.0" }, "categories": [ "Other" @@ -53,6 +53,6 @@ }, "dependencies": { "vscode": "^1.1.5", - "vscode-languageclient": "next" + "vscode-languageclient": "^3.4.1" } } \ No newline at end of file diff --git a/lsp-multi-root-sample/client/src/extension.ts b/lsp-multi-root-sample/client/src/extension.ts index 26524a4e..e83a5c70 100644 --- a/lsp-multi-root-sample/client/src/extension.ts +++ b/lsp-multi-root-sample/client/src/extension.ts @@ -8,8 +8,7 @@ import * as path from 'path'; import { workspace, ExtensionContext, WorkspaceConfiguration } from 'vscode'; import { - LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, ProposedProtocol, CancellationToken, - ConfigurationMiddleware, GetConfigurationParams + LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, CancellationToken, Middleware, Proposed, ProposedFeatures } from 'vscode-languageclient'; // The example settings @@ -33,32 +32,33 @@ export function activate(context: ExtensionContext) { // Convert VS Code specific settings to a format acceptable by the server. Since // both client and server do use JSON the conversion is trivial. - let configurationMiddleware: ConfigurationMiddleware = { - configuration: (params: GetConfigurationParams, _token: CancellationToken, _next: Function): any[] => { - if (!params.items) { - return null; - } - let result: (MultiRootExampleSettings | null)[] = []; - for (let item of params.items) { - // The server asks the client for configuration settings without a section - // If a section is present we return null to indicate that the configuration - // is not supported. - if (item.section) { - result.push(null); - continue; + let middleware: ProposedFeatures.ConfigurationMiddleware | Middleware = { + workspace: { + configuration: (params: Proposed.ConfigurationParams, _token: CancellationToken, _next: Function): any[] => { + if (!params.items) { + return null; } - let config: WorkspaceConfiguration; - if (item.scopeUri) { - config = workspace.getConfiguration('lspMultiRootSample', client.protocol2CodeConverter.asUri(item.scopeUri)); - } else { - config = workspace.getConfiguration('lspMultiRootSample'); + let result: (MultiRootExampleSettings | null)[] = []; + for (let item of params.items) { + // The server asks the client for configuration settings without a section + // If a section is present we return null to indicate that the configuration + // is not supported. + if (item.section) { + result.push(null); + continue; + } + let config: WorkspaceConfiguration; + if (item.scopeUri) { + config = workspace.getConfiguration('lspMultiRootSample', client.protocol2CodeConverter.asUri(item.scopeUri)); + } else { + config = workspace.getConfiguration('lspMultiRootSample'); + } + result.push({ + maxNumberOfProblems: config.get('maxNumberOfProblems') + }); } - result.push({ - maxNumberOfProblems: config.get('maxNumberOfProblems') - }); + return result; } - return result; - } }; @@ -70,15 +70,13 @@ export function activate(context: ExtensionContext) { // Notify the server about file changes to '.clientrc files contain in the workspace fileEvents: workspace.createFileSystemWatcher('**/.clientrc') }, - middleware: { - workspace: configurationMiddleware as any // cast to any due to proposed API - } + middleware: middleware as Middleware } // Create the language client and start the client. let client = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions); // Register new propose protocol if available. - client.registerFeatures(ProposedProtocol(client)); + client.registerProposedFeatures(); // Start the client. This will also launch the server let disposable = client.start(); @@ -86,4 +84,4 @@ export function activate(context: ExtensionContext) { // Push the disposable to the context's subscriptions so that the // client can be deactivated on extension deactivation context.subscriptions.push(disposable); -} +} \ No newline at end of file diff --git a/lsp-multi-root-sample/server/package.json b/lsp-multi-root-sample/server/package.json index 7f6b994e..72dcb03e 100644 --- a/lsp-multi-root-sample/server/package.json +++ b/lsp-multi-root-sample/server/package.json @@ -12,7 +12,7 @@ "url": "https://github.com/Microsoft/vscode-extension-samples" }, "dependencies": { - "vscode-languageserver": "next" + "vscode-languageserver": "^3.4.1" }, "scripts": { "installServer": "installServerIntoExtension ../client ./package.json ./tsconfig.json", diff --git a/lsp-multi-root-sample/server/src/server.ts b/lsp-multi-root-sample/server/src/server.ts index 74ae1330..6f9d395d 100644 --- a/lsp-multi-root-sample/server/src/server.ts +++ b/lsp-multi-root-sample/server/src/server.ts @@ -6,11 +6,11 @@ import { createConnection, TextDocuments, TextDocument, Diagnostic, DiagnosticSeverity, - InitializeResult, DidChangeConfigurationNotification, ProposedProtocol, ConfigurationItem + InitializeResult, DidChangeConfigurationNotification, Proposed, ProposedFeatures, } from 'vscode-languageserver'; // Create a connection for the server. The connection uses Node's IPC as a transport -let connection = createConnection(ProposedProtocol); +let connection = createConnection(ProposedFeatures.all); // Create a simple text document manager. The text document manager // supports full document sync only @@ -48,7 +48,7 @@ connection.onInitialized(() => { connection.onNotification(DidChangeConfigurationNotification.type, () => { - let toRequest: ConfigurationItem[] = []; + let toRequest: Proposed.ConfigurationItem[] = []; for (let resource of settings.keys()) { toRequest.push({ section: '', scopeUri: resource}); }