vscode-css-languageserver-bin
Advanced tools
Comparing version
@@ -9,8 +9,6 @@ #!/usr/bin/env node | ||
var vscode_languageserver_1 = require("vscode-languageserver"); | ||
var protocol_configuration_proposed_1 = require("vscode-languageserver-protocol/lib/protocol.configuration.proposed"); | ||
var protocol_colorProvider_proposed_1 = require("vscode-languageserver-protocol/lib/protocol.colorProvider.proposed"); | ||
var vscode_css_languageservice_1 = require("vscode-css-languageservice"); | ||
var languageModelCache_1 = require("./languageModelCache"); | ||
var ColorSymbolRequest; | ||
(function (ColorSymbolRequest) { | ||
ColorSymbolRequest.type = new vscode_languageserver_1.RequestType('css/colorSymbols'); | ||
})(ColorSymbolRequest || (ColorSymbolRequest = {})); | ||
// Create a connection for the server. | ||
@@ -33,20 +31,30 @@ var connection = vscode_languageserver_1.createConnection(); | ||
}); | ||
var 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(function (params) { | ||
var snippetSupport = params.capabilities && params.capabilities.textDocument && params.capabilities.textDocument.completion && params.capabilities.textDocument.completion.completionItem && params.capabilities.textDocument.completion.completionItem.snippetSupport; | ||
return { | ||
capabilities: { | ||
// Tell the client that the server works in FULL text document sync mode | ||
textDocumentSync: documents.syncKind, | ||
completionProvider: snippetSupport ? { resolveProvider: false } : null, | ||
hoverProvider: true, | ||
documentSymbolProvider: true, | ||
referencesProvider: true, | ||
definitionProvider: true, | ||
documentHighlightProvider: true, | ||
codeActionProvider: true, | ||
renameProvider: true | ||
function hasClientCapability(name) { | ||
var keys = name.split('.'); | ||
var c = params.capabilities; | ||
for (var i = 0; c && i < keys.length; i++) { | ||
c = c[keys[i]]; | ||
} | ||
return !!c; | ||
} | ||
var snippetSupport = hasClientCapability('textDocument.completion.completionItem.snippetSupport'); | ||
scopedSettingsSupport = hasClientCapability('workspace.configuration'); | ||
var capabilities = { | ||
// Tell the client that the server works in FULL text document sync mode | ||
textDocumentSync: documents.syncKind, | ||
completionProvider: snippetSupport ? { resolveProvider: false } : undefined, | ||
hoverProvider: true, | ||
documentSymbolProvider: true, | ||
referencesProvider: true, | ||
definitionProvider: true, | ||
documentHighlightProvider: true, | ||
codeActionProvider: true, | ||
renameProvider: true, | ||
colorProvider: true | ||
}; | ||
return { capabilities: capabilities }; | ||
}); | ||
@@ -66,2 +74,19 @@ var languageServices = { | ||
} | ||
var documentSettings = {}; | ||
// remove document settings on close | ||
documents.onDidClose(function (e) { | ||
delete documentSettings[e.document.uri]; | ||
}); | ||
function getDocumentSettings(textDocument) { | ||
if (scopedSettingsSupport) { | ||
var promise = documentSettings[textDocument.uri]; | ||
if (!promise) { | ||
var configRequestParam = { items: [{ scopeUri: textDocument.uri, section: textDocument.languageId }] }; | ||
promise = connection.sendRequest(protocol_configuration_proposed_1.ConfigurationRequest.type, configRequestParam).then(function (s) { return s[0]; }); | ||
documentSettings[textDocument.uri] = promise; | ||
} | ||
return promise; | ||
} | ||
return Promise.resolve(void 0); | ||
} | ||
// The settings have changed. Is send on server activation as well. | ||
@@ -75,2 +100,4 @@ connection.onDidChangeConfiguration(function (change) { | ||
} | ||
// reset all document settings | ||
documentSettings = {}; | ||
// Revalidate any open text documents | ||
@@ -106,6 +133,9 @@ documents.all().forEach(triggerValidation); | ||
function validateTextDocument(textDocument) { | ||
var stylesheet = stylesheets.get(textDocument); | ||
var diagnostics = getLanguageService(textDocument).doValidation(textDocument, stylesheet); | ||
// Send the computed diagnostics to VSCode. | ||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: diagnostics }); | ||
var settingsPromise = getDocumentSettings(textDocument); | ||
settingsPromise.then(function (settings) { | ||
var stylesheet = stylesheets.get(textDocument); | ||
var diagnostics = getLanguageService(textDocument).doValidation(textDocument, stylesheet, settings); | ||
// Send the computed diagnostics to VSCode. | ||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: diagnostics }); | ||
}); | ||
} | ||
@@ -115,3 +145,3 @@ connection.onCompletion(function (textDocumentPosition) { | ||
var stylesheet = stylesheets.get(document); | ||
return getLanguageService(document).doComplete(document, textDocumentPosition.position, stylesheet); | ||
return getLanguageService(document).doComplete(document, textDocumentPosition.position, stylesheet); /* TODO: remove ! once LS has null annotations */ | ||
}); | ||
@@ -121,3 +151,3 @@ connection.onHover(function (textDocumentPosition) { | ||
var styleSheet = stylesheets.get(document); | ||
return getLanguageService(document).doHover(document, textDocumentPosition.position, styleSheet); | ||
return getLanguageService(document).doHover(document, textDocumentPosition.position, styleSheet); /* TODO: remove ! once LS has null annotations */ | ||
}); | ||
@@ -149,10 +179,18 @@ connection.onDocumentSymbol(function (documentSymbolParams) { | ||
}); | ||
connection.onRequest(ColorSymbolRequest.type, function (uri) { | ||
var document = documents.get(uri); | ||
connection.onRequest(protocol_colorProvider_proposed_1.DocumentColorRequest.type, function (params) { | ||
var document = documents.get(params.textDocument.uri); | ||
if (document) { | ||
var stylesheet = stylesheets.get(document); | ||
return getLanguageService(document).findColorSymbols(document, stylesheet); | ||
return getLanguageService(document).findDocumentColors(document, stylesheet); | ||
} | ||
return []; | ||
}); | ||
connection.onRequest(protocol_colorProvider_proposed_1.ColorPresentationRequest.type, function (params) { | ||
var document = documents.get(params.textDocument.uri); | ||
if (document) { | ||
var stylesheet = stylesheets.get(document); | ||
return getLanguageService(document).getColorPresentations(document, stylesheet, params.color, params.range); | ||
} | ||
return []; | ||
}); | ||
connection.onRenameRequest(function (renameParameters) { | ||
@@ -159,0 +197,0 @@ var document = documents.get(renameParameters.textDocument.uri); |
{ | ||
"name": "vscode-css-languageserver-bin", | ||
"description": "CSS/LESS/SCSS language server", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "Microsoft Corporation", | ||
@@ -11,4 +11,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"vscode-css-languageservice": "^2.1.2", | ||
"vscode-languageserver": "^3.2.0" | ||
"vscode-css-languageservice": "^3.0.1", | ||
"vscode-languageserver": "^3.5.0" | ||
}, | ||
@@ -15,0 +15,0 @@ "devDependencies": { |
13282
14.65%267
16.59%+ Added
+ Added
- Removed
- Removed
Updated