From 57d822772145b6d0c38f8948c8a08e0b85ab22e3 Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Fri, 1 Jun 2018 16:39:40 +0200 Subject: [PATCH] Remove middleware --- lsp-multi-root-sample/client/src/extension.ts | 73 +------------------ lsp-multi-root-sample/server/src/server.ts | 15 ++-- 2 files changed, 12 insertions(+), 76 deletions(-) diff --git a/lsp-multi-root-sample/client/src/extension.ts b/lsp-multi-root-sample/client/src/extension.ts index 3ad05ab1..ffaffdf4 100644 --- a/lsp-multi-root-sample/client/src/extension.ts +++ b/lsp-multi-root-sample/client/src/extension.ts @@ -6,67 +6,14 @@ import * as path from 'path'; -import { workspace, ExtensionContext, WorkspaceConfiguration, Disposable } from 'vscode'; +import { workspace, ExtensionContext } from 'vscode'; + import { - LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, CancellationToken, Middleware, - DidChangeConfigurationNotification, ConfigurationParams + LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient'; -// The example settings -interface MultiRootExampleSettings { - maxNumberOfProblems: number; -} - let client: LanguageClient; -namespace Configuration { - - let configurationListener: Disposable; - - // Convert VS Code specific settings to a format acceptable by the server. Since - // both client and server do use JSON the conversion is trivial. - export function computeConfiguration(params: ConfigurationParams, _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 config: WorkspaceConfiguration; - if (item.scopeUri) { - config = workspace.getConfiguration('languageServerExample', client.protocol2CodeConverter.asUri(item.scopeUri)); - } else { - config = workspace.getConfiguration('languageServerExample'); - } - result.push({ - maxNumberOfProblems: config.get('maxNumberOfProblems') - }); - } - return result; - } - - export function initialize() { - // VS Code currently doesn't sent fine grained configuration changes. So we - // listen to any change. However this will change in the near future. - configurationListener = workspace.onDidChangeConfiguration(() => { - client.sendNotification(DidChangeConfigurationNotification.type, { settings: null }); - }); - } - - export function dispose() { - if (configurationListener) { - configurationListener.dispose(); - } - } -} - - export function activate(context: ExtensionContext) { // The server is implemented in node @@ -81,12 +28,6 @@ export function activate(context: ExtensionContext) { debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } } - let middleware: Middleware = { - workspace: { - configuration: Configuration.computeConfiguration - } - }; - // Options to control the language client let clientOptions: LanguageClientOptions = { // Register the server for plain text documents @@ -94,12 +35,7 @@ export function activate(context: ExtensionContext) { synchronize: { // Notify the server about file changes to '.clientrc files contain in the workspace fileEvents: workspace.createFileSystemWatcher('**/.clientrc'), - // In the past this told the client to actively synchronize settings. Since the - // client now supports 'getConfiguration' requests this active synchronization is not - // necessary anymore. - // configurationSection: [ 'lspMultiRootSample' ] - }, - middleware: middleware + } } // Create the language client and start the client. @@ -113,6 +49,5 @@ export function deactivate(): Thenable { if (!client) { return undefined; } - Configuration.dispose(); return client.stop(); } \ No newline at end of file diff --git a/lsp-multi-root-sample/server/src/server.ts b/lsp-multi-root-sample/server/src/server.ts index cf8ac0dc..348fddfd 100644 --- a/lsp-multi-root-sample/server/src/server.ts +++ b/lsp-multi-root-sample/server/src/server.ts @@ -40,6 +40,7 @@ connection.onInitialize((params: InitializeParams) => { connection.onInitialized(() => { if (hasConfigurationCapability) { + // Register for all conifiguration changes. connection.client.register(DidChangeConfigurationNotification.type, undefined); } if (hasWorkspaceFolderCapability) { @@ -50,38 +51,38 @@ connection.onInitialized(() => { }); // The example settings -interface MultiRootExampleSettings { +interface Settings { maxNumberOfProblems: number; } // The global settings, used when the `workspace/configuration` request is not supported by the client. // Please note that this is not the case when using this server with the client provided in this example // but could happen with other clients. -const defaultSettings: MultiRootExampleSettings = { maxNumberOfProblems: 1000 }; -let globalSettings: MultiRootExampleSettings = defaultSettings; +const defaultSettings: Settings = { maxNumberOfProblems: 1000 }; +let globalSettings: Settings = defaultSettings; // Cache the settings of all open documents -let documentSettings: Map> = new Map(); +let documentSettings: Map> = new Map(); connection.onDidChangeConfiguration(change => { if (hasConfigurationCapability) { // Reset all cached document settings documentSettings.clear(); } else { - globalSettings = (change.settings.lspMultiRootSample || defaultSettings); + globalSettings = (change.settings.lspMultiRootSample || defaultSettings); } // Revalidate all open text documents documents.all().forEach(validateTextDocument); }); -function getDocumentSettings(resource: string): Thenable { +function getDocumentSettings(resource: string): Thenable { if (!hasConfigurationCapability) { return Promise.resolve(globalSettings); } let result = documentSettings.get(resource); if (!result) { - result = connection.workspace.getConfiguration({ scopeUri: resource }); + result = connection.workspace.getConfiguration({ scopeUri: resource, section: 'languageServerExample' }); documentSettings.set(resource, result); } return result;