[css] add multiroot support. Fixes #32486

This commit is contained in:
Martin Aeschlimann 2017-08-17 16:22:28 +02:00
parent 64fd8f8720
commit 47ec343bfa
6 changed files with 126 additions and 28 deletions

View file

@ -9,6 +9,7 @@ import * as path from 'path';
import { languages, window, commands, workspace, ExtensionContext } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, RequestType, Range, TextEdit } from 'vscode-languageclient';
import { activateColorDecorations, ColorProvider } from './colorDecorators';
import { GetConfigurationFeature } from 'vscode-languageclient/lib/proposed';
import * as nls from 'vscode-nls';
let localize = nls.loadMessageBundle();
@ -23,7 +24,7 @@ export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'cssServerMain.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
let debugOptions = { execArgv: ['--nolazy', '--inspect=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
@ -44,6 +45,7 @@ export function activate(context: ExtensionContext) {
// Create the language client and start the client.
let client = new LanguageClient('css', localize('cssserver.name', 'CSS Language Server'), serverOptions, clientOptions);
client.registerFeature(new GetConfigurationFeature(client));
let disposable = client.start();
// Push the disposable to the context's subscriptions so that the

View file

@ -13,19 +13,19 @@
"resolved": "https://registry.npmjs.org/parse-color/-/parse-color-1.0.0.tgz"
},
"vscode-jsonrpc": {
"version": "3.2.0",
"from": "vscode-jsonrpc@>=3.2.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.2.0.tgz"
"version": "3.3.1",
"from": "vscode-jsonrpc@>=3.3.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.3.1.tgz"
},
"vscode-languageclient": {
"version": "3.2.0",
"from": "vscode-languageclient@3.2.0",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-3.2.0.tgz"
"version": "3.4.0-next.4",
"from": "vscode-languageclient@next",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-3.4.0-next.4.tgz"
},
"vscode-languageserver-types": {
"version": "3.2.0",
"from": "vscode-languageserver-types@>=3.2.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.2.0.tgz"
"version": "3.3.0",
"from": "vscode-languageserver-types@>=3.3.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.3.0.tgz"
},
"vscode-nls": {
"version": "2.0.2",

View file

@ -62,16 +62,19 @@
"properties": {
"css.validate": {
"type": "boolean",
"scope": "resource",
"default": true,
"description": "%css.validate.desc%"
},
"css.colorDecorators.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%css.colorDecorators.enable.desc%"
},
"css.lint.compatibleVendorPrefixes": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -82,6 +85,7 @@
},
"css.lint.vendorPrefix": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -92,6 +96,7 @@
},
"css.lint.duplicateProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -102,6 +107,7 @@
},
"css.lint.emptyRules": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -112,6 +118,7 @@
},
"css.lint.importStatement": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -122,6 +129,7 @@
},
"css.lint.boxModel": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -132,6 +140,7 @@
},
"css.lint.universalSelector": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -142,6 +151,7 @@
},
"css.lint.zeroUnits": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -152,6 +162,7 @@
},
"css.lint.fontFaceProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -162,6 +173,7 @@
},
"css.lint.hexColorLength": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -172,6 +184,7 @@
},
"css.lint.argumentsInColorFunction": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -182,6 +195,7 @@
},
"css.lint.unknownProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -192,6 +206,7 @@
},
"css.lint.ieHack": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -202,6 +217,7 @@
},
"css.lint.unknownVendorSpecificProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -212,6 +228,7 @@
},
"css.lint.propertyIgnoredDueToDisplay": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -222,6 +239,7 @@
},
"css.lint.important": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -232,6 +250,7 @@
},
"css.lint.float": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -242,6 +261,7 @@
},
"css.lint.idSelector": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -252,6 +272,7 @@
},
"css.trace.server": {
"type": "string",
"scope": "window",
"enum": [
"off",
"messages",
@ -274,16 +295,19 @@
"properties": {
"scss.validate": {
"type": "boolean",
"scope": "resource",
"default": true,
"description": "%scss.validate.desc%"
},
"scss.colorDecorators.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%scss.colorDecorators.enable.desc%"
},
"scss.lint.compatibleVendorPrefixes": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -294,6 +318,7 @@
},
"scss.lint.vendorPrefix": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -304,6 +329,7 @@
},
"scss.lint.duplicateProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -314,6 +340,7 @@
},
"scss.lint.emptyRules": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -324,6 +351,7 @@
},
"scss.lint.importStatement": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -334,6 +362,7 @@
},
"scss.lint.boxModel": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -344,6 +373,7 @@
},
"scss.lint.universalSelector": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -354,6 +384,7 @@
},
"scss.lint.zeroUnits": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -364,6 +395,7 @@
},
"scss.lint.fontFaceProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -374,6 +406,7 @@
},
"scss.lint.hexColorLength": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -384,6 +417,7 @@
},
"scss.lint.argumentsInColorFunction": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -394,6 +428,7 @@
},
"scss.lint.unknownProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -404,6 +439,7 @@
},
"scss.lint.ieHack": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -414,6 +450,7 @@
},
"scss.lint.unknownVendorSpecificProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -424,6 +461,7 @@
},
"scss.lint.propertyIgnoredDueToDisplay": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -434,6 +472,7 @@
},
"scss.lint.important": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -444,6 +483,7 @@
},
"scss.lint.float": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -454,6 +494,7 @@
},
"scss.lint.idSelector": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -477,16 +518,19 @@
"properties": {
"less.validate": {
"type": "boolean",
"scope": "resource",
"default": true,
"description": "%less.validate.desc%"
},
"less.colorDecorators.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%less.colorDecorators.enable.desc%"
},
"less.lint.compatibleVendorPrefixes": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -497,6 +541,7 @@
},
"less.lint.vendorPrefix": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -507,6 +552,7 @@
},
"less.lint.duplicateProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -517,6 +563,7 @@
},
"less.lint.emptyRules": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -527,6 +574,7 @@
},
"less.lint.importStatement": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -537,6 +585,7 @@
},
"less.lint.boxModel": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -547,6 +596,7 @@
},
"less.lint.universalSelector": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -557,6 +607,7 @@
},
"less.lint.zeroUnits": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -567,6 +618,7 @@
},
"less.lint.fontFaceProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -577,6 +629,7 @@
},
"less.lint.hexColorLength": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -587,6 +640,7 @@
},
"less.lint.argumentsInColorFunction": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -597,6 +651,7 @@
},
"less.lint.unknownProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -607,6 +662,7 @@
},
"less.lint.ieHack": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -617,6 +673,7 @@
},
"less.lint.unknownVendorSpecificProperties": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -627,6 +684,7 @@
},
"less.lint.propertyIgnoredDueToDisplay": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -637,6 +695,7 @@
},
"less.lint.important": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -647,6 +706,7 @@
},
"less.lint.float": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -657,6 +717,7 @@
},
"less.lint.idSelector": {
"type": "string",
"scope": "resource",
"enum": [
"ignore",
"warning",
@ -674,7 +735,7 @@
},
"dependencies": {
"parse-color": "^1.0.0",
"vscode-languageclient": "^3.2.0",
"vscode-languageclient": "^3.4.0-next.4",
"vscode-nls": "^2.0.2"
},
"devDependencies": {

View file

@ -3,29 +3,34 @@
"version": "1.0.0",
"dependencies": {
"vscode-css-languageservice": {
"version": "2.1.2",
"version": "2.1.3",
"from": "vscode-css-languageservice@next",
"resolved": "https://registry.npmjs.org/vscode-css-languageservice/-/vscode-css-languageservice-2.1.2.tgz"
"resolved": "https://registry.npmjs.org/vscode-css-languageservice/-/vscode-css-languageservice-2.1.3.tgz"
},
"vscode-jsonrpc": {
"version": "3.2.0",
"from": "vscode-jsonrpc@>=3.2.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.2.0.tgz"
"version": "3.3.1",
"from": "vscode-jsonrpc@>=3.3.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-3.3.1.tgz"
},
"vscode-languageserver": {
"version": "3.2.0",
"from": "vscode-languageserver@3.2.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-3.2.0.tgz"
"version": "3.4.0-next.2",
"from": "vscode-languageserver@next",
"resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-3.4.0-next.2.tgz"
},
"vscode-languageserver-types": {
"version": "3.2.0",
"from": "vscode-languageserver-types@>=3.2.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.2.0.tgz"
"version": "3.3.0",
"from": "vscode-languageserver-types@>=3.3.0 <4.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.3.0.tgz"
},
"vscode-nls": {
"version": "2.0.2",
"from": "vscode-nls@>=2.0.1 <3.0.0",
"resolved": "https://registry.npmjs.org/vscode-nls/-/vscode-nls-2.0.2.tgz"
},
"vscode-uri": {
"version": "1.0.1",
"from": "vscode-uri@>=1.0.1 <2.0.0",
"resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.1.tgz"
}
}
}

View file

@ -8,8 +8,8 @@
"node": "*"
},
"dependencies": {
"vscode-css-languageservice": "^2.1.2",
"vscode-languageserver": "^3.2.0"
"vscode-css-languageservice": "^2.1.3",
"vscode-languageserver": "^3.4.0-next.2"
},
"devDependencies": {
"@types/node": "^6.0.51"

View file

@ -8,6 +8,7 @@ import {
createConnection, IConnection, Range,
TextDocuments, TextDocument, InitializeParams, InitializeResult, RequestType
} from 'vscode-languageserver';
import { GetConfigurationRequest } from 'vscode-languageserver/lib/protocol.proposed';
import { getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, LanguageSettings, LanguageService, Stylesheet } from 'vscode-css-languageservice';
import { getLanguageModelCache } from './languageModelCache';
@ -43,10 +44,20 @@ connection.onShutdown(() => {
stylesheets.dispose();
});
let scopedSettingsSupport = false;
// After the server has started the client sends an initilize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilities.
connection.onInitialize((params: InitializeParams): InitializeResult => {
let snippetSupport = params.capabilities && params.capabilities.textDocument && params.capabilities.textDocument.completion && params.capabilities.textDocument.completion.completionItem && params.capabilities.textDocument.completion.completionItem.snippetSupport;
function hasClientCapability(name: string) {
let keys = name.split('.');
let c = params.capabilities;
for (let i = 0; c && i < keys.length; i++) {
c = c[keys[i]];
}
return !!c;
}
let snippetSupport = hasClientCapability('textDocument.completion.completionItem.snippetSupport');
scopedSettingsSupport = hasClientCapability('workspace.getConfiguration');
return {
capabilities: {
// Tell the client that the server works in FULL text document sync mode
@ -78,6 +89,20 @@ function getLanguageService(document: TextDocument) {
return service;
}
let documentSettings: { [key: string]: Thenable<LanguageSettings> } = {};
function getDocumentSettings(textDocument: TextDocument): Thenable<LanguageSettings> {
if (scopedSettingsSupport) {
let promise = documentSettings[textDocument.uri];
if (!promise) {
let configRequestParam = { scopeUris: [textDocument.uri], sections: [textDocument.languageId] };
promise = connection.sendRequest(GetConfigurationRequest.type, configRequestParam).then(s => s[0][0]);
documentSettings[textDocument.uri] = promise;
}
return promise;
}
return void 0;
}
// The settings have changed. Is send on server activation as well.
connection.onDidChangeConfiguration(change => {
updateConfiguration(<Settings>change.settings);
@ -87,6 +112,8 @@ function updateConfiguration(settings: Settings) {
for (let languageId in languageServices) {
languageServices[languageId].configure(settings[languageId]);
}
// reset all document settings
documentSettings = {};
// Revalidate any open text documents
documents.all().forEach(triggerValidation);
}
@ -123,10 +150,13 @@ function triggerValidation(textDocument: TextDocument): void {
}
function validateTextDocument(textDocument: TextDocument): void {
let settingsPromise = getDocumentSettings(textDocument);
let stylesheet = stylesheets.get(textDocument);
let diagnostics = getLanguageService(textDocument).doValidation(textDocument, stylesheet);
// Send the computed diagnostics to VSCode.
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
settingsPromise.then(settings => {
let diagnostics = getLanguageService(textDocument).doValidation(textDocument, stylesheet, settings);
// Send the computed diagnostics to VSCode.
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
});
}
connection.onCompletion(textDocumentPosition => {