diff --git a/package.json b/package.json index 53ff50c..2e245fd 100644 --- a/package.json +++ b/package.json @@ -101,8 +101,8 @@ }, "dependencies": { "vscode-extension-telemetry": "0.0.17", - "vscode-languageclient": "^4.0.0", - "vscode-languageserver-protocol-foldingprovider": "^2.0.0-next.2", + "vscode-languageclient": "^4.1.4", + "vscode-languageserver-protocol-foldingprovider": "^2.0.1", "vscode-nls": "^3.2.2" }, "devDependencies": { diff --git a/server/package.json b/server/package.json index 3f4cc77..8ae8056 100644 --- a/server/package.json +++ b/server/package.json @@ -13,9 +13,9 @@ "dependencies": { "jsonc-parser": "^2.0.0-next.1", "request-light": "^0.2.2", - "vscode-json-languageservice": "^3.1.2-next.2", - "vscode-languageserver": "^4.0.0", - "vscode-languageserver-protocol-foldingprovider": "^2.0.0-next.2", + "vscode-json-languageservice": "^3.1.2-next.3", + "vscode-languageserver": "^4.1.3", + "vscode-languageserver-protocol-foldingprovider": "^2.0.1", "vscode-nls": "^3.2.2", "vscode-uri": "^1.0.3" }, diff --git a/server/src/jsonServerMain.ts b/server/src/jsonServerMain.ts index 295e44d..2fa7619 100644 --- a/server/src/jsonServerMain.ts +++ b/server/src/jsonServerMain.ts @@ -38,7 +38,7 @@ namespace SchemaContentChangeNotification { } // Create a connection for the server -let connection: IConnection = createConnection(); +const connection: IConnection = createConnection(); process.on('unhandledRejection', (e: any) => { console.error(formatError(`Unhandled exception`, e)); @@ -53,7 +53,7 @@ console.error = connection.console.error.bind(connection.console); // Create a simple text document manager. The text document manager // supports full document sync only -let documents: TextDocuments = new TextDocuments(); +const documents: TextDocuments = new TextDocuments(); // Make the text document manager listen on the connection // for open, change and close text document events documents.listen(connection); @@ -67,7 +67,7 @@ let foldingRangeLimit = Number.MAX_VALUE; connection.onInitialize((params: InitializeParams): InitializeResult => { function getClientCapability(name: string, def: T) { - let keys = name.split('.'); + const keys = name.split('.'); let c: any = params.capabilities; for (let i = 0; c && i < keys.length; i++) { if (!c.hasOwnProperty(keys[i])) { @@ -81,7 +81,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => { clientSnippetSupport = getClientCapability('textDocument.completion.completionItem.snippetSupport', false); clientDynamicRegisterSupport = getClientCapability('workspace.symbol.dynamicRegistration', false); foldingRangeLimit = getClientCapability('textDocument.foldingRange.rangeLimit', Number.MAX_VALUE); - let capabilities: ServerCapabilities & FoldingRangeServerCapabilities = { + const capabilities: ServerCapabilities & FoldingRangeServerCapabilities = { // Tell the client that the server works in FULL text document sync mode textDocumentSync: documents.syncKind, completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['"', ':'] } : void 0, @@ -95,15 +95,15 @@ connection.onInitialize((params: InitializeParams): InitializeResult => { return { capabilities }; }); -let workspaceContext = { +const workspaceContext = { resolveRelativePath: (relativePath: string, resource: string) => { return URL.resolve(resource, relativePath); } }; -let schemaRequestService = (uri: string): Thenable => { +const schemaRequestService = (uri: string): Thenable => { if (startsWith(uri, 'file://')) { - let fsPath = URI.parse(uri).fsPath; + const fsPath = URI.parse(uri).fsPath; return new Promise((c, e) => { fs.readFile(fsPath, 'UTF-8', (err, result) => { err ? e('') : c(result.toString()); @@ -129,7 +129,7 @@ let schemaRequestService = (uri: string): Thenable => { } }); } - let headers = { 'Accept-Encoding': 'gzip, deflate' }; + const headers = { 'Accept-Encoding': 'gzip, deflate' }; return xhr({ url: uri, followRedirects: 5, headers }).then(response => { return response.responseText; }, (error: XHRResponse) => { @@ -138,7 +138,7 @@ let schemaRequestService = (uri: string): Thenable => { }; // create the JSON language service -let languageService = getLanguageService({ +const languageService = getLanguageService({ schemaRequestService, workspaceContext, contributions: [] @@ -176,7 +176,7 @@ connection.onDidChangeConfiguration((change) => { // dynamically enable & disable the formatter if (clientDynamicRegisterSupport) { - let enableFormatter = settings && settings.json && settings.json.format && settings.json.format.enable; + const enableFormatter = settings && settings.json && settings.json.format && settings.json.format.enable; if (enableFormatter) { if (!formatterRegistration) { formatterRegistration = connection.client.register(DocumentRangeFormattingRequest.type, { documentSelector: [{ language: 'json' }, { language: 'jsonc' }] }); @@ -200,14 +200,14 @@ connection.onNotification(SchemaContentChangeNotification.type, uri => { }); function updateConfiguration() { - let languageSettings = { + const languageSettings = { validate: true, allowComments: true, schemas: new Array() }; if (schemaAssociations) { for (var pattern in schemaAssociations) { - let association = schemaAssociations[pattern]; + const association = schemaAssociations[pattern]; if (Array.isArray(association)) { association.forEach(uri => { languageSettings.schemas.push({ uri, fileMatch: [pattern] }); @@ -244,11 +244,11 @@ documents.onDidClose(event => { connection.sendDiagnostics({ uri: event.document.uri, diagnostics: [] }); }); -let pendingValidationRequests: { [uri: string]: NodeJS.Timer; } = {}; +const pendingValidationRequests: { [uri: string]: NodeJS.Timer; } = {}; const validationDelayMs = 500; function cleanPendingValidation(textDocument: TextDocument): void { - let request = pendingValidationRequests[textDocument.uri]; + const request = pendingValidationRequests[textDocument.uri]; if (request) { clearTimeout(request); delete pendingValidationRequests[textDocument.uri]; @@ -269,13 +269,13 @@ function validateTextDocument(textDocument: TextDocument): void { connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] }); return; } - let jsonDocument = getJSONDocument(textDocument); - let version = textDocument.version; + const jsonDocument = getJSONDocument(textDocument); + const version = textDocument.version; - let documentSettings: DocumentLanguageSettings = textDocument.languageId === 'jsonc' ? { comments: 'ignore', trailingCommas: 'ignore' } : { comments: 'error', trailingCommas: 'error' }; + const documentSettings: DocumentLanguageSettings = textDocument.languageId === 'jsonc' ? { comments: 'ignore', trailingCommas: 'ignore' } : { comments: 'error', trailingCommas: 'error' }; languageService.doValidation(textDocument, jsonDocument, documentSettings).then(diagnostics => { setTimeout(() => { - let currDocument = documents.get(textDocument.uri); + const currDocument = documents.get(textDocument.uri); if (currDocument && currDocument.version === version) { // Send the computed diagnostics to VSCode. connection.sendDiagnostics({ uri: textDocument.uri, diagnostics }); @@ -299,7 +299,7 @@ connection.onDidChangeWatchedFiles((change) => { } }); -let jsonDocuments = getLanguageModelCache(10, 60, document => languageService.parseJSONDocument(document)); +const jsonDocuments = getLanguageModelCache(10, 60, document => languageService.parseJSONDocument(document)); documents.onDidClose(e => { jsonDocuments.onDocumentRemoved(e.document); }); @@ -312,10 +312,13 @@ function getJSONDocument(document: TextDocument): JSONDocument { } connection.onCompletion((textDocumentPosition, token) => { - return runSafeAsync(() => { - let document = documents.get(textDocumentPosition.textDocument.uri); - let jsonDocument = getJSONDocument(document); - return languageService.doComplete(document, textDocumentPosition.position, jsonDocument); + return runSafeAsync(async () => { + const document = documents.get(textDocumentPosition.textDocument.uri); + if (document) { + const jsonDocument = getJSONDocument(document); + return languageService.doComplete(document, textDocumentPosition.position, jsonDocument); + } + return null; }, null, `Error while computing completions for ${textDocumentPosition.textDocument.uri}`, token); }); @@ -326,44 +329,53 @@ connection.onCompletionResolve((completionItem, token) => { }); connection.onHover((textDocumentPositionParams, token) => { - return runSafeAsync(() => { - let document = documents.get(textDocumentPositionParams.textDocument.uri); - let jsonDocument = getJSONDocument(document); - return languageService.doHover(document, textDocumentPositionParams.position, jsonDocument); + return runSafeAsync(async () => { + const document = documents.get(textDocumentPositionParams.textDocument.uri); + if (document) { + const jsonDocument = getJSONDocument(document); + return languageService.doHover(document, textDocumentPositionParams.position, jsonDocument); + } + return null; }, null, `Error while computing hover for ${textDocumentPositionParams.textDocument.uri}`, token); }); connection.onDocumentSymbol((documentSymbolParams, token) => { return runSafe(() => { - let document = documents.get(documentSymbolParams.textDocument.uri); - let jsonDocument = getJSONDocument(document); - return languageService.findDocumentSymbols(document, jsonDocument); + const document = documents.get(documentSymbolParams.textDocument.uri); + if (document) { + const jsonDocument = getJSONDocument(document); + return languageService.findDocumentSymbols(document, jsonDocument); + } + return []; }, [], `Error while computing document symbols for ${documentSymbolParams.textDocument.uri}`, token); }); connection.onDocumentRangeFormatting((formatParams, token) => { return runSafe(() => { - let document = documents.get(formatParams.textDocument.uri); - return languageService.format(document, formatParams.range, formatParams.options); + const document = documents.get(formatParams.textDocument.uri); + if (document) { + return languageService.format(document, formatParams.range, formatParams.options); + } + return []; }, [], `Error while formatting range for ${formatParams.textDocument.uri}`, token); }); connection.onDocumentColor((params, token) => { - return runSafeAsync(() => { - let document = documents.get(params.textDocument.uri); + return runSafeAsync(async () => { + const document = documents.get(params.textDocument.uri); if (document) { - let jsonDocument = getJSONDocument(document); + const jsonDocument = getJSONDocument(document); return languageService.findDocumentColors(document, jsonDocument); } - return Promise.resolve([]); + return []; }, [], `Error while computing document colors for ${params.textDocument.uri}`, token); }); connection.onColorPresentation((params, token) => { return runSafe(() => { - let document = documents.get(params.textDocument.uri); + const document = documents.get(params.textDocument.uri); if (document) { - let jsonDocument = getJSONDocument(document); + const jsonDocument = getJSONDocument(document); return languageService.getColorPresentations(document, jsonDocument, params.color, params.range); } return []; @@ -372,7 +384,7 @@ connection.onColorPresentation((params, token) => { connection.onRequest(FoldingRangeRequest.type, (params, token) => { return runSafe(() => { - let document = documents.get(params.textDocument.uri); + const document = documents.get(params.textDocument.uri); if (document) { return languageService.getFoldingRanges(document, { rangeLimit: foldingRangeLimit }); } diff --git a/server/yarn.lock b/server/yarn.lock index 26fe224..ce5677e 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -72,56 +72,48 @@ request-light@^0.2.2: https-proxy-agent "2.1.1" vscode-nls "^2.0.2" -vscode-json-languageservice@^3.1.2-next.2: - version "3.1.2-next.2" - resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.1.2-next.2.tgz#da5346e5c22edbce739f29c110eb41732d41dc2d" +vscode-json-languageservice@^3.1.2-next.3: + version "3.1.2-next.3" + resolved "https://registry.yarnpkg.com/vscode-json-languageservice/-/vscode-json-languageservice-3.1.2-next.3.tgz#cc0902148f898b413987fb1b4c4a9e7fc1a79c78" dependencies: jsonc-parser "^2.0.0" - vscode-languageserver-types "^3.6.1" - vscode-nls "^3.2.1" + vscode-languageserver-types "^3.7.2" + vscode-nls "^3.2.2" vscode-uri "^1.0.3" -vscode-jsonrpc@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.0.tgz#848d56995d5168950d84feb5d9c237ae5c6a02d4" +vscode-jsonrpc@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8" -vscode-languageserver-protocol-foldingprovider@^2.0.0-next.2: - version "2.0.0-next.2" - resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol-foldingprovider/-/vscode-languageserver-protocol-foldingprovider-2.0.0-next.2.tgz#fbb9cfdf5b8c4ac451826ba6312f1f88379f35b0" +vscode-languageserver-protocol-foldingprovider@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol-foldingprovider/-/vscode-languageserver-protocol-foldingprovider-2.0.1.tgz#051d0d9e58d1b79dc4681acd48f21797f5515bfd" dependencies: - vscode-languageserver-protocol "^3.6.0" - vscode-languageserver-types "^3.6.0" + vscode-languageserver-protocol "^3.7.2" + vscode-languageserver-types "^3.7.2" -vscode-languageserver-protocol@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.6.0.tgz#579642cdcccf74b0cd771c33daa3239acb40d040" +vscode-languageserver-protocol@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.7.2.tgz#df58621c032139010888b6a9ddc969423f9ba9d6" dependencies: - vscode-jsonrpc "^3.6.0" - vscode-languageserver-types "^3.6.0" + vscode-jsonrpc "^3.6.2" + vscode-languageserver-types "^3.7.2" -vscode-languageserver-types@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.6.0.tgz#0bba63b0fa82a714394a4478f55a596ee4ed7d0a" +vscode-languageserver-types@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.7.2.tgz#aad8846f8e3e27962648554de5a8417e358f34eb" -vscode-languageserver-types@^3.6.1: - version "3.6.1" - resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.6.1.tgz#4bc06a48dff653495f12f94b8b1e228988a1748d" - -vscode-languageserver@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.0.0.tgz#8b792f0d6d10acfe363d02371ed4ce53d08af88a" +vscode-languageserver@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.1.3.tgz#937d37c955b6b9c2409388413cd6f54d1eb9fe7d" dependencies: - vscode-languageserver-protocol "^3.6.0" + vscode-languageserver-protocol "^3.7.2" vscode-uri "^1.0.1" vscode-nls@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-2.0.2.tgz#808522380844b8ad153499af5c3b03921aea02da" -vscode-nls@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-3.2.1.tgz#b1f3e04e8a94a715d5a7bcbc8339c51e6d74ca51" - vscode-nls@^3.2.2: version "3.2.2" resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-3.2.2.tgz#3817eca5b985c2393de325197cf4e15eb2aa5350" diff --git a/yarn.lock b/yarn.lock index ccfd30a..36c0c89 100644 --- a/yarn.lock +++ b/yarn.lock @@ -34,33 +34,33 @@ vscode-extension-telemetry@0.0.17: dependencies: applicationinsights "1.0.1" -vscode-jsonrpc@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.0.tgz#848d56995d5168950d84feb5d9c237ae5c6a02d4" +vscode-jsonrpc@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8" -vscode-languageclient@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.0.0.tgz#635f5bfbcfa1385dae489b394857f1db8b459a7d" +vscode-languageclient@^4.1.4: + version "4.1.4" + resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.1.4.tgz#fff1a6bca4714835dca7fce35bc4ce81442fdf2c" dependencies: - vscode-languageserver-protocol "^3.6.0" + vscode-languageserver-protocol "^3.7.2" -vscode-languageserver-protocol-foldingprovider@^2.0.0-next.2: - version "2.0.0-next.2" - resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol-foldingprovider/-/vscode-languageserver-protocol-foldingprovider-2.0.0-next.2.tgz#fbb9cfdf5b8c4ac451826ba6312f1f88379f35b0" +vscode-languageserver-protocol-foldingprovider@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol-foldingprovider/-/vscode-languageserver-protocol-foldingprovider-2.0.1.tgz#051d0d9e58d1b79dc4681acd48f21797f5515bfd" dependencies: - vscode-languageserver-protocol "^3.6.0" - vscode-languageserver-types "^3.6.0" + vscode-languageserver-protocol "^3.7.2" + vscode-languageserver-types "^3.7.2" -vscode-languageserver-protocol@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.6.0.tgz#579642cdcccf74b0cd771c33daa3239acb40d040" +vscode-languageserver-protocol@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.7.2.tgz#df58621c032139010888b6a9ddc969423f9ba9d6" dependencies: - vscode-jsonrpc "^3.6.0" - vscode-languageserver-types "^3.6.0" + vscode-jsonrpc "^3.6.2" + vscode-languageserver-types "^3.7.2" -vscode-languageserver-types@^3.6.0: - version "3.6.0" - resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.6.0.tgz#0bba63b0fa82a714394a4478f55a596ee4ed7d0a" +vscode-languageserver-types@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.7.2.tgz#aad8846f8e3e27962648554de5a8417e358f34eb" vscode-nls@^3.2.2: version "3.2.2"