[css] updates service (multi-semantic selection, webpack)

This commit is contained in:
Martin Aeschlimann
2019-03-05 15:21:23 +01:00
parent f7f4357b9f
commit c9370aeaf1
8 changed files with 51 additions and 84 deletions

View File

@@ -9,8 +9,8 @@ import * as fs from 'fs';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
import { languages, window, commands, ExtensionContext, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString, workspace, TextDocument, SelectionRange, SelectionRangeKind } from 'vscode'; import { languages, window, commands, ExtensionContext, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString, workspace, TextDocument, SelectionRange } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Disposable, TextDocumentIdentifier } from 'vscode-languageclient'; import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Disposable } from 'vscode-languageclient';
import { getCustomDataPathsInAllWorkspaces, getCustomDataPathsFromAllExtensions } from './customData'; import { getCustomDataPathsInAllWorkspaces, getCustomDataPathsFromAllExtensions } from './customData';
// this method is called when vs code is activated // this method is called when vs code is activated
@@ -83,43 +83,23 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(languages.registerSelectionRangeProvider(selector, { context.subscriptions.push(languages.registerSelectionRangeProvider(selector, {
async provideSelectionRanges(document: TextDocument, positions: Position[]): Promise<SelectionRange[][]> { async provideSelectionRanges(document: TextDocument, positions: Position[]): Promise<SelectionRange[][]> {
const textDocument = client.code2ProtocolConverter.asTextDocumentIdentifier(document); const textDocument = client.code2ProtocolConverter.asTextDocumentIdentifier(document);
return Promise.all(positions.map(async position => { const rawResult = await client.sendRequest<SelectionRange[][]>('$/textDocument/selectionRanges', { textDocument, positions: positions.map(client.code2ProtocolConverter.asPosition) });
const rawRanges = await client.sendRequest<Range[]>('$/textDocument/selectionRange', { textDocument, position }); if (Array.isArray(rawResult)) {
if (Array.isArray(rawRanges)) { return rawResult.map(rawSelectionRanges => {
return rawRanges.map(r => { return rawSelectionRanges.map(selectionRange => {
return { return {
range: client.protocol2CodeConverter.asRange(r), range: client.protocol2CodeConverter.asRange(selectionRange.range),
kind: SelectionRangeKind.Declaration kind: selectionRange.kind
}; };
}); });
} });
return []; }
})); return [];
} }
})); }));
}); });
}); });
const selectionRangeProvider = {
async provideSelectionRanges(document: TextDocument, positions: Position[]): Promise<SelectionRange[][]> {
const textDocument = TextDocumentIdentifier.create(document.uri.toString());
return Promise.all(positions.map(async position => {
const rawRanges: Range[] = await client.sendRequest('$/textDocument/selectionRange', { textDocument, position });
return rawRanges.map(r => {
const actualRange = new Range(new Position(r.start.line, r.start.character), new Position(r.end.line, r.end.character));
return {
range: actualRange,
kind: SelectionRangeKind.Declaration
};
});
}));
}
};
documentSelector.forEach(selector => {
languages.registerSelectionRangeProvider(selector, selectionRangeProvider);
});
function initCompletionProvider(): Disposable { function initCompletionProvider(): Disposable {
const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/; const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?$/;

View File

@@ -726,7 +726,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"vscode-languageclient": "^5.1.0", "vscode-languageclient": "^5.2.1",
"vscode-nls": "^4.0.0" "vscode-nls": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -1,5 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
module.exports = {};

View File

@@ -9,7 +9,6 @@
const withDefaults = require('../../shared.webpack.config'); const withDefaults = require('../../shared.webpack.config');
const path = require('path'); const path = require('path');
var webpack = require('webpack');
module.exports = withDefaults({ module.exports = withDefaults({
context: path.join(__dirname), context: path.join(__dirname),
@@ -19,12 +18,5 @@ module.exports = withDefaults({
output: { output: {
filename: 'cssServerMain.js', filename: 'cssServerMain.js',
path: path.join(__dirname, 'dist') path: path.join(__dirname, 'dist')
}, }
plugins: [
new webpack.NormalModuleReplacementPlugin(
/[/\\]vscode-languageserver[/\\]lib[/\\]files\.js/,
require.resolve('./build/filesFillIn')
),
new webpack.IgnorePlugin(/vertx/)
],
}); });

View File

@@ -9,8 +9,8 @@
}, },
"main": "./out/cssServerMain", "main": "./out/cssServerMain",
"dependencies": { "dependencies": {
"vscode-css-languageservice": "^3.0.13-next.12", "vscode-css-languageservice": "^4.0.0-next.3",
"vscode-languageserver": "^5.1.0" "vscode-languageserver": "^5.3.0-next.2"
}, },
"devDependencies": { "devDependencies": {
"@types/mocha": "2.2.33", "@types/mocha": "2.2.33",

View File

@@ -335,14 +335,14 @@ connection.onFoldingRanges((params, token) => {
}, null, `Error while computing folding ranges for ${params.textDocument.uri}`, token); }, null, `Error while computing folding ranges for ${params.textDocument.uri}`, token);
}); });
connection.onRequest('$/textDocument/selectionRange', async (params, token) => { connection.onRequest('$/textDocument/selectionRanges', async (params, token) => {
return runSafe(() => { return runSafe(() => {
const document = documents.get(params.textDocument.uri); const document = documents.get(params.textDocument.uri);
const position: Position = params.position; const positions: Position[] = params.positions;
if (document) { if (document) {
const stylesheet = stylesheets.get(document); const stylesheet = stylesheets.get(document);
return getLanguageService(document).getSelectionRanges(document, position, stylesheet); return getLanguageService(document).getSelectionRanges(document, positions, stylesheet);
} }
return Promise.resolve(null); return Promise.resolve(null);
}, null, `Error while computing selection ranges for ${params.textDocument.uri}`, token); }, null, `Error while computing selection ranges for ${params.textDocument.uri}`, token);

View File

@@ -229,12 +229,12 @@ supports-color@5.4.0:
dependencies: dependencies:
has-flag "^3.0.0" has-flag "^3.0.0"
vscode-css-languageservice@^3.0.13-next.12: vscode-css-languageservice@^4.0.0-next.3:
version "3.0.13-next.12" version "4.0.0-next.3"
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.13-next.12.tgz#8d20828e41bc7dcf44cdba4b2e476393780a7793" resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-4.0.0-next.3.tgz#e9529f3b4ddf95c9a3e5dc2a6d701a38280ffa98"
integrity sha512-5B3NYU2DBFhbUvMuTg7kBlc9COHyr/pbR1cDzXGFwemQG8W6ERsgn+eftPHFbcug1kwBjPVSoMgtw/czKpboHQ== integrity sha512-/xmbWpIQLw+HZ/3LsaE2drHFSNJbM9mZ8bKR5NUiu2ZUr10WbGxX0j/GDZB3LlMmdSHQGgRQ5hTM/Ic2PuBDRw==
dependencies: dependencies:
vscode-languageserver-types "^3.13.0" vscode-languageserver-types "^3.14.0"
vscode-nls "^4.0.0" vscode-nls "^4.0.0"
vscode-jsonrpc@^4.0.0: vscode-jsonrpc@^4.0.0:
@@ -242,25 +242,25 @@ vscode-jsonrpc@^4.0.0:
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-4.0.0.tgz#a7bf74ef3254d0a0c272fab15c82128e378b3be9" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-4.0.0.tgz#a7bf74ef3254d0a0c272fab15c82128e378b3be9"
integrity sha512-perEnXQdQOJMTDFNv+UF3h1Y0z4iSiaN9jIlb0OqIYgosPCZGYh/MCUlkFtV2668PL69lRDO32hmvL2yiidUYg== integrity sha512-perEnXQdQOJMTDFNv+UF3h1Y0z4iSiaN9jIlb0OqIYgosPCZGYh/MCUlkFtV2668PL69lRDO32hmvL2yiidUYg==
vscode-languageserver-protocol@3.13.0: vscode-languageserver-protocol@3.15.0-next.1:
version "3.13.0" version "3.15.0-next.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.13.0.tgz#710d8e42119bb3affb1416e1e104bd6b4d503595" resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.0-next.1.tgz#1e45e224d7eef8c79b4bed75b9dcb1930d2ab8ed"
integrity sha512-2ZGKwI+P2ovQll2PGAp+2UfJH+FK9eait86VBUdkPd9HRlm8e58aYT9pV/NYanHOcp3pL6x2yTLVCFMcTer0mg== integrity sha512-LXF0d9s3vxFBxVQ4aKl/XghdEMAncGt3dh4urIYa9Is43g3MfIQL9fC44YZtP+XXOrI2rpZU8lRNN01U1V6CDg==
dependencies: dependencies:
vscode-jsonrpc "^4.0.0" vscode-jsonrpc "^4.0.0"
vscode-languageserver-types "3.13.0" vscode-languageserver-types "3.14.0"
vscode-languageserver-types@3.13.0, vscode-languageserver-types@^3.13.0: vscode-languageserver-types@3.14.0, vscode-languageserver-types@^3.14.0:
version "3.13.0" version "3.14.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.13.0.tgz#b704b024cef059f7b326611c99b9c8753c0a18b4" resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.14.0.tgz#d3b5952246d30e5241592b6dde8280e03942e743"
integrity sha512-BnJIxS+5+8UWiNKCP7W3g9FlE7fErFw0ofP5BXJe7c2tl0VeWh+nNHFbwAS2vmVC4a5kYxHBjRy0UeOtziemVA== integrity sha512-lTmS6AlAlMHOvPQemVwo3CezxBp0sNB95KNPkqp3Nxd5VFEnuG1ByM0zlRWos0zjO3ZWtkvhal0COgiV1xIA4A==
vscode-languageserver@^5.1.0: vscode-languageserver@^5.3.0-next.2:
version "5.1.0" version "5.3.0-next.2"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-5.1.0.tgz#012a28f154cc7a848c443d217894942e4c3eeb39" resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-5.3.0-next.2.tgz#31ce4c34d68b517b400ca9e211e43f8d868b8dcc"
integrity sha512-CIsrgx2Y5VHS317g/HwkSTWYBIQmy0DwEyZPmB2pEpVOhYFwVsYpbiJwHIIyLQsQtmRaO4eA2xM8KPjNSdXpBw== integrity sha512-n5onRw9naMrRHp2jnOn+ZwN1n+tTfzftWLPonjp1FWf/iCZWIlnw2TyF/Hn+SDGhLoVtoghmxhwEQaxEAfLHvw==
dependencies: dependencies:
vscode-languageserver-protocol "3.13.0" vscode-languageserver-protocol "3.15.0-next.1"
vscode-uri "^1.0.6" vscode-uri "^1.0.6"
vscode-nls@^4.0.0: vscode-nls@^4.0.0:

View File

@@ -167,26 +167,26 @@ vscode-jsonrpc@^4.0.0:
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-4.0.0.tgz#a7bf74ef3254d0a0c272fab15c82128e378b3be9" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-4.0.0.tgz#a7bf74ef3254d0a0c272fab15c82128e378b3be9"
integrity sha512-perEnXQdQOJMTDFNv+UF3h1Y0z4iSiaN9jIlb0OqIYgosPCZGYh/MCUlkFtV2668PL69lRDO32hmvL2yiidUYg== integrity sha512-perEnXQdQOJMTDFNv+UF3h1Y0z4iSiaN9jIlb0OqIYgosPCZGYh/MCUlkFtV2668PL69lRDO32hmvL2yiidUYg==
vscode-languageclient@^5.1.0: vscode-languageclient@^5.2.1:
version "5.1.0" version "5.2.1"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-5.1.0.tgz#650ab0dc9fd0daaade058a8471aaff5bc3f9580e" resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-5.2.1.tgz#7cfc83a294c409f58cfa2b910a8cfeaad0397193"
integrity sha512-Z95Kps8UqD4o17HE3uCkZuvenOsxHVH46dKmaGVpGixEFZigPaVuVxLM/JWeIY9aRenoC0ZD9CK1O7L4jpffKg== integrity sha512-7jrS/9WnV0ruqPamN1nE7qCxn0phkH5LjSgSp9h6qoJGoeAKzwKz/PF6M+iGA/aklx4GLZg1prddhEPQtuXI1Q==
dependencies: dependencies:
semver "^5.5.0" semver "^5.5.0"
vscode-languageserver-protocol "3.13.0" vscode-languageserver-protocol "3.14.1"
vscode-languageserver-protocol@3.13.0: vscode-languageserver-protocol@3.14.1:
version "3.13.0" version "3.14.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.13.0.tgz#710d8e42119bb3affb1416e1e104bd6b4d503595" resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.14.1.tgz#b8aab6afae2849c84a8983d39a1cf742417afe2f"
integrity sha512-2ZGKwI+P2ovQll2PGAp+2UfJH+FK9eait86VBUdkPd9HRlm8e58aYT9pV/NYanHOcp3pL6x2yTLVCFMcTer0mg== integrity sha512-IL66BLb2g20uIKog5Y2dQ0IiigW0XKrvmWiOvc0yXw80z3tMEzEnHjaGAb3ENuU7MnQqgnYJ1Cl2l9RvNgDi4g==
dependencies: dependencies:
vscode-jsonrpc "^4.0.0" vscode-jsonrpc "^4.0.0"
vscode-languageserver-types "3.13.0" vscode-languageserver-types "3.14.0"
vscode-languageserver-types@3.13.0: vscode-languageserver-types@3.14.0:
version "3.13.0" version "3.14.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.13.0.tgz#b704b024cef059f7b326611c99b9c8753c0a18b4" resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.14.0.tgz#d3b5952246d30e5241592b6dde8280e03942e743"
integrity sha512-BnJIxS+5+8UWiNKCP7W3g9FlE7fErFw0ofP5BXJe7c2tl0VeWh+nNHFbwAS2vmVC4a5kYxHBjRy0UeOtziemVA== integrity sha512-lTmS6AlAlMHOvPQemVwo3CezxBp0sNB95KNPkqp3Nxd5VFEnuG1ByM0zlRWos0zjO3ZWtkvhal0COgiV1xIA4A==
vscode-nls@^4.0.0: vscode-nls@^4.0.0:
version "4.0.0" version "4.0.0"