vscode-html-languageserver-bin
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,16 +7,55 @@ #!/usr/bin/env node | ||
'use strict'; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var vscode_languageserver_1 = require("vscode-languageserver"); | ||
var languageModes_1 = require("./modes/languageModes"); | ||
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 protocol_workspaceFolders_proposed_1 = require("vscode-languageserver-protocol/lib/protocol.workspaceFolders.proposed"); | ||
var formatting_1 = require("./modes/formatting"); | ||
var arrays_1 = require("./utils/arrays"); | ||
var url = require("url"); | ||
var path = require("path"); | ||
var documentContext_1 = require("./utils/documentContext"); | ||
var vscode_uri_1 = require("vscode-uri"); | ||
var errors_1 = require("./utils/errors"); | ||
var nls = require("vscode-nls"); | ||
nls.config(process.env['VSCODE_NLS_CONFIG']); | ||
var ColorSymbolRequest; | ||
(function (ColorSymbolRequest) { | ||
ColorSymbolRequest.type = new vscode_languageserver_1.RequestType('css/colorSymbols'); | ||
})(ColorSymbolRequest || (ColorSymbolRequest = {})); | ||
var TagCloseRequest; | ||
(function (TagCloseRequest) { | ||
TagCloseRequest.type = new vscode_languageserver_1.RequestType('html/tag'); | ||
})(TagCloseRequest || (TagCloseRequest = {})); | ||
// Create a connection for the server | ||
@@ -26,2 +65,5 @@ var connection = vscode_languageserver_1.createConnection(); | ||
console.error = connection.console.error.bind(connection.console); | ||
process.on('unhandledRejection', function (e) { | ||
connection.console.error(errors_1.formatError("Unhandled exception", e)); | ||
}); | ||
// Create a simple text document manager. The text document manager | ||
@@ -33,7 +75,27 @@ // supports full document sync only | ||
documents.listen(connection); | ||
var workspacePath; | ||
var workspaceFolders; | ||
var languageModes; | ||
var settings = {}; | ||
var clientSnippetSupport = false; | ||
var clientDynamicRegisterSupport = false; | ||
var scopedSettingsSupport = false; | ||
var workspaceFoldersSupport = false; | ||
var globalSettings = {}; | ||
var documentSettings = {}; | ||
// remove document settings on close | ||
documents.onDidClose(function (e) { | ||
delete documentSettings[e.document.uri]; | ||
}); | ||
function getDocumentSettings(textDocument, needsDocumentSettings) { | ||
if (scopedSettingsSupport && needsDocumentSettings()) { | ||
var promise = documentSettings[textDocument.uri]; | ||
if (!promise) { | ||
var scopeUri = textDocument.uri; | ||
var configRequestParam = { items: [{ scopeUri: scopeUri, section: 'css' }, { scopeUri: scopeUri, section: 'html' }, { scopeUri: scopeUri, section: 'javascript' }] }; | ||
promise = connection.sendRequest(protocol_configuration_proposed_1.ConfigurationRequest.type, configRequestParam).then(function (s) { return ({ css: s[0], html: s[1], javascript: s[2] }); }); | ||
documentSettings[textDocument.uri] = promise; | ||
} | ||
return promise; | ||
} | ||
return Promise.resolve(void 0); | ||
} | ||
// After the server has started the client sends an initilize request. The server receives | ||
@@ -43,3 +105,9 @@ // in the passed params the rootPath of the workspace plus the client capabilites | ||
var initializationOptions = params.initializationOptions; | ||
workspacePath = params.rootPath; | ||
workspaceFolders = params.workspaceFolders; | ||
if (!Array.isArray(workspaceFolders)) { | ||
workspaceFolders = []; | ||
if (params.rootPath) { | ||
workspaceFolders.push({ name: '', uri: vscode_uri_1.default.file(params.rootPath).toString() }); | ||
} | ||
} | ||
languageModes = languageModes_1.getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }); | ||
@@ -65,30 +133,47 @@ documents.onDidClose(function (e) { | ||
clientDynamicRegisterSupport = hasClientCapability('workspace', 'symbol', 'dynamicRegistration'); | ||
return { | ||
capabilities: { | ||
// Tell the client that the server works in FULL text document sync mode | ||
textDocumentSync: documents.syncKind, | ||
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/'] } : null, | ||
hoverProvider: true, | ||
documentHighlightProvider: true, | ||
documentRangeFormattingProvider: false, | ||
documentLinkProvider: { resolveProvider: false }, | ||
documentSymbolProvider: true, | ||
definitionProvider: true, | ||
signatureHelpProvider: { triggerCharacters: ['('] }, | ||
referencesProvider: true, | ||
} | ||
scopedSettingsSupport = hasClientCapability('workspace', 'configuration'); | ||
workspaceFoldersSupport = hasClientCapability('workspace', 'workspaceFolders'); | ||
var capabilities = { | ||
// Tell the client that the server works in FULL text document sync mode | ||
textDocumentSync: documents.syncKind, | ||
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/'] } : undefined, | ||
hoverProvider: true, | ||
documentHighlightProvider: true, | ||
documentRangeFormattingProvider: false, | ||
documentLinkProvider: { resolveProvider: false }, | ||
documentSymbolProvider: true, | ||
definitionProvider: true, | ||
signatureHelpProvider: { triggerCharacters: ['('] }, | ||
referencesProvider: true, | ||
colorProvider: true | ||
}; | ||
return { capabilities: capabilities }; | ||
}); | ||
var validation = { | ||
html: true, | ||
css: true, | ||
javascript: true | ||
}; | ||
connection.onInitialized(function (p) { | ||
if (workspaceFoldersSupport) { | ||
connection.client.register(protocol_workspaceFolders_proposed_1.DidChangeWorkspaceFoldersNotification.type); | ||
connection.onNotification(protocol_workspaceFolders_proposed_1.DidChangeWorkspaceFoldersNotification.type, function (e) { | ||
var toAdd = e.event.added; | ||
var toRemove = e.event.removed; | ||
var updatedFolders = []; | ||
if (workspaceFolders) { | ||
var _loop_1 = function (folder) { | ||
if (!toRemove.some(function (r) { return r.uri === folder.uri; }) && !toAdd.some(function (r) { return r.uri === folder.uri; })) { | ||
updatedFolders.push(folder); | ||
} | ||
}; | ||
for (var _i = 0, workspaceFolders_1 = workspaceFolders; _i < workspaceFolders_1.length; _i++) { | ||
var folder = workspaceFolders_1[_i]; | ||
_loop_1(folder); | ||
} | ||
} | ||
workspaceFolders = updatedFolders.concat(toAdd); | ||
}); | ||
} | ||
}); | ||
var formatterRegistration = null; | ||
// The settings have changed. Is send on server activation as well. | ||
connection.onDidChangeConfiguration(function (change) { | ||
settings = change.settings; | ||
var validationSettings = settings && settings.html && settings.html.validate || {}; | ||
validation.css = validationSettings.styles !== false; | ||
validation.javascript = validationSettings.scripts !== false; | ||
globalSettings = change.settings; | ||
documentSettings = {}; // reset all document settings | ||
languageModes.getAllModes().forEach(function (m) { | ||
@@ -102,3 +187,3 @@ if (m.configure) { | ||
if (clientDynamicRegisterSupport) { | ||
var enableFormatter = settings && settings.html && settings.html.format && settings.html.format.enable; | ||
var enableFormatter = globalSettings && globalSettings.html && globalSettings.html.format && globalSettings.html.format.enable; | ||
if (enableFormatter) { | ||
@@ -117,3 +202,3 @@ if (!formatterRegistration) { | ||
var pendingValidationRequests = {}; | ||
var validationDelayMs = 200; | ||
var validationDelayMs = 500; | ||
// The content of a text document has changed. This event is emitted | ||
@@ -143,125 +228,221 @@ // when the text document first opened or when its content has changed. | ||
} | ||
function isValidationEnabled(languageId, settings) { | ||
if (settings === void 0) { settings = globalSettings; } | ||
var validationSettings = settings && settings.html && settings.html.validate; | ||
if (validationSettings) { | ||
return languageId === 'css' && validationSettings.styles !== false || languageId === 'javascript' && validationSettings.scripts !== false; | ||
} | ||
return true; | ||
} | ||
function validateTextDocument(textDocument) { | ||
var diagnostics = []; | ||
if (textDocument.languageId === 'html') { | ||
languageModes.getAllModesInDocument(textDocument).forEach(function (mode) { | ||
if (mode.doValidation && validation[mode.getId()]) { | ||
arrays_1.pushAll(diagnostics, mode.doValidation(textDocument)); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var diagnostics_1, modes_1, settings_1, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 3, , 4]); | ||
diagnostics_1 = []; | ||
if (!(textDocument.languageId === 'html')) return [3 /*break*/, 2]; | ||
modes_1 = languageModes.getAllModesInDocument(textDocument); | ||
return [4 /*yield*/, getDocumentSettings(textDocument, function () { return modes_1.some(function (m) { return !!m.doValidation; }); })]; | ||
case 1: | ||
settings_1 = _a.sent(); | ||
modes_1.forEach(function (mode) { | ||
if (mode.doValidation && isValidationEnabled(mode.getId(), settings_1)) { | ||
arrays_1.pushAll(diagnostics_1, mode.doValidation(textDocument, settings_1)); | ||
} | ||
}); | ||
_a.label = 2; | ||
case 2: | ||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: diagnostics_1 }); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
connection.console.error(errors_1.formatError("Error while validating " + textDocument.uri, e_1)); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
} | ||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: diagnostics }); | ||
}); | ||
} | ||
connection.onCompletion(function (textDocumentPosition) { | ||
var document = documents.get(textDocumentPosition.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, textDocumentPosition.position); | ||
if (mode && mode.doComplete) { | ||
if (mode.getId() !== 'html') { | ||
connection.telemetry.logEvent({ key: 'html.embbedded.complete', value: { languageId: mode.getId() } }); | ||
} | ||
return mode.doComplete(document, textDocumentPosition.position); | ||
} | ||
return { isIncomplete: true, items: [] }; | ||
}); | ||
connection.onCompletion(function (textDocumentPosition) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, errors_1.runSafe(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var document, mode, doComplete_1, settings; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
document = documents.get(textDocumentPosition.textDocument.uri); | ||
mode = languageModes.getModeAtPosition(document, textDocumentPosition.position); | ||
if (!(mode && mode.doComplete)) return [3 /*break*/, 2]; | ||
doComplete_1 = mode.doComplete; | ||
if (mode.getId() !== 'html') { | ||
connection.telemetry.logEvent({ key: 'html.embbedded.complete', value: { languageId: mode.getId() } }); | ||
} | ||
return [4 /*yield*/, getDocumentSettings(document, function () { return doComplete_1.length > 2; })]; | ||
case 1: | ||
settings = _a.sent(); | ||
return [2 /*return*/, doComplete_1(document, textDocumentPosition.position, settings)]; | ||
case 2: return [2 /*return*/, { isIncomplete: true, items: [] }]; | ||
} | ||
}); | ||
}); }, null, "Error while computing completions for " + textDocumentPosition.textDocument.uri)]; | ||
}); | ||
}); }); | ||
connection.onCompletionResolve(function (item) { | ||
var data = item.data; | ||
if (data && data.languageId && data.uri) { | ||
var mode = languageModes.getMode(data.languageId); | ||
var document_1 = documents.get(data.uri); | ||
if (mode && mode.doResolve && document_1) { | ||
return mode.doResolve(document_1, item); | ||
return errors_1.runSafe(function () { | ||
var data = item.data; | ||
if (data && data.languageId && data.uri) { | ||
var mode = languageModes.getMode(data.languageId); | ||
var document_1 = documents.get(data.uri); | ||
if (mode && mode.doResolve && document_1) { | ||
return mode.doResolve(document_1, item); | ||
} | ||
} | ||
} | ||
return item; | ||
return item; | ||
}, null, "Error while resolving completion proposal"); | ||
}); | ||
connection.onHover(function (textDocumentPosition) { | ||
var document = documents.get(textDocumentPosition.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, textDocumentPosition.position); | ||
if (mode && mode.doHover) { | ||
return mode.doHover(document, textDocumentPosition.position); | ||
} | ||
return null; | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(textDocumentPosition.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, textDocumentPosition.position); | ||
if (mode && mode.doHover) { | ||
return mode.doHover(document, textDocumentPosition.position); | ||
} | ||
return null; | ||
}, null, "Error while computing hover for " + textDocumentPosition.textDocument.uri); | ||
}); | ||
connection.onDocumentHighlight(function (documentHighlightParams) { | ||
var document = documents.get(documentHighlightParams.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, documentHighlightParams.position); | ||
if (mode && mode.findDocumentHighlight) { | ||
return mode.findDocumentHighlight(document, documentHighlightParams.position); | ||
} | ||
return []; | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(documentHighlightParams.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, documentHighlightParams.position); | ||
if (mode && mode.findDocumentHighlight) { | ||
return mode.findDocumentHighlight(document, documentHighlightParams.position); | ||
} | ||
return []; | ||
}, [], "Error while computing document highlights for " + documentHighlightParams.textDocument.uri); | ||
}); | ||
connection.onDefinition(function (definitionParams) { | ||
var document = documents.get(definitionParams.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, definitionParams.position); | ||
if (mode && mode.findDefinition) { | ||
return mode.findDefinition(document, definitionParams.position); | ||
} | ||
return []; | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(definitionParams.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, definitionParams.position); | ||
if (mode && mode.findDefinition) { | ||
return mode.findDefinition(document, definitionParams.position); | ||
} | ||
return []; | ||
}, null, "Error while computing definitions for " + definitionParams.textDocument.uri); | ||
}); | ||
connection.onReferences(function (referenceParams) { | ||
var document = documents.get(referenceParams.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, referenceParams.position); | ||
if (mode && mode.findReferences) { | ||
return mode.findReferences(document, referenceParams.position); | ||
} | ||
return []; | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(referenceParams.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, referenceParams.position); | ||
if (mode && mode.findReferences) { | ||
return mode.findReferences(document, referenceParams.position); | ||
} | ||
return []; | ||
}, [], "Error while computing references for " + referenceParams.textDocument.uri); | ||
}); | ||
connection.onSignatureHelp(function (signatureHelpParms) { | ||
var document = documents.get(signatureHelpParms.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, signatureHelpParms.position); | ||
if (mode && mode.doSignatureHelp) { | ||
return mode.doSignatureHelp(document, signatureHelpParms.position); | ||
} | ||
return null; | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(signatureHelpParms.textDocument.uri); | ||
var mode = languageModes.getModeAtPosition(document, signatureHelpParms.position); | ||
if (mode && mode.doSignatureHelp) { | ||
return mode.doSignatureHelp(document, signatureHelpParms.position); | ||
} | ||
return null; | ||
}, null, "Error while computing signature help for " + signatureHelpParms.textDocument.uri); | ||
}); | ||
connection.onDocumentRangeFormatting(function (formatParams) { | ||
var document = documents.get(formatParams.textDocument.uri); | ||
var unformattedTags = settings && settings.html && settings.html.format && settings.html.format.unformatted || ''; | ||
var enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/) }; | ||
return formatting_1.format(languageModes, document, formatParams.range, formatParams.options, enabledModes); | ||
}); | ||
connection.onDocumentRangeFormatting(function (formatParams) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, errors_1.runSafe(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var document, settings, unformattedTags, enabledModes; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
document = documents.get(formatParams.textDocument.uri); | ||
return [4 /*yield*/, getDocumentSettings(document, function () { return true; })]; | ||
case 1: | ||
settings = _a.sent(); | ||
if (!settings) { | ||
settings = globalSettings; | ||
} | ||
unformattedTags = settings && settings.html && settings.html.format && settings.html.format.unformatted || ''; | ||
enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/) }; | ||
return [2 /*return*/, formatting_1.format(languageModes, document, formatParams.range, formatParams.options, settings, enabledModes)]; | ||
} | ||
}); | ||
}); }, [], "Error while formatting range for " + formatParams.textDocument.uri)]; | ||
}); | ||
}); }); | ||
connection.onDocumentLinks(function (documentLinkParam) { | ||
var document = documents.get(documentLinkParam.textDocument.uri); | ||
var documentContext = { | ||
resolveReference: function (ref, base) { | ||
if (base) { | ||
ref = url.resolve(base, ref); | ||
} | ||
if (workspacePath && ref[0] === '/') { | ||
return vscode_uri_1.default.file(path.join(workspacePath, ref)).toString(); | ||
} | ||
return url.resolve(document.uri, ref); | ||
}, | ||
}; | ||
var links = []; | ||
languageModes.getAllModesInDocument(document).forEach(function (m) { | ||
if (m.findDocumentLinks) { | ||
arrays_1.pushAll(links, m.findDocumentLinks(document, documentContext)); | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(documentLinkParam.textDocument.uri); | ||
var links = []; | ||
if (document) { | ||
var documentContext_2 = documentContext_1.getDocumentContext(document.uri, workspaceFolders); | ||
languageModes.getAllModesInDocument(document).forEach(function (m) { | ||
if (m.findDocumentLinks) { | ||
arrays_1.pushAll(links, m.findDocumentLinks(document, documentContext_2)); | ||
} | ||
}); | ||
} | ||
}); | ||
return links; | ||
return links; | ||
}, [], "Error while document links for " + documentLinkParam.textDocument.uri); | ||
}); | ||
connection.onDocumentSymbol(function (documentSymbolParms) { | ||
var document = documents.get(documentSymbolParms.textDocument.uri); | ||
var symbols = []; | ||
languageModes.getAllModesInDocument(document).forEach(function (m) { | ||
if (m.findDocumentSymbols) { | ||
arrays_1.pushAll(symbols, m.findDocumentSymbols(document)); | ||
} | ||
}); | ||
return symbols; | ||
}); | ||
connection.onRequest(ColorSymbolRequest.type, function (uri) { | ||
var ranges = []; | ||
var document = documents.get(uri); | ||
if (document) { | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(documentSymbolParms.textDocument.uri); | ||
var symbols = []; | ||
languageModes.getAllModesInDocument(document).forEach(function (m) { | ||
if (m.findColorSymbols) { | ||
arrays_1.pushAll(ranges, m.findColorSymbols(document)); | ||
if (m.findDocumentSymbols) { | ||
arrays_1.pushAll(symbols, m.findDocumentSymbols(document)); | ||
} | ||
}); | ||
} | ||
return ranges; | ||
return symbols; | ||
}, [], "Error while computing document symbols for " + documentSymbolParms.textDocument.uri); | ||
}); | ||
connection.onRequest(protocol_colorProvider_proposed_1.DocumentColorRequest.type, function (params) { | ||
return errors_1.runSafe(function () { | ||
var infos = []; | ||
var document = documents.get(params.textDocument.uri); | ||
if (document) { | ||
languageModes.getAllModesInDocument(document).forEach(function (m) { | ||
if (m.findDocumentColors) { | ||
arrays_1.pushAll(infos, m.findDocumentColors(document)); | ||
} | ||
}); | ||
} | ||
return infos; | ||
}, [], "Error while computing document colors for " + params.textDocument.uri); | ||
}); | ||
connection.onRequest(protocol_colorProvider_proposed_1.ColorPresentationRequest.type, function (params) { | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(params.textDocument.uri); | ||
if (document) { | ||
var mode = languageModes.getModeAtPosition(document, params.range.start); | ||
if (mode && mode.getColorPresentations) { | ||
return mode.getColorPresentations(document, params.color, params.range); | ||
} | ||
} | ||
return []; | ||
}, [], "Error while computing color presentations for " + params.textDocument.uri); | ||
}); | ||
connection.onRequest(TagCloseRequest.type, function (params) { | ||
return errors_1.runSafe(function () { | ||
var document = documents.get(params.textDocument.uri); | ||
if (document) { | ||
var pos = params.position; | ||
if (pos.character > 0) { | ||
var mode = languageModes.getModeAtPosition(document, vscode_languageserver_1.Position.create(pos.line, pos.character - 1)); | ||
if (mode && mode.doAutoClose) { | ||
return mode.doAutoClose(document, pos); | ||
} | ||
} | ||
} | ||
return null; | ||
}, null, "Error while computing tag close actions for " + params.textDocument.uri); | ||
}); | ||
// Listen on the connection | ||
connection.listen(); |
@@ -21,5 +21,5 @@ /*--------------------------------------------------------------------------------------------- | ||
}, | ||
doValidation: function (document) { | ||
doValidation: function (document, settings) { | ||
var embedded = embeddedCSSDocuments.get(document); | ||
return cssLanguageService.doValidation(embedded, cssStylesheets.get(embedded)); | ||
return cssLanguageService.doValidation(embedded, cssStylesheets.get(embedded), settings && settings.css); | ||
}, | ||
@@ -50,6 +50,10 @@ doComplete: function (document, position) { | ||
}, | ||
findColorSymbols: function (document) { | ||
findDocumentColors: function (document) { | ||
var embedded = embeddedCSSDocuments.get(document); | ||
return cssLanguageService.findColorSymbols(embedded, cssStylesheets.get(embedded)); | ||
return cssLanguageService.findDocumentColors(embedded, cssStylesheets.get(embedded)); | ||
}, | ||
getColorPresentations: function (document, color, range) { | ||
var embedded = embeddedCSSDocuments.get(document); | ||
return cssLanguageService.getColorPresentations(embedded, cssStylesheets.get(embedded), color, range); | ||
}, | ||
onDocumentRemoved: function (document) { | ||
@@ -66,2 +70,1 @@ embeddedCSSDocuments.onDocumentRemoved(document); | ||
exports.getCSSMode = getCSSMode; | ||
; |
@@ -9,9 +9,8 @@ /*--------------------------------------------------------------------------------------------- | ||
exports.CSS_STYLE_RULE = '__'; | ||
; | ||
function getDocumentRegions(languageService, document) { | ||
var regions = []; | ||
var scanner = languageService.createScanner(document.getText()); | ||
var lastTagName; | ||
var lastAttributeName; | ||
var languageIdFromType; | ||
var lastTagName = ''; | ||
var lastAttributeName = null; | ||
var languageIdFromType = undefined; | ||
var importedScripts = []; | ||
@@ -44,3 +43,3 @@ var token = scanner.scan(); | ||
else if (lastAttributeName === 'type' && lastTagName.toLowerCase() === 'script') { | ||
if (/["'](text|application)\/(java|ecma)script["']/.test(scanner.getTokenText())) { | ||
if (/["'](module|(text|application)\/(java|ecma)script)["']/.test(scanner.getTokenText())) { | ||
languageIdFromType = 'javascript'; | ||
@@ -47,0 +46,0 @@ } |
@@ -11,3 +11,3 @@ /*--------------------------------------------------------------------------------------------- | ||
var strings_1 = require("../utils/strings"); | ||
function format(languageModes, document, formatRange, formattingOptions, enabledModes) { | ||
function format(languageModes, document, formatRange, formattingOptions, settings, enabledModes) { | ||
var result = []; | ||
@@ -35,6 +35,7 @@ var endPos = formatRange.end; | ||
var startPos = formatRange.start; | ||
while (i < allRanges.length && allRanges[i].mode.getId() !== 'html') { | ||
var isHTML = function (range) { return range.mode && range.mode.getId() === 'html'; }; | ||
while (i < allRanges.length && !isHTML(allRanges[i])) { | ||
var range = allRanges[i]; | ||
if (!range.attributeValue && range.mode.format) { | ||
var edits = range.mode.format(document, vscode_languageserver_types_1.Range.create(startPos, range.end), formattingOptions); | ||
if (!range.attributeValue && range.mode && range.mode.format) { | ||
var edits = range.mode.format(document, vscode_languageserver_types_1.Range.create(startPos, range.end), formattingOptions, settings); | ||
arrays_1.pushAll(result, edits); | ||
@@ -52,3 +53,3 @@ } | ||
var htmlMode = languageModes.getMode('html'); | ||
var htmlEdits = htmlMode.format(document, formatRange, formattingOptions); | ||
var htmlEdits = htmlMode.format(document, formatRange, formattingOptions, settings); | ||
var htmlFormattedContent = edits_1.applyEdits(document, htmlEdits); | ||
@@ -66,3 +67,3 @@ var newDocument = vscode_languageserver_types_1.TextDocument.create(document.uri + '.tmp', document.languageId, document.version, htmlFormattedContent); | ||
if (mode && mode.format && enabledModes[mode.getId()] && !r.attributeValue) { | ||
var edits = mode.format(newDocument, r, formattingOptions); | ||
var edits = mode.format(newDocument, r, formattingOptions, settings); | ||
for (var _a = 0, edits_2 = edits; _a < edits_2.length; _a++) { | ||
@@ -74,3 +75,2 @@ var edit = edits_2[_a]; | ||
} | ||
; | ||
if (embeddedEdits.length === 0) { | ||
@@ -77,0 +77,0 @@ arrays_1.pushAll(result, htmlEdits); |
@@ -9,3 +9,3 @@ /*--------------------------------------------------------------------------------------------- | ||
function getHTMLMode(htmlLanguageService) { | ||
var settings = {}; | ||
var globalSettings = {}; | ||
var htmlDocuments = languageModelCache_1.getLanguageModelCache(10, 60, function (document) { return htmlLanguageService.parseHTMLDocument(document); }); | ||
@@ -17,6 +17,11 @@ return { | ||
configure: function (options) { | ||
settings = options && options.html; | ||
globalSettings = options; | ||
}, | ||
doComplete: function (document, position) { | ||
var options = settings && settings.suggest; | ||
doComplete: function (document, position, settings) { | ||
if (settings === void 0) { settings = globalSettings; } | ||
var options = settings && settings.html && settings.html.suggest; | ||
var doAutoComplete = settings && settings.html && settings.html.autoClosingTags; | ||
if (doAutoComplete) { | ||
options.hideAutoCompleteProposals = true; | ||
} | ||
return htmlLanguageService.doComplete(document, position, htmlDocuments.get(document), options); | ||
@@ -36,12 +41,28 @@ }, | ||
}, | ||
format: function (document, range, formatParams) { | ||
var formatSettings = settings && settings.format; | ||
if (!formatSettings) { | ||
formatSettings = formatParams; | ||
format: function (document, range, formatParams, settings) { | ||
if (settings === void 0) { settings = globalSettings; } | ||
var formatSettings = settings && settings.html && settings.html.format; | ||
if (formatSettings) { | ||
formatSettings = merge(formatSettings, {}); | ||
} | ||
else { | ||
formatSettings = merge(formatParams, merge(formatSettings, {})); | ||
formatSettings = {}; | ||
} | ||
if (formatSettings.contentUnformatted) { | ||
formatSettings.contentUnformatted = formatSettings.contentUnformatted + ',script'; | ||
} | ||
else { | ||
formatSettings.contentUnformatted = 'script'; | ||
} | ||
formatSettings = merge(formatParams, formatSettings); | ||
return htmlLanguageService.format(document, range, formatSettings); | ||
}, | ||
doAutoClose: function (document, position) { | ||
var offset = document.offsetAt(position); | ||
var text = document.getText(); | ||
if (offset > 0 && text.charAt(offset - 1).match(/[>\/]/g)) { | ||
return htmlLanguageService.doTagComplete(document, position, htmlDocuments.get(document)); | ||
} | ||
return null; | ||
}, | ||
onDocumentRemoved: function (document) { | ||
@@ -56,3 +77,2 @@ htmlDocuments.onDocumentRemoved(document); | ||
exports.getHTMLMode = getHTMLMode; | ||
; | ||
function merge(src, dst) { | ||
@@ -59,0 +79,0 @@ for (var key in src) { |
@@ -56,3 +56,3 @@ /*--------------------------------------------------------------------------------------------- | ||
var jsLanguageService = ts.createLanguageService(host); | ||
var settings = {}; | ||
var globalSettings = {}; | ||
return { | ||
@@ -63,3 +63,3 @@ getId: function () { | ||
configure: function (options) { | ||
settings = options && options.javascript; | ||
globalSettings = options; | ||
}, | ||
@@ -74,2 +74,3 @@ doValidation: function (document) { | ||
severity: vscode_languageserver_types_1.DiagnosticSeverity.Error, | ||
source: 'js', | ||
message: ts.flattenDiagnosticMessageText(diag.messageText, '\n') | ||
@@ -82,3 +83,3 @@ }; | ||
var offset = currentTextDocument.offsetAt(position); | ||
var completions = jsLanguageService.getCompletionsAtPosition(FILE_NAME, offset); | ||
var completions = jsLanguageService.getCompletionsAtPosition(FILE_NAME, offset, { includeExternalModuleExports: false }); | ||
if (!completions) { | ||
@@ -109,3 +110,3 @@ return { isIncomplete: false, items: [] }; | ||
updateCurrentTextDocument(document); | ||
var details = jsLanguageService.getCompletionEntryDetails(FILE_NAME, item.data.offset, item.label); | ||
var details = jsLanguageService.getCompletionEntryDetails(FILE_NAME, item.data.offset, item.label, undefined, undefined); | ||
if (details) { | ||
@@ -142,3 +143,3 @@ item.detail = ts.displayPartsToString(details.displayParts); | ||
label: '', | ||
documentation: null, | ||
documentation: undefined, | ||
parameters: [] | ||
@@ -164,3 +165,2 @@ }; | ||
} | ||
; | ||
return null; | ||
@@ -179,4 +179,3 @@ }, | ||
} | ||
; | ||
return null; | ||
return []; | ||
}, | ||
@@ -188,3 +187,3 @@ findDocumentSymbols: function (document) { | ||
var result_1 = []; | ||
var existing_1 = {}; | ||
var existing_1 = Object.create(null); | ||
var collectSymbols_1 = function (item, containerLabel) { | ||
@@ -216,3 +215,3 @@ var sig = item.text + item.kind + item.spans[0].start; | ||
} | ||
return null; | ||
return []; | ||
}, | ||
@@ -243,13 +242,15 @@ findDefinition: function (document, position) { | ||
} | ||
return null; | ||
return []; | ||
}, | ||
format: function (document, range, formatParams) { | ||
format: function (document, range, formatParams, settings) { | ||
if (settings === void 0) { settings = globalSettings; } | ||
currentTextDocument = documentRegions.get(document).getEmbeddedDocument('javascript', true); | ||
scriptFileVersion++; | ||
var formatterSettings = settings && settings.javascript && settings.javascript.format; | ||
var initialIndentLevel = computeInitialIndent(document, range, formatParams); | ||
var formatSettings = convertOptions(formatParams, settings && settings.format, initialIndentLevel + 1); | ||
var formatSettings = convertOptions(formatParams, formatterSettings, initialIndentLevel + 1); | ||
var start = currentTextDocument.offsetAt(range.start); | ||
var end = currentTextDocument.offsetAt(range.end); | ||
var lastLineRange = null; | ||
if (range.end.character === 0 || strings_1.isWhitespaceOnly(currentTextDocument.getText().substr(end - range.end.character, range.end.character))) { | ||
if (range.end.line > range.start.line && (range.end.character === 0 || strings_1.isWhitespaceOnly(currentTextDocument.getText().substr(end - range.end.character, range.end.character)))) { | ||
end -= range.end.character; | ||
@@ -278,3 +279,3 @@ lastLineRange = vscode_languageserver_types_1.Range.create(vscode_languageserver_types_1.Position.create(range.end.line, 0), range.end); | ||
} | ||
return null; | ||
return []; | ||
}, | ||
@@ -291,6 +292,9 @@ onDocumentRemoved: function (document) { | ||
exports.getJavascriptMode = getJavascriptMode; | ||
; | ||
function convertRange(document, span) { | ||
if (typeof span.start === 'undefined') { | ||
var pos = document.positionAt(0); | ||
return vscode_languageserver_types_1.Range.create(pos, pos); | ||
} | ||
var startPosition = document.positionAt(span.start); | ||
var endPosition = document.positionAt(span.start + span.length); | ||
var endPosition = document.positionAt(span.start + (span.length || 0)); | ||
return vscode_languageserver_types_1.Range.create(startPosition, endPosition); | ||
@@ -297,0 +301,0 @@ } |
@@ -18,3 +18,3 @@ /*--------------------------------------------------------------------------------------------- | ||
modelCaches.push(documentRegions); | ||
var modes = {}; | ||
var modes = Object.create(null); | ||
modes['html'] = htmlMode_1.getHTMLMode(htmlLanguageService); | ||
@@ -33,3 +33,3 @@ if (supportedLanguages['css']) { | ||
} | ||
return null; | ||
return void 0; | ||
}, | ||
@@ -41,3 +41,3 @@ getModesInRange: function (document, range) { | ||
end: r.end, | ||
mode: modes[r.languageId], | ||
mode: r.languageId && modes[r.languageId], | ||
attributeValue: r.attributeValue | ||
@@ -44,0 +44,0 @@ }; |
{ | ||
"name": "vscode-html-languageserver-bin", | ||
"description": "HTML language server", | ||
"version": "1.0.0", | ||
"author": "Microsoft Corporation", | ||
"description": "Binary version published on npm of vscode-html-languageserver extracted from VSCode tree", | ||
"version": "1.1.0", | ||
"author": "VSCode Langservers", | ||
"license": "MIT", | ||
@@ -11,11 +11,10 @@ "engines": { | ||
"dependencies": { | ||
"vscode-css-languageservice": "^2.1.0", | ||
"vscode-html-languageservice": "^2.0.5", | ||
"vscode-languageserver": "^3.1.0-alpha.1", | ||
"vscode-css-languageservice": "^3.0.3", | ||
"vscode-html-languageservice": "^2.0.14", | ||
"vscode-languageserver": "^3.5.0", | ||
"vscode-nls": "^2.0.2", | ||
"vscode-uri": "^1.0.0", | ||
"typescript": "^2.4.2" | ||
"vscode-uri": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^2.4.2" | ||
"typescript": "^2.6.2" | ||
}, | ||
@@ -22,0 +21,0 @@ "scripts": {}, |
@@ -7,2 +7,3 @@ /*--------------------------------------------------------------------------------------------- | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("mocha"); | ||
var assert = require("assert"); | ||
@@ -9,0 +10,0 @@ var embeddedSupport = require("../modes/embeddedSupport"); |
@@ -7,2 +7,3 @@ /*--------------------------------------------------------------------------------------------- | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("mocha"); | ||
var path = require("path"); | ||
@@ -36,3 +37,3 @@ var fs = require("fs"); | ||
} | ||
var result = formatting_1.format(languageModes, document, range, formatOptions, { css: true, javascript: true }); | ||
var result = formatting_1.format(languageModes, document, range, formatOptions, void 0, { css: true, javascript: true }); | ||
var actual = applyEdits(document, result); | ||
@@ -53,7 +54,7 @@ assert.equal(actual, expected, message); | ||
assertFormat('<html><head><script></script></head></html>', '<html>\n\n<head>\n <script></script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head><script>var x=1;</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head><script>\nvar x=2;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 2;\n\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n <script>\nvar x=3;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 3;\n\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n <script>\nvar x=4;\nconsole.log("Hi");\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 4;\n console.log("Hi");\n\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n |<script>\nvar x=5;\n</script>|</head></html>', '<html><head>\n <script>\n var x = 5;\n\n </script></head></html>'); | ||
assertFormat('<html><head><script>var x=1;</script></head></html>', '<html>\n\n<head>\n <script>var x = 1;</script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head><script>\nvar x=2;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 2;\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n <script>\nvar x=3;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 3;\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n <script>\nvar x=4;\nconsole.log("Hi");\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 4;\n console.log("Hi");\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n |<script>\nvar x=5;\n</script>|</head></html>', '<html><head>\n <script>\n var x = 5;\n </script></head></html>'); | ||
}); | ||
@@ -67,6 +68,6 @@ test('HTLM & Scripts - Fixtures', function () { | ||
test('Script end tag', function () { | ||
assertFormat('<html>\n<head>\n <script>\nvar x = 0;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 0;\n\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html>\n<head>\n <script>\nvar x = 0;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 0;\n </script>\n</head>\n\n</html>'); | ||
}); | ||
test('HTML & Multiple Scripts', function () { | ||
assertFormat('<html><head>\n<script>\nif(x){\nbar(); }\n</script><script>\nfunction(x){ }\n</script></head></html>', '<html>\n\n<head>\n <script>\n if (x) {\n bar();\n }\n\n </script>\n <script>\n function(x) {}\n\n </script>\n</head>\n\n</html>'); | ||
assertFormat('<html><head>\n<script>\nif(x){\nbar(); }\n</script><script>\nfunction(x){ }\n</script></head></html>', '<html>\n\n<head>\n <script>\n if (x) {\n bar();\n }\n </script>\n <script>\n function(x) {}\n </script>\n</head>\n\n</html>'); | ||
}); | ||
@@ -86,3 +87,3 @@ test('HTML & Styles', function () { | ||
assertFormat('<html>|<body><p>Hello</p></body>|</html>', '<html><body>\n <p>Hello</p>\n</body></html>', options); | ||
assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n\n </script>\n</head>\n\n</html>\n', options); | ||
assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n </script>\n</head>\n\n</html>\n', options); | ||
}); | ||
@@ -94,4 +95,7 @@ test('Inside script', function () { | ||
test('Range after new line', function () { | ||
assertFormat('<html><head>\n |<script>\nvar x=6;\n</script>\n|</head></html>', '<html><head>\n <script>\n var x = 6;\n\n </script>\n</head></html>'); | ||
assertFormat('<html><head>\n |<script>\nvar x=6;\n</script>\n|</head></html>', '<html><head>\n <script>\n var x = 6;\n </script>\n</head></html>'); | ||
}); | ||
test('bug 36574', function () { | ||
assertFormat('<script src="/js/main.js"> </script>', '<script src="/js/main.js"> </script>'); | ||
}); | ||
}); | ||
@@ -98,0 +102,0 @@ function applyEdits(document, edits) { |
@@ -7,2 +7,3 @@ /*--------------------------------------------------------------------------------------------- | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("mocha"); | ||
var assert = require("assert"); | ||
@@ -9,0 +10,0 @@ var javascriptMode_1 = require("../modes/javascriptMode"); |
@@ -16,3 +16,2 @@ /*--------------------------------------------------------------------------------------------- | ||
}); | ||
var lastOffset = text.length; | ||
sortedEdits.forEach(function (e) { | ||
@@ -22,3 +21,2 @@ var startOffset = document.offsetAt(e.range.start); | ||
text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length); | ||
lastOffset = startOffset; | ||
}); | ||
@@ -25,0 +23,0 @@ return text; |
@@ -39,2 +39,15 @@ /*--------------------------------------------------------------------------------------------- | ||
exports.startsWith = startsWith; | ||
function endsWith(haystack, needle) { | ||
var diff = haystack.length - needle.length; | ||
if (diff > 0) { | ||
return haystack.indexOf(needle, diff) === diff; | ||
} | ||
else if (diff === 0) { | ||
return haystack === needle; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
exports.endsWith = endsWith; | ||
function repeat(value, count) { | ||
@@ -41,0 +54,0 @@ var s = ''; |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
101216
5
21
1948
1
72
+ Addedvscode-css-languageservice@3.0.13(transitive)
- Removedtypescript@^2.4.2
- Removedtypescript@2.9.2(transitive)
- Removedvscode-css-languageservice@2.1.11(transitive)
Updatedvscode-languageserver@^3.5.0
Updatedvscode-uri@^1.0.1