From c769ce20e695d70173f62f0b0c41937f6abfcc8f Mon Sep 17 00:00:00 2001 From: Kees Schollaart Date: Sun, 18 Aug 2019 13:55:21 +0200 Subject: [PATCH] Updated a lot of dependencies --- package-lock.json | 119 ++++++++++---------------- package.json | 18 ++-- src/server/completionHelpers/utils.ts | 73 ---------------- src/server/fileAccessor.ts | 28 ++++-- src/server/haLanguageService.ts | 3 - src/server/server.ts | 2 +- 6 files changed, 80 insertions(+), 163 deletions(-) delete mode 100644 src/server/completionHelpers/utils.ts diff --git a/package-lock.json b/package-lock.json index bb12b40b43..b4c9672977 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,19 +25,13 @@ } }, "@babel/runtime": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.4.3.tgz", - "integrity": "sha512-9lsJwJLxDh/T3Q3SZszfWOTkk3pHbkmH+3KY+zwIDmsNlxsumuhS2TH3NIpktU4kNvfzy+k3eLT7aTJSPTo0OA==", + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.5.5.tgz", + "integrity": "sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ==", "requires": { "regenerator-runtime": "^0.13.2" } }, - "@types/events": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", - "integrity": "sha1-KGLz9Yqaf3w+eNefEw3U1xwlwqc=", - "dev": true - }, "@types/mocha": { "version": "5.2.7", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.7.tgz", @@ -45,18 +39,17 @@ "dev": true }, "@types/node": { - "version": "12.6.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.8.tgz", - "integrity": "sha512-aX+gFgA5GHcDi89KG5keey2zf0WfZk/HAQotEamsK2kbey+8yGKcson0hbK8E+v0NArlCJQCqMP161YhV6ZXLg==", + "version": "12.7.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.2.tgz", + "integrity": "sha512-dyYO+f6ihZEtNPDcWNR1fkoTDf3zAK3lAABDze3mz6POyIercH0lEUawUFXlG8xaQZmm1yEBON/4TsYv/laDYg==", "dev": true }, "@types/ws": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.1.tgz", - "integrity": "sha1-yno/N1aqEvYqCmIUXtFMbbJdWig=", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.2.tgz", + "integrity": "sha512-22XiR1ox9LftTaAtn/c5JCninwc7moaqbkJfaDUb7PkaUitcf5vbTZHdq9dxSMviCm9C3W85rzB8e6yNR70apQ==", "dev": true, "requires": { - "@types/events": "*", "@types/node": "*" } }, @@ -150,9 +143,9 @@ } }, "async-limiter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", - "integrity": "sha1-ePrtjD0HSrgfIrTphdeehzj3IPg=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, "async-listener": { "version": "0.6.10", @@ -541,9 +534,9 @@ "dev": true }, "home-assistant-js-websocket": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/home-assistant-js-websocket/-/home-assistant-js-websocket-4.0.0.tgz", - "integrity": "sha512-yWW9TKmr2Yj11+sSOdm+En7d8UFA68NIF+x7E7npUiMsb1+oBfSou5HvcZMf2S1eT4/YaDJI3ZIMkjb54Jv6IA==" + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/home-assistant-js-websocket/-/home-assistant-js-websocket-4.3.1.tgz", + "integrity": "sha512-eVIRdisSmcIzYKNSgB3gqUCrZpQkSUKlluYTsM0NqpUc4W0hHmF2vd8bShl3URWJXPOI5XPdeHuAPPqc0gUj+Q==" }, "http-proxy-agent": { "version": "2.1.0", @@ -859,9 +852,9 @@ "optional": true }, "psl": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.2.0.tgz", - "integrity": "sha512-GEn74ZffufCmkDDLNcl3uuyF/aSD6exEyh1v/ZSdAomB82t6G9hzJVRx0jBmLDW+VfZqks3aScmMw9DszwUalA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.3.0.tgz", + "integrity": "sha512-avHdspHO+9rQTLbv1RO+MPYeP/SzsCoxofjVnHanETfQhTJrmB0HlDoW+EiN/R+C0BZ+gERab9NY0lPN2TxNag==", "dev": true }, "punycode": { @@ -883,9 +876,9 @@ "dev": true }, "regenerator-runtime": { - "version": "0.13.2", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.2.tgz", - "integrity": "sha512-S/TQAZJO+D3m9xeN1WTI8dLKBBiRgXBlTJvbWjCThHWZj9EvHK70Ff50/tYj2J/fvBY6JtFVwRuazHN2E7M9BA==" + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz", + "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==" }, "request": { "version": "2.88.0", @@ -1143,9 +1136,9 @@ "dev": true }, "typescript": { - "version": "3.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", - "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.3.tgz", + "integrity": "sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==", "dev": true }, "typescript-json-schema": { @@ -1219,9 +1212,9 @@ } }, "vscode": { - "version": "1.1.35", - "resolved": "https://registry.npmjs.org/vscode/-/vscode-1.1.35.tgz", - "integrity": "sha512-xPnxzQU40LOS2yPyzWW+WKpTV6qA3z16TcgpZ9O38UWLA157Zz4GxUx5H7Gd07pxzw0GqvusbF4D+5GBgNxvEQ==", + "version": "1.1.36", + "resolved": "https://registry.npmjs.org/vscode/-/vscode-1.1.36.tgz", + "integrity": "sha512-cGFh9jmGLcTapCpPCKvn8aG/j9zVQ+0x5hzYJq5h5YyUXVGa1iamOaB2M2PZXoumQPES4qeAP1FwkI0b6tL4bQ==", "dev": true, "requires": { "glob": "^7.1.2", @@ -1295,34 +1288,21 @@ } }, "vscode-languageserver": { - "version": "5.3.0-next.8", - "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-5.3.0-next.8.tgz", - "integrity": "sha512-6vUb96wsRfrFqndril3gct/FBCSc24OxFZ2iz7kuEuXvLaIcEVOcSZIqQK8oFN7PdbAIaa9nnIpKSy4Yd15cIw==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-5.2.1.tgz", + "integrity": "sha512-GuayqdKZqAwwaCUjDvMTAVRPJOp/SLON3mJ07eGsx/Iq9HjRymhKWztX41rISqDKhHVVyFM+IywICyZDla6U3A==", "requires": { - "vscode-languageserver-protocol": "^3.15.0-next.6", - "vscode-textbuffer": "^1.0.0", + "vscode-languageserver-protocol": "3.14.1", "vscode-uri": "^1.0.6" } }, "vscode-languageserver-protocol": { - "version": "3.15.0-next.6", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.0-next.6.tgz", - "integrity": "sha512-/yDpYlWyNs26mM23mT73xmOFsh1iRfgZfBdHmfAxwDKwpQKLoOSqVidtYfxlK/pD3IEKGcAVnT4WXTsguxxAMQ==", + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.14.1.tgz", + "integrity": "sha512-IL66BLb2g20uIKog5Y2dQ0IiigW0XKrvmWiOvc0yXw80z3tMEzEnHjaGAb3ENuU7MnQqgnYJ1Cl2l9RvNgDi4g==", "requires": { - "vscode-jsonrpc": "^4.1.0-next.2", - "vscode-languageserver-types": "^3.15.0-next.2" - }, - "dependencies": { - "vscode-jsonrpc": { - "version": "4.1.0-next.2", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-4.1.0-next.2.tgz", - "integrity": "sha512-GsBLjP9DxQ42yl1mW9GEIlnSc0+R8mfzhaebwmmTPEJjezD5SPoAo3DFrIAFZha9yvQ1nzZfZlhtVpGQmgxtXg==" - }, - "vscode-languageserver-types": { - "version": "3.15.0-next.2", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.0-next.2.tgz", - "integrity": "sha512-2JkrMWWUi2rlVLSo9OFR2PIGUzdiowEM8NgNYiwLKnXTjpwpjjIrJbNNxDik7Rv4oo9KtikcFQZKXbrKilL/MQ==" - } + "vscode-jsonrpc": "^4.0.0", + "vscode-languageserver-types": "3.14.0" } }, "vscode-languageserver-types": { @@ -1345,15 +1325,10 @@ "https-proxy-agent": "^2.2.1" } }, - "vscode-textbuffer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/vscode-textbuffer/-/vscode-textbuffer-1.0.0.tgz", - "integrity": "sha512-zPaHo4urgpwsm+PrJWfNakolRpryNja18SUip/qIIsfhuEqEIPEXMxHOlFPjvDC4JgTaimkncNW7UMXRJTY6ow==" - }, "vscode-uri": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.6.tgz", - "integrity": "sha512-sLI2L0uGov3wKVb9EB+vIQBl9tVP90nqRvxSoJ35vI3NjxE8jfsE5DSOhWgSunHSZmKS4OCi2jrtfxK7uyp2ww==" + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.8.tgz", + "integrity": "sha512-obtSWTlbJ+a+TFRYGaUumtVwb+InIUVI0Lu0VBUAPmj2cU5JutEXg3xUE0c2J5Tcy7h2DEKVJBFi+Y9ZSFzzPQ==" }, "which-module": { "version": "2.0.0", @@ -1379,11 +1354,11 @@ "dev": true }, "ws": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.0.tgz", - "integrity": "sha1-E4BtmROypfPLubpHtWPAAsvHxSY=", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz", + "integrity": "sha512-gftXq3XI81cJCgkUiAVixA0raD9IVmXqsylCrjRygw4+UOOGzPoxnQ6r/CnVL9i+mDncJo94tSkyrtuuQVBmrg==", "requires": { - "async-limiter": "~1.0.0" + "async-limiter": "^1.0.0" } }, "y18n": { @@ -1393,11 +1368,11 @@ "dev": true }, "yaml": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.5.0.tgz", - "integrity": "sha512-nKxSWOa7vxAP2pikrGxbkZsG/garQseRiLn9mIDjzwoQsyVy7ZWIpLoARejnINGGLA4fttuzRFFNxxbsztdJgw==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.6.0.tgz", + "integrity": "sha512-iZfse3lwrJRoSlfs/9KQ9iIXxs9++RvBFVzAqbbBiFT+giYtyanevreF9r61ZTbGMgWQBxAua3FzJiniiJXWWw==", "requires": { - "@babel/runtime": "^7.4.3" + "@babel/runtime": "^7.4.5" } }, "yaml-ast-parser-custom-tags": { diff --git a/package.json b/package.json index 9fbbc7ebb9..c7ecce6619 100644 --- a/package.json +++ b/package.json @@ -136,24 +136,24 @@ "vscode:prepublish": "tsc -p ./" }, "devDependencies": { - "@types/mocha": "^5.2.7", - "@types/node": "^12.6.8", - "@types/ws": "6.0.1", + "@types/mocha": "5.2.7", + "@types/node": "12.7.2", + "@types/ws": "6.0.2", "@types/yaml": "1.0.2", "ts-node": "8.3.0", "tslint": "^5.18.0", - "typescript": "^3.4.5", + "typescript": "3.5.3", "typescript-json-schema": "0.39.0", - "vscode": "^1.1.35" + "vscode": "^1.1.36" }, "dependencies": { - "home-assistant-js-websocket": "4.0.0", - "ws": "6.2.0", + "home-assistant-js-websocket": "4.3.1", + "ws": "7.1.2", "vscode-json-languageservice": "3.3.1", "vscode-languageclient": "5.2.1", - "vscode-languageserver": "5.3.0-next.8", + "vscode-languageserver": "5.2.1", "yaml-language-server": "0.5.3", - "yaml": "1.5.0", + "yaml": "1.6.0", "vscode-extension-telemetry": "0.1.2" } } diff --git a/src/server/completionHelpers/utils.ts b/src/server/completionHelpers/utils.ts deleted file mode 100644 index f507c0ed53..0000000000 --- a/src/server/completionHelpers/utils.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { TextDocument, Position } from "vscode-languageserver"; -import { getLineOffsets } from "yaml-language-server/out/server/src/languageservice/utils/arrUtils"; -import { EntityIdCompletionContribution } from "./entityIds"; - -// this is the updated implementation from -// https://github.com/Microsoft/azure-pipelines-language-server/blob/master/language-service/src/utils/yamlServiceUtils.ts -// which works better than the original yaml-language-server one - -export const nodeHolder = "~"; //This won't conflict with any legal Pipelines nodes - -const nodeLineEnding = ":\r\n"; -const nodeHolderWithEnding = nodeHolder + nodeLineEnding; - -function is_EOL(c: number) { - return (c === 0x0A/* LF */) || (c === 0x0D/* CR */); -} - -export interface CompletionAdjustment { - newText: string; - newPosition: Position; -} - -export function completionHelper(document: TextDocument, textDocumentPosition: Position): CompletionAdjustment { - // Get the string we are looking at via a substring - const lineNumber: number = textDocumentPosition.line; - const lineOffsets: number[] = getLineOffsets(document.getText()); - const start: number = lineOffsets[lineNumber]; // Start of where the autocompletion is happening - let end = 0; // End of where the autocompletion is happening - - if (lineOffsets[lineNumber + 1] !== undefined) { - end = lineOffsets[lineNumber + 1]; - } else { - end = document.getText().length; - } - - while (end - 1 >= start && is_EOL(document.getText().charCodeAt(end - 1))) { - end--; - } - - const textLine = document.getText().substring(start, end); - - // Check if the string we are looking at is a node - if (textLine.indexOf(":") === -1) { - // We need to add the ":" to load the nodes - const documentText = document.getText(); - - let newText = ""; - - // This is for the empty line case - const trimmedText = textLine.trim(); - if (trimmedText.length === 0 || (trimmedText.length === 1 && trimmedText[0] === '-')) { - // Add a temp node that is in the document but we don't use at all. - newText = documentText.substring(0, start + textDocumentPosition.character) + nodeHolderWithEnding + documentText.substr(start + textDocumentPosition.character); - } else { - // Add a colon to the end of the current line so we can validate the node - newText = documentText.substring(0, start + textLine.length) + nodeLineEnding + documentText.substr(lineOffsets[lineNumber + 1] || documentText.length); - } - - return { - newText: newText, - newPosition: textDocumentPosition, - }; - - } else { - // All the nodes are loaded - textDocumentPosition.character = textDocumentPosition.character - 1; - return { - newText: document.getText(), - newPosition: textDocumentPosition, - }; - } -} - \ No newline at end of file diff --git a/src/server/fileAccessor.ts b/src/server/fileAccessor.ts index 2c3e40962c..bf34a79f05 100644 --- a/src/server/fileAccessor.ts +++ b/src/server/fileAccessor.ts @@ -1,4 +1,4 @@ -import { IConnection, TextDocument, TextDocuments } from "vscode-languageserver"; +import { TextDocuments } from "vscode-languageserver"; import * as fs from "fs"; import * as path from "path"; import Uri from 'vscode-uri'; @@ -15,7 +15,11 @@ export interface FileAccessor { export class VsCodeFileAccessor implements FileAccessor { - constructor(private workspaceFolder: string, private connection: IConnection, private documents: TextDocuments) { } + private ourRoot: string; + + constructor(private workspaceFolder: string, private documents: TextDocuments) { + this.ourRoot = path.resolve(); + } public async getFileContents(uri: string): Promise { var fullUri = Uri.file(path.resolve(uri)); @@ -38,6 +42,7 @@ export class VsCodeFileAccessor implements FileAccessor { public getFilesInFolder(subFolder: string, filelist: string[] = []): string[] { subFolder = path.normalize(subFolder); + try { fs.readdirSync(subFolder).forEach(file => { filelist = fs.statSync(path.join(subFolder, file)).isDirectory() @@ -51,8 +56,21 @@ export class VsCodeFileAccessor implements FileAccessor { return filelist; } + private dealtWithRelativeFrom = (relativeFrom: string): string => { + if (relativeFrom.startsWith("file://")) { + relativeFrom = Uri.parse(relativeFrom).fsPath; + } + else { + if (!relativeFrom.startsWith(this.ourRoot)) { + relativeFrom = path.resolve(relativeFrom); + } + relativeFrom = Uri.file(relativeFrom).fsPath; + } + return relativeFrom; + } + public getFilesInFolderRelativeFrom(subFolder: string, relativeFrom: string): string[] { - relativeFrom = Uri.parse(relativeFrom).fsPath; + relativeFrom = this.dealtWithRelativeFrom(relativeFrom); var dirOfFile = path.dirname(relativeFrom); subFolder = path.join(dirOfFile, subFolder); @@ -65,7 +83,7 @@ export class VsCodeFileAccessor implements FileAccessor { } public getRelativePath = (relativeFrom: string, filename: string): string => { - relativeFrom = Uri.parse(relativeFrom).fsPath; + relativeFrom = this.dealtWithRelativeFrom(relativeFrom); var dirOfFile = path.dirname(relativeFrom); let joinedPath = path.join(dirOfFile, filename); @@ -81,7 +99,7 @@ export class VsCodeFileAccessor implements FileAccessor { let workspaceFolderUri = Uri.parse(this.workspaceFolder); let fileUri = Uri.parse(uri); let local = fileUri.fsPath.replace(workspaceFolderUri.fsPath, ""); - if (local[0] === "/" || local[0] === "\\"){ + if (local[0] === "/" || local[0] === "\\") { local = local.substring(1); } // let joined = path.join(workspaceFolderUri.fsPath, uri); diff --git a/src/server/haLanguageService.ts b/src/server/haLanguageService.ts index 1ec39061f1..5bd092d458 100644 --- a/src/server/haLanguageService.ts +++ b/src/server/haLanguageService.ts @@ -1,6 +1,4 @@ import { TextDocuments, CompletionList, TextDocumentChangeEvent, DidChangeWatchedFilesParams, DidOpenTextDocumentParams, TextDocument, Position, CompletionItem, TextEdit, Definition, DefinitionLink, TextDocumentPositionParams, Location, IConnection, Diagnostic, Hover } from "vscode-languageserver"; -import { completionHelper } from "./completionHelpers/utils"; -import { parse as parseYAML } from "yaml-language-server/out/server/src/languageservice/parser/yamlParser07"; import { YamlLanguageService } from "./yamlLanguageService"; import { SchemaServiceForIncludes } from "./schemas/schemaService"; import { EntityIdCompletionContribution } from "./completionHelpers/entityIds"; @@ -10,7 +8,6 @@ import { ServicesCompletionContribution } from "./completionHelpers/services"; import { DefinitionProvider } from "./definition/definition"; import { HomeAssistantConfiguration } from "./haConfig/haConfig"; - export class HomeAssistantLanguageService { constructor( diff --git a/src/server/server.ts b/src/server/server.ts index 84a78cdd0e..7597c053f0 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -30,7 +30,7 @@ connection.onInitialize(async params => { var configurationService = new ConfigurationService(); var haConnection = new HaConnection(configurationService); - var fileAccessor = new VsCodeFileAccessor(params.rootUri, connection, documents); + var fileAccessor = new VsCodeFileAccessor(params.rootUri, documents); var haConfig = new HomeAssistantConfiguration(fileAccessor); var definitionProviders = [