Move to latest version of the LSP libraries for the multi root example

This commit is contained in:
Dirk Baeumer
2017-09-08 13:06:57 +02:00
parent 50a135a73c
commit 02f3fd68cd
4 changed files with 34 additions and 36 deletions

View File

@ -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"
}
}

View File

@ -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);
}
}

View File

@ -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",

View File

@ -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});
}