vscode-html-languageserver-bin
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -46,5 +46,2 @@ #!/usr/bin/env node | ||
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"); | ||
@@ -54,3 +51,5 @@ var arrays_1 = require("./utils/arrays"); | ||
var vscode_uri_1 = require("vscode-uri"); | ||
var errors_1 = require("./utils/errors"); | ||
var runner_1 = require("./utils/runner"); | ||
var vscode_languageserver_protocol_foldingprovider_1 = require("vscode-languageserver-protocol-foldingprovider"); | ||
var htmlFolding_1 = require("./modes/htmlFolding"); | ||
var TagCloseRequest; | ||
@@ -65,4 +64,7 @@ (function (TagCloseRequest) { | ||
process.on('unhandledRejection', function (e) { | ||
connection.console.error(errors_1.formatError("Unhandled exception", e)); | ||
console.error(runner_1.formatError("Unhandled exception", e)); | ||
}); | ||
process.on('uncaughtException', function (e) { | ||
console.error(runner_1.formatError("Unhandled exception", e)); | ||
}); | ||
// Create a simple text document manager. The text document manager | ||
@@ -74,3 +76,3 @@ // supports full document sync only | ||
documents.listen(connection); | ||
var workspaceFolders; | ||
var workspaceFolders = []; | ||
var languageModes; | ||
@@ -81,2 +83,3 @@ var clientSnippetSupport = false; | ||
var workspaceFoldersSupport = false; | ||
var foldingRangeLimit = Number.MAX_VALUE; | ||
var globalSettings = {}; | ||
@@ -94,3 +97,3 @@ var documentSettings = {}; | ||
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] }); }); | ||
promise = connection.sendRequest(vscode_languageserver_1.ConfigurationRequest.type, configRequestParam).then(function (s) { return ({ css: s[0], html: s[1], javascript: s[2] }); }); | ||
documentSettings[textDocument.uri] = promise; | ||
@@ -102,4 +105,4 @@ } | ||
} | ||
// 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 capabilites | ||
// After the server has started the client sends an initialize request. The server receives | ||
// in the passed params the rootPath of the workspace plus the client capabilities | ||
connection.onInitialize(function (params) { | ||
@@ -114,3 +117,7 @@ var initializationOptions = params.initializationOptions; | ||
} | ||
languageModes = languageModes_1.getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }); | ||
var workspace = { | ||
get settings() { return globalSettings; }, | ||
get folders() { return workspaceFolders; } | ||
}; | ||
languageModes = languageModes_1.getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true }, workspace); | ||
documents.onDidClose(function (e) { | ||
@@ -122,17 +129,18 @@ languageModes.onDocumentRemoved(e.document); | ||
}); | ||
function hasClientCapability() { | ||
var keys = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
keys[_i] = arguments[_i]; | ||
} | ||
function getClientCapability(name, def) { | ||
var keys = name.split('.'); | ||
var c = params.capabilities; | ||
for (var i = 0; c && i < keys.length; i++) { | ||
if (!c.hasOwnProperty(keys[i])) { | ||
return def; | ||
} | ||
c = c[keys[i]]; | ||
} | ||
return !!c; | ||
return c; | ||
} | ||
clientSnippetSupport = hasClientCapability('textDocument', 'completion', 'completionItem', 'snippetSupport'); | ||
clientDynamicRegisterSupport = hasClientCapability('workspace', 'symbol', 'dynamicRegistration'); | ||
scopedSettingsSupport = hasClientCapability('workspace', 'configuration'); | ||
workspaceFoldersSupport = hasClientCapability('workspace', 'workspaceFolders'); | ||
clientSnippetSupport = getClientCapability('textDocument.completion.completionItem.snippetSupport', false); | ||
clientDynamicRegisterSupport = getClientCapability('workspace.symbol.dynamicRegistration', false); | ||
scopedSettingsSupport = getClientCapability('workspace.configuration', false); | ||
workspaceFoldersSupport = getClientCapability('workspace.workspaceFolders', false); | ||
foldingRangeLimit = getClientCapability('textDocument.foldingRange.rangeLimit', Number.MAX_VALUE); | ||
var capabilities = { | ||
@@ -150,3 +158,4 @@ // Tell the client that the server works in FULL text document sync mode | ||
referencesProvider: true, | ||
colorProvider: true | ||
colorProvider: {}, | ||
foldingRangeProvider: true | ||
}; | ||
@@ -157,4 +166,4 @@ return { capabilities: capabilities }; | ||
if (workspaceFoldersSupport) { | ||
connection.client.register(protocol_workspaceFolders_proposed_1.DidChangeWorkspaceFoldersNotification.type); | ||
connection.onNotification(protocol_workspaceFolders_proposed_1.DidChangeWorkspaceFoldersNotification.type, function (e) { | ||
connection.client.register(vscode_languageserver_1.DidChangeWorkspaceFoldersNotification.type); | ||
connection.onNotification(vscode_languageserver_1.DidChangeWorkspaceFoldersNotification.type, function (e) { | ||
var toAdd = e.event.added; | ||
@@ -175,2 +184,3 @@ var toRemove = e.event.removed; | ||
workspaceFolders = updatedFolders.concat(toAdd); | ||
documents.all().forEach(triggerValidation); | ||
}); | ||
@@ -184,7 +194,2 @@ } | ||
documentSettings = {}; // reset all document settings | ||
languageModes.getAllModes().forEach(function (m) { | ||
if (m.configure) { | ||
m.configure(change.settings); | ||
} | ||
}); | ||
documents.all().forEach(triggerValidation); | ||
@@ -242,3 +247,3 @@ // dynamically enable & disable the formatter | ||
return __awaiter(this, void 0, void 0, function () { | ||
var diagnostics_1, modes_1, settings_1, e_1; | ||
var version, diagnostics_1, modes_1, settings_1, latestTextDocument_1, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -248,2 +253,3 @@ switch (_a.label) { | ||
_a.trys.push([0, 3, , 4]); | ||
version = textDocument.version; | ||
diagnostics_1 = []; | ||
@@ -255,14 +261,16 @@ if (!(textDocument.languageId === 'html')) return [3 /*break*/, 2]; | ||
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)); | ||
} | ||
}); | ||
latestTextDocument_1 = documents.get(textDocument.uri); | ||
if (latestTextDocument_1 && latestTextDocument_1.version === version) { // check no new version has come in after in after the async op | ||
modes_1.forEach(function (mode) { | ||
if (mode.doValidation && isValidationEnabled(mode.getId(), settings_1)) { | ||
arrays_1.pushAll(diagnostics_1, mode.doValidation(latestTextDocument_1, settings_1)); | ||
} | ||
}); | ||
connection.sendDiagnostics({ uri: latestTextDocument_1.uri, diagnostics: diagnostics_1 }); | ||
} | ||
_a.label = 2; | ||
case 2: | ||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: diagnostics_1 }); | ||
return [3 /*break*/, 4]; | ||
case 2: return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
connection.console.error(errors_1.formatError("Error while validating " + textDocument.uri, e_1)); | ||
connection.console.error(runner_1.formatError("Error while validating " + textDocument.uri, e_1)); | ||
return [3 /*break*/, 4]; | ||
@@ -274,7 +282,7 @@ case 4: return [2 /*return*/]; | ||
} | ||
connection.onCompletion(function (textDocumentPosition) { return __awaiter(_this, void 0, void 0, function () { | ||
connection.onCompletion(function (textDocumentPosition, token) { 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 [2 /*return*/, runner_1.runSafeAsync(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var document, mode, doComplete, settings, result; | ||
return __generator(this, function (_a) { | ||
@@ -284,20 +292,30 @@ switch (_a.label) { | ||
document = documents.get(textDocumentPosition.textDocument.uri); | ||
if (!document) { | ||
return [2 /*return*/, null]; | ||
} | ||
mode = languageModes.getModeAtPosition(document, textDocumentPosition.position); | ||
if (!(mode && mode.doComplete)) return [3 /*break*/, 2]; | ||
doComplete_1 = mode.doComplete; | ||
if (!mode || !mode.doComplete) { | ||
return [2 /*return*/, { isIncomplete: true, items: [] }]; | ||
} | ||
doComplete = mode.doComplete; | ||
if (mode.getId() !== 'html') { | ||
/* __GDPR__ | ||
"html.embbedded.complete" : { | ||
"languageId" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } | ||
} | ||
*/ | ||
connection.telemetry.logEvent({ key: 'html.embbedded.complete', value: { languageId: mode.getId() } }); | ||
} | ||
return [4 /*yield*/, getDocumentSettings(document, function () { return doComplete_1.length > 2; })]; | ||
return [4 /*yield*/, getDocumentSettings(document, function () { return doComplete.length > 2; })]; | ||
case 1: | ||
settings = _a.sent(); | ||
return [2 /*return*/, doComplete_1(document, textDocumentPosition.position, settings)]; | ||
case 2: return [2 /*return*/, { isIncomplete: true, items: [] }]; | ||
result = doComplete(document, textDocumentPosition.position, settings); | ||
return [2 /*return*/, result]; | ||
} | ||
}); | ||
}); }, null, "Error while computing completions for " + textDocumentPosition.textDocument.uri)]; | ||
}); }, null, "Error while computing completions for " + textDocumentPosition.textDocument.uri, token)]; | ||
}); | ||
}); }); | ||
connection.onCompletionResolve(function (item) { | ||
return errors_1.runSafe(function () { | ||
connection.onCompletionResolve(function (item, token) { | ||
return runner_1.runSafe(function () { | ||
var data = item.data; | ||
@@ -312,58 +330,68 @@ if (data && data.languageId && data.uri) { | ||
return item; | ||
}, null, "Error while resolving completion proposal"); | ||
}, item, "Error while resolving completion proposal", token); | ||
}); | ||
connection.onHover(function (textDocumentPosition) { | ||
return errors_1.runSafe(function () { | ||
connection.onHover(function (textDocumentPosition, token) { | ||
return runner_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); | ||
if (document) { | ||
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); | ||
}, null, "Error while computing hover for " + textDocumentPosition.textDocument.uri, token); | ||
}); | ||
connection.onDocumentHighlight(function (documentHighlightParams) { | ||
return errors_1.runSafe(function () { | ||
connection.onDocumentHighlight(function (documentHighlightParams, token) { | ||
return runner_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); | ||
if (document) { | ||
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); | ||
}, [], "Error while computing document highlights for " + documentHighlightParams.textDocument.uri, token); | ||
}); | ||
connection.onDefinition(function (definitionParams) { | ||
return errors_1.runSafe(function () { | ||
connection.onDefinition(function (definitionParams, token) { | ||
return runner_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); | ||
if (document) { | ||
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); | ||
}, null, "Error while computing definitions for " + definitionParams.textDocument.uri, token); | ||
}); | ||
connection.onReferences(function (referenceParams) { | ||
return errors_1.runSafe(function () { | ||
connection.onReferences(function (referenceParams, token) { | ||
return runner_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); | ||
if (document) { | ||
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); | ||
}, [], "Error while computing references for " + referenceParams.textDocument.uri, token); | ||
}); | ||
connection.onSignatureHelp(function (signatureHelpParms) { | ||
return errors_1.runSafe(function () { | ||
connection.onSignatureHelp(function (signatureHelpParms, token) { | ||
return runner_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); | ||
if (document) { | ||
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); | ||
}, null, "Error while computing signature help for " + signatureHelpParms.textDocument.uri, token); | ||
}); | ||
connection.onDocumentRangeFormatting(function (formatParams) { return __awaiter(_this, void 0, void 0, function () { | ||
connection.onDocumentRangeFormatting(function (formatParams, token) { 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 () { | ||
return [2 /*return*/, runner_1.runSafeAsync(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var document, settings, unformattedTags, enabledModes; | ||
@@ -374,2 +402,3 @@ return __generator(this, function (_a) { | ||
document = documents.get(formatParams.textDocument.uri); | ||
if (!document) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, getDocumentSettings(document, function () { return true; })]; | ||
@@ -384,9 +413,10 @@ case 1: | ||
return [2 /*return*/, formatting_1.format(languageModes, document, formatParams.range, formatParams.options, settings, enabledModes)]; | ||
case 2: return [2 /*return*/, []]; | ||
} | ||
}); | ||
}); }, [], "Error while formatting range for " + formatParams.textDocument.uri)]; | ||
}); }, [], "Error while formatting range for " + formatParams.textDocument.uri, token)]; | ||
}); | ||
}); }); | ||
connection.onDocumentLinks(function (documentLinkParam) { | ||
return errors_1.runSafe(function () { | ||
connection.onDocumentLinks(function (documentLinkParam, token) { | ||
return runner_1.runSafe(function () { | ||
var document = documents.get(documentLinkParam.textDocument.uri); | ||
@@ -403,18 +433,20 @@ var links = []; | ||
return links; | ||
}, [], "Error while document links for " + documentLinkParam.textDocument.uri); | ||
}, [], "Error while document links for " + documentLinkParam.textDocument.uri, token); | ||
}); | ||
connection.onDocumentSymbol(function (documentSymbolParms) { | ||
return errors_1.runSafe(function () { | ||
connection.onDocumentSymbol(function (documentSymbolParms, token) { | ||
return runner_1.runSafe(function () { | ||
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)); | ||
} | ||
}); | ||
if (document) { | ||
languageModes.getAllModesInDocument(document).forEach(function (m) { | ||
if (m.findDocumentSymbols) { | ||
arrays_1.pushAll(symbols, m.findDocumentSymbols(document)); | ||
} | ||
}); | ||
} | ||
return symbols; | ||
}, [], "Error while computing document symbols for " + documentSymbolParms.textDocument.uri); | ||
}, [], "Error while computing document symbols for " + documentSymbolParms.textDocument.uri, token); | ||
}); | ||
connection.onRequest(protocol_colorProvider_proposed_1.DocumentColorRequest.type, function (params) { | ||
return errors_1.runSafe(function () { | ||
connection.onRequest(vscode_languageserver_1.DocumentColorRequest.type, function (params, token) { | ||
return runner_1.runSafe(function () { | ||
var infos = []; | ||
@@ -430,6 +462,6 @@ var document = documents.get(params.textDocument.uri); | ||
return infos; | ||
}, [], "Error while computing document colors for " + params.textDocument.uri); | ||
}, [], "Error while computing document colors for " + params.textDocument.uri, token); | ||
}); | ||
connection.onRequest(protocol_colorProvider_proposed_1.ColorPresentationRequest.type, function (params) { | ||
return errors_1.runSafe(function () { | ||
connection.onRequest(vscode_languageserver_1.ColorPresentationRequest.type, function (params, token) { | ||
return runner_1.runSafe(function () { | ||
var document = documents.get(params.textDocument.uri); | ||
@@ -443,6 +475,6 @@ if (document) { | ||
return []; | ||
}, [], "Error while computing color presentations for " + params.textDocument.uri); | ||
}, [], "Error while computing color presentations for " + params.textDocument.uri, token); | ||
}); | ||
connection.onRequest(TagCloseRequest.type, function (params) { | ||
return errors_1.runSafe(function () { | ||
connection.onRequest(TagCloseRequest.type, function (params, token) { | ||
return runner_1.runSafe(function () { | ||
var document = documents.get(params.textDocument.uri); | ||
@@ -459,5 +491,15 @@ if (document) { | ||
return null; | ||
}, null, "Error while computing tag close actions for " + params.textDocument.uri); | ||
}, null, "Error while computing tag close actions for " + params.textDocument.uri, token); | ||
}); | ||
connection.onRequest(vscode_languageserver_protocol_foldingprovider_1.FoldingRangeRequest.type, function (params, token) { | ||
return runner_1.runSafe(function () { | ||
var document = documents.get(params.textDocument.uri); | ||
if (document) { | ||
return htmlFolding_1.getFoldingRanges(languageModes, document, foldingRangeLimit, token); | ||
} | ||
return null; | ||
}, null, "Error while computing folding regions for " + params.textDocument.uri, token); | ||
}); | ||
// Listen on the connection | ||
connection.listen(); | ||
//# sourceMappingURL=htmlServerMain.js.map |
@@ -74,1 +74,2 @@ /*--------------------------------------------------------------------------------------------- | ||
exports.getLanguageModelCache = getLanguageModelCache; | ||
//# sourceMappingURL=languageModelCache.js.map |
@@ -8,5 +8,6 @@ /*--------------------------------------------------------------------------------------------- | ||
var languageModelCache_1 = require("../languageModelCache"); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
var vscode_css_languageservice_1 = require("vscode-css-languageservice"); | ||
var embeddedSupport_1 = require("./embeddedSupport"); | ||
function getCSSMode(documentRegions) { | ||
function getCSSMode(documentRegions, workspace) { | ||
var cssLanguageService = vscode_css_languageservice_1.getCSSLanguageService(); | ||
@@ -19,12 +20,12 @@ var embeddedCSSDocuments = languageModelCache_1.getLanguageModelCache(10, 60, function (document) { return documentRegions.get(document).getEmbeddedDocument('css'); }); | ||
}, | ||
configure: function (options) { | ||
cssLanguageService.configure(options && options.css); | ||
}, | ||
doValidation: function (document, settings) { | ||
if (settings === void 0) { settings = workspace.settings; } | ||
var embedded = embeddedCSSDocuments.get(document); | ||
return cssLanguageService.doValidation(embedded, cssStylesheets.get(embedded), settings && settings.css); | ||
}, | ||
doComplete: function (document, position) { | ||
doComplete: function (document, position, settings) { | ||
if (settings === void 0) { settings = workspace.settings; } | ||
var embedded = embeddedCSSDocuments.get(document); | ||
return cssLanguageService.doComplete(embedded, position, cssStylesheets.get(embedded)); | ||
var stylesheet = cssStylesheets.get(embedded); | ||
return cssLanguageService.doComplete(embedded, position, stylesheet) || vscode_languageserver_types_1.CompletionList.create(); | ||
}, | ||
@@ -59,2 +60,7 @@ doHover: function (document, position) { | ||
}, | ||
getFoldingRanges: function (document, range) { | ||
var embedded = embeddedCSSDocuments.get(document); | ||
var ranges = cssLanguageService.getFoldingRanges(embedded, {}); | ||
return ranges.filter(function (r) { return r.startLine >= range.start.line && r.endLine < range.end.line; }); | ||
}, | ||
onDocumentRemoved: function (document) { | ||
@@ -71,1 +77,2 @@ embeddedCSSDocuments.onDocumentRemoved(document); | ||
exports.getCSSMode = getCSSMode; | ||
//# sourceMappingURL=cssMode.js.map |
@@ -215,1 +215,2 @@ /*--------------------------------------------------------------------------------------------- | ||
} | ||
//# sourceMappingURL=embeddedSupport.js.map |
@@ -7,3 +7,2 @@ /*--------------------------------------------------------------------------------------------- | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var edits_1 = require("../utils/edits"); | ||
var vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
@@ -53,3 +52,3 @@ var arrays_1 = require("../utils/arrays"); | ||
var htmlEdits = htmlMode.format(document, formatRange, formattingOptions, settings); | ||
var htmlFormattedContent = edits_1.applyEdits(document, htmlEdits); | ||
var htmlFormattedContent = vscode_languageserver_types_1.TextDocument.applyEdits(document, htmlEdits); | ||
var newDocument = vscode_languageserver_types_1.TextDocument.create(document.uri + '.tmp', document.languageId, document.version, htmlFormattedContent); | ||
@@ -67,4 +66,4 @@ try { | ||
var edits = mode.format(newDocument, r, formattingOptions, settings); | ||
for (var _a = 0, edits_2 = edits; _a < edits_2.length; _a++) { | ||
var edit = edits_2[_a]; | ||
for (var _a = 0, edits_1 = edits; _a < edits_1.length; _a++) { | ||
var edit = edits_1[_a]; | ||
embeddedEdits.push(edit); | ||
@@ -79,3 +78,3 @@ } | ||
// apply all embedded format edits and create a single edit for all changes | ||
var resultContent = edits_1.applyEdits(newDocument, embeddedEdits); | ||
var resultContent = vscode_languageserver_types_1.TextDocument.applyEdits(newDocument, embeddedEdits); | ||
var resultReplaceText = resultContent.substring(document.offsetAt(formatRange.start), resultContent.length - afterFormatRangeLength); | ||
@@ -90,1 +89,2 @@ result.push(vscode_languageserver_types_1.TextEdit.replace(formatRange, resultReplaceText)); | ||
exports.format = format; | ||
//# sourceMappingURL=formatting.js.map |
@@ -8,4 +8,4 @@ /*--------------------------------------------------------------------------------------------- | ||
var languageModelCache_1 = require("../languageModelCache"); | ||
function getHTMLMode(htmlLanguageService) { | ||
var globalSettings = {}; | ||
var pathCompletion_1 = require("./pathCompletion"); | ||
function getHTMLMode(htmlLanguageService, workspace) { | ||
var htmlDocuments = languageModelCache_1.getLanguageModelCache(10, 60, function (document) { return htmlLanguageService.parseHTMLDocument(document); }); | ||
@@ -16,7 +16,5 @@ return { | ||
}, | ||
configure: function (options) { | ||
globalSettings = options; | ||
}, | ||
doComplete: function (document, position, settings) { | ||
if (settings === void 0) { settings = globalSettings; } | ||
var _a; | ||
if (settings === void 0) { settings = workspace.settings; } | ||
var options = settings && settings.html && settings.html.suggest; | ||
@@ -27,3 +25,9 @@ var doAutoComplete = settings && settings.html && settings.html.autoClosingTags; | ||
} | ||
return htmlLanguageService.doComplete(document, position, htmlDocuments.get(document), options); | ||
var pathCompletionProposals = []; | ||
var participants = [pathCompletion_1.getPathCompletionParticipant(document, workspace.folders, pathCompletionProposals)]; | ||
htmlLanguageService.setCompletionParticipants(participants); | ||
var htmlDocument = htmlDocuments.get(document); | ||
var completionList = htmlLanguageService.doComplete(document, position, htmlDocument, options); | ||
(_a = completionList.items).push.apply(_a, pathCompletionProposals); | ||
return completionList; | ||
}, | ||
@@ -43,3 +47,3 @@ doHover: function (document, position) { | ||
format: function (document, range, formatParams, settings) { | ||
if (settings === void 0) { settings = globalSettings; } | ||
if (settings === void 0) { settings = workspace.settings; } | ||
var formatSettings = settings && settings.html && settings.html.format; | ||
@@ -61,2 +65,6 @@ if (formatSettings) { | ||
}, | ||
getFoldingRanges: function (document, range) { | ||
var ranges = htmlLanguageService.getFoldingRanges(document); | ||
return ranges.filter(function (r) { return r.startLine >= range.start.line && r.endLine < range.end.line; }); | ||
}, | ||
doAutoClose: function (document, position) { | ||
@@ -87,1 +95,2 @@ var offset = document.offsetAt(position); | ||
} | ||
//# sourceMappingURL=htmlMode.js.map |
@@ -12,6 +12,7 @@ /*--------------------------------------------------------------------------------------------- | ||
var path_1 = require("path"); | ||
var vscode_languageserver_protocol_foldingprovider_1 = require("vscode-languageserver-protocol-foldingprovider"); | ||
var FILE_NAME = 'vscode://javascript/1'; // the same 'file' is used for all contents | ||
var JQUERY_D_TS = path_1.join(__dirname, '../../lib/jquery.d.ts'); | ||
var JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g; | ||
function getJavascriptMode(documentRegions) { | ||
function getJavaScriptMode(documentRegions, workspace) { | ||
var jsDocuments = languageModelCache_1.getLanguageModelCache(10, 60, function (document) { return documentRegions.get(document).getEmbeddedDocument('javascript'); }); | ||
@@ -62,5 +63,2 @@ var compilerOptions = { allowNonTsExtensions: true, allowJs: true, lib: ['lib.es6.d.ts'], target: ts.ScriptTarget.Latest, moduleResolution: ts.ModuleResolutionKind.Classic }; | ||
}, | ||
configure: function (options) { | ||
globalSettings = options; | ||
}, | ||
doValidation: function (document) { | ||
@@ -108,3 +106,3 @@ updateCurrentTextDocument(document); | ||
updateCurrentTextDocument(document); | ||
var details = jsLanguageService.getCompletionEntryDetails(FILE_NAME, item.data.offset, item.label, undefined, undefined); | ||
var details = jsLanguageService.getCompletionEntryDetails(FILE_NAME, item.data.offset, item.label, undefined, undefined, undefined); | ||
if (details) { | ||
@@ -273,2 +271,24 @@ item.detail = ts.displayPartsToString(details.displayParts); | ||
}, | ||
getFoldingRanges: function (document, range) { | ||
updateCurrentTextDocument(document); | ||
var spans = jsLanguageService.getOutliningSpans(FILE_NAME); | ||
var rangeStartLine = range.start.line; | ||
var rangeEndLine = range.end.line; | ||
var ranges = []; | ||
for (var _i = 0, spans_1 = spans; _i < spans_1.length; _i++) { | ||
var span = spans_1[_i]; | ||
var curr = convertRange(currentTextDocument, span.textSpan); | ||
var startLine = curr.start.line; | ||
var endLine = curr.end.line; | ||
if (startLine < endLine && startLine >= rangeStartLine && endLine < rangeEndLine) { | ||
var foldingRange = { startLine: startLine, endLine: endLine }; | ||
var match = document.getText(curr).match(/^\s*\/(?:(\/\s*#(?:end)?region\b)|(\*|\/))/); | ||
if (match) { | ||
foldingRange.kind = match[1] ? vscode_languageserver_protocol_foldingprovider_1.FoldingRangeKind.Region : vscode_languageserver_protocol_foldingprovider_1.FoldingRangeKind.Comment; | ||
} | ||
ranges.push(foldingRange); | ||
} | ||
} | ||
return ranges; | ||
}, | ||
onDocumentRemoved: function (document) { | ||
@@ -283,3 +303,3 @@ jsDocuments.onDocumentRemoved(document); | ||
} | ||
exports.getJavascriptMode = getJavascriptMode; | ||
exports.getJavaScriptMode = getJavaScriptMode; | ||
function convertRange(document, span) { | ||
@@ -401,1 +421,2 @@ if (typeof span.start === 'undefined') { | ||
} | ||
//# sourceMappingURL=javascriptMode.js.map |
@@ -13,3 +13,3 @@ /*--------------------------------------------------------------------------------------------- | ||
var htmlMode_1 = require("./htmlMode"); | ||
function getLanguageModes(supportedLanguages) { | ||
function getLanguageModes(supportedLanguages, workspace) { | ||
var htmlLanguageService = vscode_html_languageservice_1.getLanguageService(); | ||
@@ -20,8 +20,8 @@ var documentRegions = languageModelCache_1.getLanguageModelCache(10, 60, function (document) { return embeddedSupport_1.getDocumentRegions(htmlLanguageService, document); }); | ||
var modes = Object.create(null); | ||
modes['html'] = htmlMode_1.getHTMLMode(htmlLanguageService); | ||
modes['html'] = htmlMode_1.getHTMLMode(htmlLanguageService, workspace); | ||
if (supportedLanguages['css']) { | ||
modes['css'] = cssMode_1.getCSSMode(documentRegions); | ||
modes['css'] = cssMode_1.getCSSMode(documentRegions, workspace); | ||
} | ||
if (supportedLanguages['javascript']) { | ||
modes['javascript'] = javascriptMode_1.getJavascriptMode(documentRegions); | ||
modes['javascript'] = javascriptMode_1.getJavaScriptMode(documentRegions, workspace); | ||
} | ||
@@ -87,1 +87,2 @@ return { | ||
exports.getLanguageModes = getLanguageModes; | ||
//# sourceMappingURL=languageModes.js.map |
{ | ||
"name": "vscode-html-languageserver-bin", | ||
"description": "Binary version published on npm of vscode-html-languageserver extracted from VSCode tree", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": "VSCode Langservers", | ||
@@ -11,8 +11,10 @@ "license": "MIT", | ||
"dependencies": { | ||
"vscode-css-languageservice": "^3.0.5", | ||
"vscode-html-languageservice": "^2.0.15", | ||
"vscode-languageserver": "^3.5.0", | ||
"vscode-nls": "^3.2.1", | ||
"vscode-uri": "^1.0.1", | ||
"typescript": "2.7.0-rc" | ||
"vscode-css-languageservice": "^3.0.9-next.18", | ||
"vscode-html-languageservice": "^2.1.3-next.5", | ||
"vscode-languageserver": "^4.1.3", | ||
"vscode-languageserver-protocol-foldingprovider": "^2.0.1", | ||
"vscode-languageserver-types": "^3.7.2", | ||
"vscode-nls": "^3.2.2", | ||
"vscode-uri": "^1.0.3", | ||
"typescript": "^2.9.1" | ||
}, | ||
@@ -19,0 +21,0 @@ "devDependencies": {}, |
# vscode-html-languageserver-bin | ||
[![npm](https://img.shields.io/npm/v/vscode-html-languageserver-bin.svg)](https://www.npmjs.com/package/vscode-html-languageserver-bin) | ||
[![Join the chat at https://gitter.im/vscode-langservers/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vscode-langservers/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
Binary version published on npm of [vscode-html-languageserver](https://github.com/vscode-langservers/vscode-html-languageserver) extracted from [VSCode tree](https://github.com/Microsoft/vscode/tree/master/extensions/html/server) | ||
@@ -14,2 +17,7 @@ | ||
# Clients | ||
- [Oni](https://github.com/onivim/oni) | ||
- [ide-html](https://github.com/liuderchi/ide-html) | ||
## Getting Started | ||
@@ -16,0 +24,0 @@ |
@@ -9,3 +9,3 @@ /*--------------------------------------------------------------------------------------------- | ||
var documentContext_1 = require("../utils/documentContext"); | ||
suite('Document Context', function () { | ||
suite('HTML Document Context', function () { | ||
test('Context', function () { | ||
@@ -21,1 +21,2 @@ var docURI = 'file:///users/test/folder/test.html'; | ||
}); | ||
//# sourceMappingURL=documentContext.test.js.map |
@@ -107,1 +107,2 @@ /*--------------------------------------------------------------------------------------------- | ||
}); | ||
//# sourceMappingURL=embedded.test.js.map |
@@ -16,6 +16,7 @@ /*--------------------------------------------------------------------------------------------- | ||
function assertFormat(value, expected, options, formatOptions, message) { | ||
var languageModes = languageModes_1.getLanguageModes({ css: true, javascript: true }); | ||
if (options) { | ||
languageModes.getAllModes().forEach(function (m) { return m.configure(options); }); | ||
} | ||
var workspace = { | ||
settings: options, | ||
folders: [{ name: 'foo', uri: 'test://foo' }] | ||
}; | ||
var languageModes = languageModes_1.getLanguageModes({ css: true, javascript: true }, workspace); | ||
var rangeStartOffset = value.indexOf('|'); | ||
@@ -38,8 +39,8 @@ var rangeEndOffset; | ||
var result = formatting_1.format(languageModes, document, range, formatOptions, void 0, { css: true, javascript: true }); | ||
var actual = applyEdits(document, result); | ||
var actual = vscode_languageserver_types_1.TextDocument.applyEdits(document, result); | ||
assert.equal(actual, expected, message); | ||
} | ||
function assertFormatWithFixture(fixtureName, expectedPath, options, formatOptions) { | ||
var input = fs.readFileSync(path.join(__dirname, 'fixtures', 'inputs', fixtureName)).toString(); | ||
var expected = fs.readFileSync(path.join(__dirname, 'fixtures', 'expected', expectedPath)).toString(); | ||
var input = fs.readFileSync(path.join(__dirname, 'fixtures', 'inputs', fixtureName)).toString().replace(/\r\n/mg, '\n'); | ||
var expected = fs.readFileSync(path.join(__dirname, 'fixtures', 'expected', expectedPath)).toString().replace(/\r\n/mg, '\n'); | ||
assertFormat(input, expected, options, formatOptions, expectedPath); | ||
@@ -97,22 +98,49 @@ } | ||
}); | ||
test('bug 48049', function () { | ||
assertFormat([ | ||
'<html>', | ||
'<head>', | ||
'</head>', | ||
'', | ||
'<body>', | ||
'', | ||
' <script>', | ||
' function f(x) {}', | ||
' f(function () {', | ||
' // ', | ||
'', | ||
' console.log(" vsc crashes on formatting")', | ||
' });', | ||
' </script>', | ||
'', | ||
'', | ||
'', | ||
' </body>', | ||
'', | ||
'</html>' | ||
].join('\n'), [ | ||
'<html>', | ||
'', | ||
'<head>', | ||
'</head>', | ||
'', | ||
'<body>', | ||
'', | ||
' <script>', | ||
' function f(x) {}', | ||
' f(function () {', | ||
' // ', | ||
'', | ||
' console.log(" vsc crashes on formatting")', | ||
' });', | ||
' </script>', | ||
'', | ||
'', | ||
'', | ||
'</body>', | ||
'', | ||
'</html>' | ||
].join('\n')); | ||
}); | ||
}); | ||
function applyEdits(document, edits) { | ||
var text = document.getText(); | ||
var sortedEdits = edits.sort(function (a, b) { | ||
var startDiff = document.offsetAt(b.range.start) - document.offsetAt(a.range.start); | ||
if (startDiff === 0) { | ||
return document.offsetAt(b.range.end) - document.offsetAt(a.range.end); | ||
} | ||
return startDiff; | ||
}); | ||
var lastOffset = text.length; | ||
sortedEdits.forEach(function (e) { | ||
var startOffset = document.offsetAt(e.range.start); | ||
var endOffset = document.offsetAt(e.range.end); | ||
assert.ok(startOffset <= endOffset); | ||
assert.ok(endOffset <= lastOffset); | ||
text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length); | ||
lastOffset = startOffset; | ||
}); | ||
return text; | ||
} | ||
//# sourceMappingURL=formatting.test.js.map |
@@ -9,3 +9,3 @@ /*--------------------------------------------------------------------------------------------- | ||
var words = require("../utils/strings"); | ||
suite('Words', function () { | ||
suite('HTML Words', function () { | ||
var wordRegex = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g; | ||
@@ -40,1 +40,2 @@ function assertWord(value, expected) { | ||
}); | ||
//# sourceMappingURL=words.test.js.map |
@@ -15,1 +15,64 @@ /*--------------------------------------------------------------------------------------------- | ||
exports.pushAll = pushAll; | ||
function contains(arr, val) { | ||
return arr.indexOf(val) !== -1; | ||
} | ||
exports.contains = contains; | ||
/** | ||
* Like `Array#sort` but always stable. Usually runs a little slower `than Array#sort` | ||
* so only use this when actually needing stable sort. | ||
*/ | ||
function mergeSort(data, compare) { | ||
_divideAndMerge(data, compare); | ||
return data; | ||
} | ||
exports.mergeSort = mergeSort; | ||
function _divideAndMerge(data, compare) { | ||
if (data.length <= 1) { | ||
// sorted | ||
return; | ||
} | ||
var p = (data.length / 2) | 0; | ||
var left = data.slice(0, p); | ||
var right = data.slice(p); | ||
_divideAndMerge(left, compare); | ||
_divideAndMerge(right, compare); | ||
var leftIdx = 0; | ||
var rightIdx = 0; | ||
var i = 0; | ||
while (leftIdx < left.length && rightIdx < right.length) { | ||
var ret = compare(left[leftIdx], right[rightIdx]); | ||
if (ret <= 0) { | ||
// smaller_equal -> take left to preserve order | ||
data[i++] = left[leftIdx++]; | ||
} | ||
else { | ||
// greater -> take right | ||
data[i++] = right[rightIdx++]; | ||
} | ||
} | ||
while (leftIdx < left.length) { | ||
data[i++] = left[leftIdx++]; | ||
} | ||
while (rightIdx < right.length) { | ||
data[i++] = right[rightIdx++]; | ||
} | ||
} | ||
function binarySearch(array, key, comparator) { | ||
var low = 0, high = array.length - 1; | ||
while (low <= high) { | ||
var mid = ((low + high) / 2) | 0; | ||
var comp = comparator(array[mid], key); | ||
if (comp < 0) { | ||
low = mid + 1; | ||
} | ||
else if (comp > 0) { | ||
high = mid - 1; | ||
} | ||
else { | ||
return mid; | ||
} | ||
} | ||
return -(low + 1); | ||
} | ||
exports.binarySearch = binarySearch; | ||
//# sourceMappingURL=arrays.js.map |
@@ -26,3 +26,3 @@ /*--------------------------------------------------------------------------------------------- | ||
if (base === void 0) { base = documentUri; } | ||
if (ref[0] === '/') { | ||
if (ref[0] === '/') { // resolve absolute path against the current workspace folder | ||
if (strings_1.startsWith(base, 'file://')) { | ||
@@ -40,1 +40,2 @@ var folderUri = getRootFolder(); | ||
exports.getDocumentContext = getDocumentContext; | ||
//# sourceMappingURL=documentContext.js.map |
@@ -78,1 +78,2 @@ /*--------------------------------------------------------------------------------------------- | ||
exports.isNewlineCharacter = isNewlineCharacter; | ||
//# sourceMappingURL=strings.js.map |
234762
43
2803
81
8
2
+ Addedvscode-languageserver-protocol-foldingprovider@^2.0.1
+ Addedtypescript@2.9.2(transitive)
+ Addedvscode-jsonrpc@8.2.0(transitive)
+ Addedvscode-languageserver@4.4.2(transitive)
+ Addedvscode-languageserver-protocol@3.17.5(transitive)
+ Addedvscode-languageserver-protocol-foldingprovider@2.0.1(transitive)
- Removedtypescript@2.7.0-rc(transitive)
- Removedvscode-jsonrpc@3.5.0(transitive)
- Removedvscode-languageserver@3.5.1(transitive)
- Removedvscode-languageserver-protocol@3.5.1(transitive)
- Removedvscode-languageserver-types@3.5.0(transitive)
Updatedtypescript@^2.9.1
Updatedvscode-languageserver@^4.1.3
Updatedvscode-nls@^3.2.2
Updatedvscode-uri@^1.0.3