From 188abb0ffb08029755fb79e088fd6c18410bb6c0 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:08:13 +0100 Subject: [PATCH 01/21] Add windows fixes for files --- client/package-lock.json | 258 +-------------------------------------- package.json | 2 + server/src/utils.ts | 100 +++++++++------ 3 files changed, 66 insertions(+), 294 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 8ea3f702a..28ef10034 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1,264 +1,8 @@ { "name": "rescript-language-client", "version": "0.0.1", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "rescript-language-client", - "version": "0.0.1", - "license": "MIT", - "dependencies": { - "vscode-languageclient": "^6.1.3" - }, - "devDependencies": { - "@types/vscode": "1.43.0", - "vscode-test": "^1.3.0" - }, - "engines": { - "vscode": "^1.43.0" - } - }, - "node_modules/@types/vscode": { - "version": "1.43.0", - "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.43.0.tgz", - "integrity": "sha512-kIaR9qzd80rJOxePKpCB/mdy00mz8Apt2QA5Y6rdrKFn13QNFNeP3Hzmsf37Bwh/3cS7QjtAeGSK7wSqAU0sYQ==", - "dev": true - }, - "node_modules/agent-base": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", - "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", - "dev": true, - "dependencies": { - "es6-promisify": "^5.0.0" - }, - "engines": { - "node": ">= 4.0.0" - } - }, - "node_modules/balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "node_modules/debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", - "dev": true - }, - "node_modules/es6-promisify": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", - "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", - "dev": true, - "dependencies": { - "es6-promise": "^4.0.3" - } - }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "node_modules/glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - } - }, - "node_modules/http-proxy-agent": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-2.1.0.tgz", - "integrity": "sha512-qwHbBLV7WviBl0rQsOzH6o5lwyOIvwp/BdFnvVxXORldu5TmjFfjzBcWUWS5kWAZhmv+JtiDhSuQCp4sBfbIgg==", - "dev": true, - "dependencies": { - "agent-base": "4", - "debug": "3.1.0" - }, - "engines": { - "node": ">= 4.5.0" - } - }, - "node_modules/https-proxy-agent": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", - "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", - "dev": true, - "dependencies": { - "agent-base": "^4.3.0", - "debug": "^3.1.0" - }, - "engines": { - "node": ">= 4.5.0" - } - }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - } - }, - "node_modules/vscode-jsonrpc": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz", - "integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==", - "engines": { - "node": ">=8.0.0 || >=10.0.0" - } - }, - "node_modules/vscode-languageclient": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.1.3.tgz", - "integrity": "sha512-YciJxk08iU5LmWu7j5dUt9/1OLjokKET6rME3cI4BRpiF6HZlusm2ZwPt0MYJ0lV5y43sZsQHhyon2xBg4ZJVA==", - "dependencies": { - "semver": "^6.3.0", - "vscode-languageserver-protocol": "^3.15.3" - }, - "engines": { - "vscode": "^1.41.0" - } - }, - "node_modules/vscode-languageclient/node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "bin": { - "semver": "bin/semver.js" - } - }, - "node_modules/vscode-languageserver-protocol": { - "version": "3.15.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz", - "integrity": "sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==", - "dependencies": { - "vscode-jsonrpc": "^5.0.1", - "vscode-languageserver-types": "3.15.1" - } - }, - "node_modules/vscode-languageserver-types": { - "version": "3.15.1", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz", - "integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==" - }, - "node_modules/vscode-test": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/vscode-test/-/vscode-test-1.3.0.tgz", - "integrity": "sha512-LddukcBiSU2FVTDr3c1D8lwkiOvwlJdDL2hqVbn6gIz+rpTqUCkMZSKYm94Y1v0WXlHSDQBsXyY+tchWQgGVsw==", - "dev": true, - "dependencies": { - "http-proxy-agent": "^2.1.0", - "https-proxy-agent": "^2.2.4", - "rimraf": "^2.6.3" - }, - "engines": { - "node": ">=8.9.3" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - } - }, "dependencies": { "@types/vscode": { "version": "1.43.0", diff --git a/package.json b/package.json index 31150ee09..b2dc2cc24 100644 --- a/package.json +++ b/package.json @@ -108,9 +108,11 @@ "devDependencies": { "@types/mocha": "^7.0.2", "@types/node": "^12.12.0", + "@typescript-eslint/eslint-plugin": "^4.14.0", "@typescript-eslint/parser": "^2.3.0", "eslint": "^6.4.0", "mocha": "^8.0.1", + "prettier": "^2.2.1", "typescript": "^3.9.4" }, "dependencies": { diff --git a/server/src/utils.ts b/server/src/utils.ts index c877b2233..4970594b2 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -7,21 +7,21 @@ import * as t from "vscode-languageserver-types"; import fs from "fs"; import * as os from "os"; -let tempFilePrefix = "rescript_format_file_" + process.pid + "_"; +const tempFilePrefix = "rescript_format_file_" + process.pid + "_"; let tempFileId = 0; -export let createFileInTempDir = (extension = "") => { - let tempFileName = tempFilePrefix + tempFileId + extension; +export const createFileInTempDir = (extension = "") => { + const tempFileName = tempFilePrefix + tempFileId + extension; tempFileId = tempFileId + 1; return path.join(os.tmpdir(), tempFileName); }; // TODO: races here? // TODO: this doesn't handle file:/// scheme -export let findProjectRootOfFile = ( +export const findProjectRootOfFile = ( source: p.DocumentUri ): null | p.DocumentUri => { - let dir = path.dirname(source); + const dir = path.dirname(source); if (fs.existsSync(path.join(dir, c.bsconfigPartialPath))) { return dir; } else { @@ -44,11 +44,11 @@ export let findProjectRootOfFile = ( // Also, if someone's ever formatting a regular project setup's dependency // (which is weird but whatever), they'll at least find an upward bs-platform // from the dependent. -export let findBscExeDirOfFile = ( +export const findBscExeDirOfFile = ( source: p.DocumentUri ): null | p.DocumentUri => { - let dir = path.dirname(source); - let bscPath = path.join(dir, c.bscExePartialPath); + const dir = path.dirname(source); + const bscPath = path.join(dir, c.bscExePartialPath); if (fs.existsSync(bscPath)) { return dir; } else { @@ -70,18 +70,18 @@ type execResult = kind: "error"; error: string; }; -export let formatUsingValidBscPath = ( +export const formatUsingValidBscPath = ( code: string, bscPath: p.DocumentUri, isInterface: boolean ): execResult => { - let extension = isInterface ? c.resiExt : c.resExt; - let formatTempFileFullPath = createFileInTempDir(extension); + const extension = isInterface ? c.resiExt : c.resExt; + const formatTempFileFullPath = createFileInTempDir(extension); fs.writeFileSync(formatTempFileFullPath, code, { encoding: "utf-8", }); try { - let result = childProcess.execFileSync( + const result = childProcess.execFileSync( bscPath, ["-color", "never", "-format", formatTempFileFullPath], { stdio: "pipe" } @@ -101,14 +101,18 @@ export let formatUsingValidBscPath = ( } }; -export let runBsbWatcherUsingValidBsbPath = ( +export const runBsbWatcherUsingValidBsbPath = ( bsbPath: p.DocumentUri, projectRootPath: p.DocumentUri ) => { - let process = childProcess.execFile(bsbPath, ["-w"], { - cwd: projectRootPath, - }); - return process; + switch (os.platform()) { + case "win32": return childProcess.exec(`${bsbPath}.cmd -w`, { + cwd: projectRootPath, + }); + default: return childProcess.execFile(bsbPath, ["-w"], { + cwd: projectRootPath, + }) + } // try { // let result = childProcess.execFileSync(bsbPath, [], { stdio: 'pipe', cwd: projectRootPath }) // return { @@ -123,7 +127,7 @@ export let runBsbWatcherUsingValidBsbPath = ( // } }; -export let parseDiagnosticLocation = (location: string): Range => { +export const parseDiagnosticLocation = (location: string): Range => { // example output location: // 3:9 // 3:5-8 @@ -131,12 +135,12 @@ export let parseDiagnosticLocation = (location: string): Range => { // language-server position is 0-based. Ours is 1-based. Don't forget to convert // also, our end character is inclusive. Language-server's is exclusive - let isRange = location.indexOf("-") >= 0; + const isRange = location.indexOf("-") >= 0; if (isRange) { - let [from, to] = location.split("-"); - let [fromLine, fromChar] = from.split(":"); - let isSingleLine = to.indexOf(":") >= 0; - let [toLine, toChar] = isSingleLine ? to.split(":") : [fromLine, to]; + const [from, to] = location.split("-"); + const [fromLine, fromChar] = from.split(":"); + const isSingleLine = to.indexOf(":") >= 0; + const [toLine, toChar] = isSingleLine ? to.split(":") : [fromLine, to]; return { start: { line: parseInt(fromLine) - 1, @@ -145,8 +149,8 @@ export let parseDiagnosticLocation = (location: string): Range => { end: { line: parseInt(toLine) - 1, character: parseInt(toChar) }, }; } else { - let [line, char] = location.split(":"); - let start = { line: parseInt(line) - 1, character: parseInt(char) }; + const [line, char] = location.split(":"); + const start = { line: parseInt(line) - 1, character: parseInt(char) }; return { start: start, end: start, @@ -154,6 +158,23 @@ export let parseDiagnosticLocation = (location: string): Range => { } }; +const separateFileAndLocation = (fileAndLocation: string, locationSeparator: number): [string, string] => { + switch (os.platform()) { + case "win32": { + return [`file:\\\\\\${fileAndLocation.slice(0, locationSeparator)}`, fileAndLocation.slice(locationSeparator + 1)]; + } + default: return [fileAndLocation.slice(2, locationSeparator), fileAndLocation.slice(locationSeparator + 1)] + } +} + +const findLocationSeparator = (fileAndLocation: string) => { + switch (os.platform()) { + // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." + case "win32": return fileAndLocation.indexOf(":", 2); + default: return fileAndLocation.indexOf(":") + } +} + type filesDiagnostics = { [key: string]: p.Diagnostic[]; }; @@ -161,12 +182,12 @@ type parsedCompilerLogResult = { done: boolean; result: filesDiagnostics; }; -export let parseCompilerLogOutput = ( +export const parseCompilerLogOutput = ( content: string ): parsedCompilerLogResult => { /* example .compiler.log file content that we're gonna parse: -#Start(1600519680823) +#Start(1600519680823) Syntax error! /Users/chenglou/github/reason-react/src/test.res:1:8-2:3 @@ -210,12 +231,12 @@ export let parseCompilerLogOutput = ( tag: t.DiagnosticTag | undefined; content: string[]; }; - let parsedDiagnostics: parsedDiagnostic[] = []; - let lines = content.split("\n"); + const parsedDiagnostics: parsedDiagnostic[] = []; + const lines = content.split("\n"); let done = false; for (let i = 0; i < lines.length; i++) { - let line = lines[i]; + const line = lines[i]; if (line.startsWith(" We've found a bug for you!")) { parsedDiagnostics.push({ code: undefined, @@ -224,7 +245,7 @@ export let parseCompilerLogOutput = ( content: [], }); } else if (line.startsWith(" Warning number ")) { - let warningNumber = parseInt(line.slice(" Warning number ".length)); + const warningNumber = parseInt(line.slice(" Warning number ".length)); let tag: t.DiagnosticTag | undefined = undefined; switch (warningNumber) { case 11: @@ -271,16 +292,21 @@ export let parseCompilerLogOutput = ( } } - let result: filesDiagnostics = {}; + const result: filesDiagnostics = {}; parsedDiagnostics.forEach((parsedDiagnostic) => { - let [fileAndLocation, ...diagnosticMessage] = parsedDiagnostic.content; - let locationSeparator = fileAndLocation.indexOf(":"); - let file = fileAndLocation.substring(2, locationSeparator); - let location = fileAndLocation.substring(locationSeparator + 1); + const [fileAndLocation, ...diagnosticMessage] = parsedDiagnostic.content; + + const fileAndLocationTrimmed = fileAndLocation.trim() + + + + const locationSeparator = findLocationSeparator(fileAndLocationTrimmed) + const [file, location] = separateFileAndLocation(fileAndLocationTrimmed, locationSeparator); + if (result[file] == null) { result[file] = []; } - let cleanedUpDiagnostic = + const cleanedUpDiagnostic = diagnosticMessage .map((line) => { // remove the spaces in front From 12fd2b71ee318d4a718ae2b39a088e46247bd782 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:14:00 +0100 Subject: [PATCH 02/21] Remove dependencies not in original repo --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index b2dc2cc24..9ba6a9ce3 100644 --- a/package.json +++ b/package.json @@ -108,14 +108,12 @@ "devDependencies": { "@types/mocha": "^7.0.2", "@types/node": "^12.12.0", - "@typescript-eslint/eslint-plugin": "^4.14.0", "@typescript-eslint/parser": "^2.3.0", "eslint": "^6.4.0", "mocha": "^8.0.1", - "prettier": "^2.2.1", "typescript": "^3.9.4" }, "dependencies": { "chokidar": "^3.4.2" } -} +} \ No newline at end of file From 87512b87abbd21af85735cda35d78bb81c7bf235 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:17:16 +0100 Subject: [PATCH 03/21] Change const to let again --- server/src/utils.ts | 70 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 4970594b2..29e1b1a42 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -1,5 +1,5 @@ import { Range } from "vscode-languageserver-textdocument"; -import * as c from "./constants"; +import * as c from "./letants"; import * as childProcess from "child_process"; import * as p from "vscode-languageserver-protocol"; import * as path from "path"; @@ -7,21 +7,21 @@ import * as t from "vscode-languageserver-types"; import fs from "fs"; import * as os from "os"; -const tempFilePrefix = "rescript_format_file_" + process.pid + "_"; +let tempFilePrefix = "rescript_format_file_" + process.pid + "_"; let tempFileId = 0; -export const createFileInTempDir = (extension = "") => { - const tempFileName = tempFilePrefix + tempFileId + extension; +export let createFileInTempDir = (extension = "") => { + let tempFileName = tempFilePrefix + tempFileId + extension; tempFileId = tempFileId + 1; return path.join(os.tmpdir(), tempFileName); }; // TODO: races here? // TODO: this doesn't handle file:/// scheme -export const findProjectRootOfFile = ( +export let findProjectRootOfFile = ( source: p.DocumentUri ): null | p.DocumentUri => { - const dir = path.dirname(source); + let dir = path.dirname(source); if (fs.existsSync(path.join(dir, c.bsconfigPartialPath))) { return dir; } else { @@ -44,11 +44,11 @@ export const findProjectRootOfFile = ( // Also, if someone's ever formatting a regular project setup's dependency // (which is weird but whatever), they'll at least find an upward bs-platform // from the dependent. -export const findBscExeDirOfFile = ( +export let findBscExeDirOfFile = ( source: p.DocumentUri ): null | p.DocumentUri => { - const dir = path.dirname(source); - const bscPath = path.join(dir, c.bscExePartialPath); + let dir = path.dirname(source); + let bscPath = path.join(dir, c.bscExePartialPath); if (fs.existsSync(bscPath)) { return dir; } else { @@ -70,18 +70,18 @@ type execResult = kind: "error"; error: string; }; -export const formatUsingValidBscPath = ( +export let formatUsingValidBscPath = ( code: string, bscPath: p.DocumentUri, isInterface: boolean ): execResult => { - const extension = isInterface ? c.resiExt : c.resExt; - const formatTempFileFullPath = createFileInTempDir(extension); + let extension = isInterface ? c.resiExt : c.resExt; + let formatTempFileFullPath = createFileInTempDir(extension); fs.writeFileSync(formatTempFileFullPath, code, { encoding: "utf-8", }); try { - const result = childProcess.execFileSync( + let result = childProcess.execFileSync( bscPath, ["-color", "never", "-format", formatTempFileFullPath], { stdio: "pipe" } @@ -101,7 +101,7 @@ export const formatUsingValidBscPath = ( } }; -export const runBsbWatcherUsingValidBsbPath = ( +export let runBsbWatcherUsingValidBsbPath = ( bsbPath: p.DocumentUri, projectRootPath: p.DocumentUri ) => { @@ -127,7 +127,7 @@ export const runBsbWatcherUsingValidBsbPath = ( // } }; -export const parseDiagnosticLocation = (location: string): Range => { +export let parseDiagnosticLocation = (location: string): Range => { // example output location: // 3:9 // 3:5-8 @@ -135,12 +135,12 @@ export const parseDiagnosticLocation = (location: string): Range => { // language-server position is 0-based. Ours is 1-based. Don't forget to convert // also, our end character is inclusive. Language-server's is exclusive - const isRange = location.indexOf("-") >= 0; + let isRange = location.indexOf("-") >= 0; if (isRange) { - const [from, to] = location.split("-"); - const [fromLine, fromChar] = from.split(":"); - const isSingleLine = to.indexOf(":") >= 0; - const [toLine, toChar] = isSingleLine ? to.split(":") : [fromLine, to]; + let [from, to] = location.split("-"); + let [fromLine, fromChar] = from.split(":"); + let isSingleLine = to.indexOf(":") >= 0; + let [toLine, toChar] = isSingleLine ? to.split(":") : [fromLine, to]; return { start: { line: parseInt(fromLine) - 1, @@ -149,8 +149,8 @@ export const parseDiagnosticLocation = (location: string): Range => { end: { line: parseInt(toLine) - 1, character: parseInt(toChar) }, }; } else { - const [line, char] = location.split(":"); - const start = { line: parseInt(line) - 1, character: parseInt(char) }; + let [line, char] = location.split(":"); + let start = { line: parseInt(line) - 1, character: parseInt(char) }; return { start: start, end: start, @@ -158,7 +158,7 @@ export const parseDiagnosticLocation = (location: string): Range => { } }; -const separateFileAndLocation = (fileAndLocation: string, locationSeparator: number): [string, string] => { +let separateFileAndLocation = (fileAndLocation: string, locationSeparator: number): [string, string] => { switch (os.platform()) { case "win32": { return [`file:\\\\\\${fileAndLocation.slice(0, locationSeparator)}`, fileAndLocation.slice(locationSeparator + 1)]; @@ -167,7 +167,7 @@ const separateFileAndLocation = (fileAndLocation: string, locationSeparator: num } } -const findLocationSeparator = (fileAndLocation: string) => { +let findLocationSeparator = (fileAndLocation: string) => { switch (os.platform()) { // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." case "win32": return fileAndLocation.indexOf(":", 2); @@ -182,7 +182,7 @@ type parsedCompilerLogResult = { done: boolean; result: filesDiagnostics; }; -export const parseCompilerLogOutput = ( +export let parseCompilerLogOutput = ( content: string ): parsedCompilerLogResult => { /* example .compiler.log file content that we're gonna parse: @@ -231,12 +231,12 @@ export const parseCompilerLogOutput = ( tag: t.DiagnosticTag | undefined; content: string[]; }; - const parsedDiagnostics: parsedDiagnostic[] = []; - const lines = content.split("\n"); + let parsedDiagnostics: parsedDiagnostic[] = []; + let lines = content.split("\n"); let done = false; for (let i = 0; i < lines.length; i++) { - const line = lines[i]; + let line = lines[i]; if (line.startsWith(" We've found a bug for you!")) { parsedDiagnostics.push({ code: undefined, @@ -245,7 +245,7 @@ export const parseCompilerLogOutput = ( content: [], }); } else if (line.startsWith(" Warning number ")) { - const warningNumber = parseInt(line.slice(" Warning number ".length)); + let warningNumber = parseInt(line.slice(" Warning number ".length)); let tag: t.DiagnosticTag | undefined = undefined; switch (warningNumber) { case 11: @@ -292,21 +292,21 @@ export const parseCompilerLogOutput = ( } } - const result: filesDiagnostics = {}; + let result: filesDiagnostics = {}; parsedDiagnostics.forEach((parsedDiagnostic) => { - const [fileAndLocation, ...diagnosticMessage] = parsedDiagnostic.content; + let [fileAndLocation, ...diagnosticMessage] = parsedDiagnostic.content; - const fileAndLocationTrimmed = fileAndLocation.trim() + let fileAndLocationTrimmed = fileAndLocation.trim() - const locationSeparator = findLocationSeparator(fileAndLocationTrimmed) - const [file, location] = separateFileAndLocation(fileAndLocationTrimmed, locationSeparator); + let locationSeparator = findLocationSeparator(fileAndLocationTrimmed) + let [file, location] = separateFileAndLocation(fileAndLocationTrimmed, locationSeparator); if (result[file] == null) { result[file] = []; } - const cleanedUpDiagnostic = + let cleanedUpDiagnostic = diagnosticMessage .map((line) => { // remove the spaces in front From 54bf3696af7fed89b3d7b80e84b62b16a156dc77 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:17:53 +0100 Subject: [PATCH 04/21] Remove amusing letants --- server/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 29e1b1a42..afb43f6cc 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -1,5 +1,5 @@ import { Range } from "vscode-languageserver-textdocument"; -import * as c from "./letants"; +import * as c from "./constants"; import * as childProcess from "child_process"; import * as p from "vscode-languageserver-protocol"; import * as path from "path"; From fa5934f556f0aba5d846b71a776443b1e2f30de6 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:18:35 +0100 Subject: [PATCH 05/21] Remove space --- server/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index afb43f6cc..691b9d627 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -187,7 +187,7 @@ export let parseCompilerLogOutput = ( ): parsedCompilerLogResult => { /* example .compiler.log file content that we're gonna parse: -#Start(1600519680823) +#Start(1600519680823) Syntax error! /Users/chenglou/github/reason-react/src/test.res:1:8-2:3 From 37848cbea1b5a64968dd79f4c52274c0e833edb8 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:28:42 +0100 Subject: [PATCH 06/21] Remove the two first spaces since it is trimmed --- server/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 691b9d627..570de00a1 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -163,7 +163,7 @@ let separateFileAndLocation = (fileAndLocation: string, locationSeparator: numbe case "win32": { return [`file:\\\\\\${fileAndLocation.slice(0, locationSeparator)}`, fileAndLocation.slice(locationSeparator + 1)]; } - default: return [fileAndLocation.slice(2, locationSeparator), fileAndLocation.slice(locationSeparator + 1)] + default: return [fileAndLocation.slice(locationSeparator), fileAndLocation.slice(locationSeparator + 1)] } } From 744d5ffd33f7381375eb4f791e8aac5c5bd00508 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:30:09 +0100 Subject: [PATCH 07/21] Refactor separatefileandlocation function --- server/src/utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 570de00a1..933d2d5ed 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -159,11 +159,13 @@ export let parseDiagnosticLocation = (location: string): Range => { }; let separateFileAndLocation = (fileAndLocation: string, locationSeparator: number): [string, string] => { + let file = fileAndLocation.slice(0, locationSeparator) + let location = fileAndLocation.slice(locationSeparator + 1) switch (os.platform()) { case "win32": { - return [`file:\\\\\\${fileAndLocation.slice(0, locationSeparator)}`, fileAndLocation.slice(locationSeparator + 1)]; + return [`file:\\\\\\${file}`, location]; } - default: return [fileAndLocation.slice(locationSeparator), fileAndLocation.slice(locationSeparator + 1)] + default: return [file, location] } } From ed6d903cc92f1f6c332f9f46e86e0fcc3df26a5b Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:40:25 +0100 Subject: [PATCH 08/21] Fix spacing --- server/src/utils.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 933d2d5ed..bfe0145d2 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -296,14 +296,10 @@ export let parseCompilerLogOutput = ( let result: filesDiagnostics = {}; parsedDiagnostics.forEach((parsedDiagnostic) => { - let [fileAndLocation, ...diagnosticMessage] = parsedDiagnostic.content; - - let fileAndLocationTrimmed = fileAndLocation.trim() - - - - let locationSeparator = findLocationSeparator(fileAndLocationTrimmed) - let [file, location] = separateFileAndLocation(fileAndLocationTrimmed, locationSeparator); + let [fileAndLocationRow, ...diagnosticMessage] = parsedDiagnostic.content; + let fileAndLocation = fileAndLocationRow.trim() + let locationSeparator = findLocationSeparator(fileAndLocation) + let [file, location] = separateFileAndLocation(fileAndLocation, locationSeparator); if (result[file] == null) { result[file] = []; From f4842630db937012f6d4e27ffb01508701a0c6da Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:41:17 +0100 Subject: [PATCH 09/21] Add one space --- server/src/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/utils.ts b/server/src/utils.ts index bfe0145d2..fb63259a7 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -297,6 +297,7 @@ export let parseCompilerLogOutput = ( let result: filesDiagnostics = {}; parsedDiagnostics.forEach((parsedDiagnostic) => { let [fileAndLocationRow, ...diagnosticMessage] = parsedDiagnostic.content; + let fileAndLocation = fileAndLocationRow.trim() let locationSeparator = findLocationSeparator(fileAndLocation) let [file, location] = separateFileAndLocation(fileAndLocation, locationSeparator); From 8b64c8015b3064e0146d655fc1b0364254939ce1 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 20:45:21 +0100 Subject: [PATCH 10/21] Move findlocationseparator into other function --- server/src/utils.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index fb63259a7..1ae31de34 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -158,7 +158,16 @@ export let parseDiagnosticLocation = (location: string): Range => { } }; -let separateFileAndLocation = (fileAndLocation: string, locationSeparator: number): [string, string] => { +let findLocationSeparator = (fileAndLocation: string) => { + switch (os.platform()) { + // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." + case "win32": return fileAndLocation.indexOf(":", 2); + default: return fileAndLocation.indexOf(":") + } +} + +let separateFileAndLocation = (fileAndLocation: string): [string, string] => { + let locationSeparator = findLocationSeparator(fileAndLocation) let file = fileAndLocation.slice(0, locationSeparator) let location = fileAndLocation.slice(locationSeparator + 1) switch (os.platform()) { @@ -169,13 +178,7 @@ let separateFileAndLocation = (fileAndLocation: string, locationSeparator: numbe } } -let findLocationSeparator = (fileAndLocation: string) => { - switch (os.platform()) { - // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." - case "win32": return fileAndLocation.indexOf(":", 2); - default: return fileAndLocation.indexOf(":") - } -} + type filesDiagnostics = { [key: string]: p.Diagnostic[]; @@ -299,8 +302,7 @@ export let parseCompilerLogOutput = ( let [fileAndLocationRow, ...diagnosticMessage] = parsedDiagnostic.content; let fileAndLocation = fileAndLocationRow.trim() - let locationSeparator = findLocationSeparator(fileAndLocation) - let [file, location] = separateFileAndLocation(fileAndLocation, locationSeparator); + let [file, location] = separateFileAndLocation(fileAndLocation); if (result[file] == null) { result[file] = []; From 856de60e8e5b5ecdbbfb997ddbd927505a150afb Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Mon, 25 Jan 2021 23:31:27 +0100 Subject: [PATCH 11/21] Reformatted some code --- server/src/utils.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 1ae31de34..47d16f002 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -171,9 +171,7 @@ let separateFileAndLocation = (fileAndLocation: string): [string, string] => { let file = fileAndLocation.slice(0, locationSeparator) let location = fileAndLocation.slice(locationSeparator + 1) switch (os.platform()) { - case "win32": { - return [`file:\\\\\\${file}`, location]; - } + case "win32": return [`file:\\\\\\${file}`, location]; default: return [file, location] } } @@ -299,9 +297,9 @@ export let parseCompilerLogOutput = ( let result: filesDiagnostics = {}; parsedDiagnostics.forEach((parsedDiagnostic) => { - let [fileAndLocationRow, ...diagnosticMessage] = parsedDiagnostic.content; + let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content; - let fileAndLocation = fileAndLocationRow.trim() + let fileAndLocation = fileAndLocationLine.trim() let [file, location] = separateFileAndLocation(fileAndLocation); if (result[file] == null) { From e724c5ea2404dde9935f7b1c9a9f65c52a6f32a2 Mon Sep 17 00:00:00 2001 From: John Pangalos Date: Tue, 26 Jan 2021 08:42:54 +0100 Subject: [PATCH 12/21] Revert package.json Reverting package.json as it is a unnecessary change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ba6a9ce3..31150ee09 100644 --- a/package.json +++ b/package.json @@ -116,4 +116,4 @@ "dependencies": { "chokidar": "^3.4.2" } -} \ No newline at end of file +} From c077b63ff67048842043408a0733102ef5e04539 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Tue, 26 Jan 2021 16:54:55 +0100 Subject: [PATCH 13/21] Update from comments --- server/src/utils.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 47d16f002..cc92d495a 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -105,11 +105,12 @@ export let runBsbWatcherUsingValidBsbPath = ( bsbPath: p.DocumentUri, projectRootPath: p.DocumentUri ) => { - switch (os.platform()) { - case "win32": return childProcess.exec(`${bsbPath}.cmd -w`, { + if (process.platform === "win32") { + return childProcess.exec(`${bsbPath}.cmd -w`, { cwd: projectRootPath, }); - default: return childProcess.execFile(bsbPath, ["-w"], { + } else { + return childProcess.execFile(bsbPath, ["-w"], { cwd: projectRootPath, }) } @@ -159,10 +160,11 @@ export let parseDiagnosticLocation = (location: string): Range => { }; let findLocationSeparator = (fileAndLocation: string) => { - switch (os.platform()) { - // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." - case "win32": return fileAndLocation.indexOf(":", 2); - default: return fileAndLocation.indexOf(":") + // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." + if (process.platform === "win32") { + return fileAndLocation.indexOf(":", 2); + } else { + return fileAndLocation.indexOf(":") } } @@ -170,9 +172,10 @@ let separateFileAndLocation = (fileAndLocation: string): [string, string] => { let locationSeparator = findLocationSeparator(fileAndLocation) let file = fileAndLocation.slice(0, locationSeparator) let location = fileAndLocation.slice(locationSeparator + 1) - switch (os.platform()) { - case "win32": return [`file:\\\\\\${file}`, location]; - default: return [file, location] + if (process.platform === "win32") { + return [`file:\\\\\\${file}`, location]; + } else { + return [file, location] } } From c74302a11c89f40e4e032aa035220e7a21b5181e Mon Sep 17 00:00:00 2001 From: John Pangalos Date: Tue, 26 Jan 2021 19:42:25 +0100 Subject: [PATCH 14/21] Revert clien package-lock.json --- client/package-lock.json | 258 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 257 insertions(+), 1 deletion(-) diff --git a/client/package-lock.json b/client/package-lock.json index 28ef10034..8ea3f702a 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1,8 +1,264 @@ { "name": "rescript-language-client", "version": "0.0.1", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "rescript-language-client", + "version": "0.0.1", + "license": "MIT", + "dependencies": { + "vscode-languageclient": "^6.1.3" + }, + "devDependencies": { + "@types/vscode": "1.43.0", + "vscode-test": "^1.3.0" + }, + "engines": { + "vscode": "^1.43.0" + } + }, + "node_modules/@types/vscode": { + "version": "1.43.0", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.43.0.tgz", + "integrity": "sha512-kIaR9qzd80rJOxePKpCB/mdy00mz8Apt2QA5Y6rdrKFn13QNFNeP3Hzmsf37Bwh/3cS7QjtAeGSK7wSqAU0sYQ==", + "dev": true + }, + "node_modules/agent-base": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", + "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "dev": true, + "dependencies": { + "es6-promisify": "^5.0.0" + }, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "node_modules/debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "dev": true + }, + "node_modules/es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "dev": true, + "dependencies": { + "es6-promise": "^4.0.3" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "node_modules/glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + } + }, + "node_modules/http-proxy-agent": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-2.1.0.tgz", + "integrity": "sha512-qwHbBLV7WviBl0rQsOzH6o5lwyOIvwp/BdFnvVxXORldu5TmjFfjzBcWUWS5kWAZhmv+JtiDhSuQCp4sBfbIgg==", + "dev": true, + "dependencies": { + "agent-base": "4", + "debug": "3.1.0" + }, + "engines": { + "node": ">= 4.5.0" + } + }, + "node_modules/https-proxy-agent": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", + "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "dev": true, + "dependencies": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + }, + "engines": { + "node": ">= 4.5.0" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "node_modules/minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + } + }, + "node_modules/vscode-jsonrpc": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz", + "integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==", + "engines": { + "node": ">=8.0.0 || >=10.0.0" + } + }, + "node_modules/vscode-languageclient": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-6.1.3.tgz", + "integrity": "sha512-YciJxk08iU5LmWu7j5dUt9/1OLjokKET6rME3cI4BRpiF6HZlusm2ZwPt0MYJ0lV5y43sZsQHhyon2xBg4ZJVA==", + "dependencies": { + "semver": "^6.3.0", + "vscode-languageserver-protocol": "^3.15.3" + }, + "engines": { + "vscode": "^1.41.0" + } + }, + "node_modules/vscode-languageclient/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/vscode-languageserver-protocol": { + "version": "3.15.3", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz", + "integrity": "sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==", + "dependencies": { + "vscode-jsonrpc": "^5.0.1", + "vscode-languageserver-types": "3.15.1" + } + }, + "node_modules/vscode-languageserver-types": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz", + "integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==" + }, + "node_modules/vscode-test": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/vscode-test/-/vscode-test-1.3.0.tgz", + "integrity": "sha512-LddukcBiSU2FVTDr3c1D8lwkiOvwlJdDL2hqVbn6gIz+rpTqUCkMZSKYm94Y1v0WXlHSDQBsXyY+tchWQgGVsw==", + "dev": true, + "dependencies": { + "http-proxy-agent": "^2.1.0", + "https-proxy-agent": "^2.2.4", + "rimraf": "^2.6.3" + }, + "engines": { + "node": ">=8.9.3" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + }, "dependencies": { "@types/vscode": { "version": "1.43.0", From 33b3e3053867ca8aac25d9009b90baf937309487 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Wed, 27 Jan 2021 12:44:16 +0100 Subject: [PATCH 15/21] Use vscode uri utils for file scheme --- server/package-lock.json | 59 ++++------------------------------------ server/package.json | 3 +- server/src/utils.ts | 8 ++---- 3 files changed, 11 insertions(+), 59 deletions(-) diff --git a/server/package-lock.json b/server/package-lock.json index 047a00195..089ce5b0d 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,60 +1,8 @@ { "name": "rescript-language-server", "version": "1.0.0", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "rescript-language-server", - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "vscode-languageserver": "^6.1.1", - "vscode-languageserver-textdocument": "^1.0.1" - }, - "engines": { - "node": "*" - } - }, - "node_modules/vscode-jsonrpc": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz", - "integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==", - "engines": { - "node": ">=8.0.0 || >=10.0.0" - } - }, - "node_modules/vscode-languageserver": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz", - "integrity": "sha512-DueEpkUAkD5XTR4MLYNr6bQIp/UFR0/IPApgXU3YfCBCB08u2sm9hRCs6DxYZELkk++STPjpcjksR2H8qI3cDQ==", - "dependencies": { - "vscode-languageserver-protocol": "^3.15.3" - }, - "bin": { - "installServerIntoExtension": "bin/installServerIntoExtension" - } - }, - "node_modules/vscode-languageserver-protocol": { - "version": "3.15.3", - "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz", - "integrity": "sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==", - "dependencies": { - "vscode-jsonrpc": "^5.0.1", - "vscode-languageserver-types": "3.15.1" - } - }, - "node_modules/vscode-languageserver-textdocument": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz", - "integrity": "sha512-UIcJDjX7IFkck7cSkNNyzIz5FyvpQfY7sdzVy+wkKN/BLaD4DQ0ppXQrKePomCxTS7RrolK1I0pey0bG9eh8dA==" - }, - "node_modules/vscode-languageserver-types": { - "version": "3.15.1", - "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz", - "integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==" - } - }, "dependencies": { "vscode-jsonrpc": { "version": "5.0.1", @@ -87,6 +35,11 @@ "version": "3.15.1", "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz", "integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==" + }, + "vscode-uri": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.2.tgz", + "integrity": "sha512-jkjy6pjU1fxUvI51P+gCsxg1u2n8LSt0W6KrCNQceaziKzff74GoWmjVG46KieVzybO1sttPQmYfrwSHey7GUA==" } } } diff --git a/server/package.json b/server/package.json index 4ae5dedef..5e5414c90 100644 --- a/server/package.json +++ b/server/package.json @@ -13,7 +13,8 @@ }, "dependencies": { "vscode-languageserver": "^6.1.1", - "vscode-languageserver-textdocument": "^1.0.1" + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-uri": "^3.0.2" }, "scripts": {} } diff --git a/server/src/utils.ts b/server/src/utils.ts index cc92d495a..69cd6b89d 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -6,6 +6,7 @@ import * as path from "path"; import * as t from "vscode-languageserver-types"; import fs from "fs"; import * as os from "os"; +import { URI } from 'vscode-uri'; let tempFilePrefix = "rescript_format_file_" + process.pid + "_"; let tempFileId = 0; @@ -172,11 +173,8 @@ let separateFileAndLocation = (fileAndLocation: string): [string, string] => { let locationSeparator = findLocationSeparator(fileAndLocation) let file = fileAndLocation.slice(0, locationSeparator) let location = fileAndLocation.slice(locationSeparator + 1) - if (process.platform === "win32") { - return [`file:\\\\\\${file}`, location]; - } else { - return [file, location] - } + + return [URI.file(file).toString(), location] } From 3fee88414353da497b94c2af60a2790337898cff Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Wed, 27 Jan 2021 12:45:22 +0100 Subject: [PATCH 16/21] Add semicolons --- server/src/utils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 69cd6b89d..b4f20ff7a 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -165,16 +165,16 @@ let findLocationSeparator = (fileAndLocation: string) => { if (process.platform === "win32") { return fileAndLocation.indexOf(":", 2); } else { - return fileAndLocation.indexOf(":") + return fileAndLocation.indexOf(":"); } } let separateFileAndLocation = (fileAndLocation: string): [string, string] => { - let locationSeparator = findLocationSeparator(fileAndLocation) - let file = fileAndLocation.slice(0, locationSeparator) - let location = fileAndLocation.slice(locationSeparator + 1) + let locationSeparator = findLocationSeparator(fileAndLocation); + let file = fileAndLocation.slice(0, locationSeparator); + let location = fileAndLocation.slice(locationSeparator + 1); - return [URI.file(file).toString(), location] + return [URI.file(file).toString(), location]; } @@ -300,7 +300,7 @@ export let parseCompilerLogOutput = ( parsedDiagnostics.forEach((parsedDiagnostic) => { let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content; - let fileAndLocation = fileAndLocationLine.trim() + let fileAndLocation = fileAndLocationLine.trim(); let [file, location] = separateFileAndLocation(fileAndLocation); if (result[file] == null) { From 7ecb7ad6e8f2334fb29f42167e68827110731259 Mon Sep 17 00:00:00 2001 From: mewhhaha Date: Wed, 27 Jan 2021 12:45:56 +0100 Subject: [PATCH 17/21] Add two semicolons --- server/src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index b4f20ff7a..aee4b16f5 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -167,7 +167,7 @@ let findLocationSeparator = (fileAndLocation: string) => { } else { return fileAndLocation.indexOf(":"); } -} +}; let separateFileAndLocation = (fileAndLocation: string): [string, string] => { let locationSeparator = findLocationSeparator(fileAndLocation); @@ -175,7 +175,7 @@ let separateFileAndLocation = (fileAndLocation: string): [string, string] => { let location = fileAndLocation.slice(locationSeparator + 1); return [URI.file(file).toString(), location]; -} +}; From afece3f0d35fdfe95a7013ae1922af15ae96889f Mon Sep 17 00:00:00 2001 From: John Pangalos Date: Wed, 27 Jan 2021 12:57:55 +0100 Subject: [PATCH 18/21] Remove trim call as to follow repos best practices --- server/src/utils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index cc92d495a..2176710ac 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -170,7 +170,7 @@ let findLocationSeparator = (fileAndLocation: string) => { let separateFileAndLocation = (fileAndLocation: string): [string, string] => { let locationSeparator = findLocationSeparator(fileAndLocation) - let file = fileAndLocation.slice(0, locationSeparator) + let file = fileAndLocation.slice(2, locationSeparator) let location = fileAndLocation.slice(locationSeparator + 1) if (process.platform === "win32") { return [`file:\\\\\\${file}`, location]; @@ -302,8 +302,7 @@ export let parseCompilerLogOutput = ( parsedDiagnostics.forEach((parsedDiagnostic) => { let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content; - let fileAndLocation = fileAndLocationLine.trim() - let [file, location] = separateFileAndLocation(fileAndLocation); + let [file, location] = separateFileAndLocation(fileAndLocationLine); if (result[file] == null) { result[file] = []; From 0a873e1b7189cb25e706b0811e2565f5a9873da2 Mon Sep 17 00:00:00 2001 From: John Pangalos Date: Wed, 27 Jan 2021 13:09:09 +0100 Subject: [PATCH 19/21] Move to lockfile package 2 This is a reversion --- package-lock.json | 4 +-- server/package-lock.json | 60 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 420b33d52..e3e6c4bbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "rescript-vscode", - "version": "1.0.2", + "version": "1.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.0.2", + "version": "1.0.4", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/server/package-lock.json b/server/package-lock.json index 089ce5b0d..1d7a2654b 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,8 +1,66 @@ { "name": "rescript-language-server", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "rescript-language-server", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "vscode-languageserver": "^6.1.1", + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-uri": "^3.0.2" + }, + "engines": { + "node": "*" + } + }, + "node_modules/vscode-jsonrpc": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz", + "integrity": "sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A==", + "engines": { + "node": ">=8.0.0 || >=10.0.0" + } + }, + "node_modules/vscode-languageserver": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-6.1.1.tgz", + "integrity": "sha512-DueEpkUAkD5XTR4MLYNr6bQIp/UFR0/IPApgXU3YfCBCB08u2sm9hRCs6DxYZELkk++STPjpcjksR2H8qI3cDQ==", + "dependencies": { + "vscode-languageserver-protocol": "^3.15.3" + }, + "bin": { + "installServerIntoExtension": "bin/installServerIntoExtension" + } + }, + "node_modules/vscode-languageserver-protocol": { + "version": "3.15.3", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz", + "integrity": "sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw==", + "dependencies": { + "vscode-jsonrpc": "^5.0.1", + "vscode-languageserver-types": "3.15.1" + } + }, + "node_modules/vscode-languageserver-textdocument": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.1.tgz", + "integrity": "sha512-UIcJDjX7IFkck7cSkNNyzIz5FyvpQfY7sdzVy+wkKN/BLaD4DQ0ppXQrKePomCxTS7RrolK1I0pey0bG9eh8dA==" + }, + "node_modules/vscode-languageserver-types": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz", + "integrity": "sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ==" + }, + "node_modules/vscode-uri": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.2.tgz", + "integrity": "sha512-jkjy6pjU1fxUvI51P+gCsxg1u2n8LSt0W6KrCNQceaziKzff74GoWmjVG46KieVzybO1sttPQmYfrwSHey7GUA==" + } + }, "dependencies": { "vscode-jsonrpc": { "version": "5.0.1", From c73947cbe042563f43d56747139e80541e41774c Mon Sep 17 00:00:00 2001 From: John Pangalos Date: Wed, 27 Jan 2021 13:14:02 +0100 Subject: [PATCH 20/21] Include spaces in colon separator search --- server/src/utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index b2775a0d6..55f5e6430 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -162,8 +162,9 @@ export let parseDiagnosticLocation = (location: string): Range => { let findLocationSeparator = (fileAndLocation: string) => { // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." + // and the two spaces at the start of the line if (process.platform === "win32") { - return fileAndLocation.indexOf(":", 2); + return fileAndLocation.indexOf(":", 4); } else { return fileAndLocation.indexOf(":"); } From 76a9da9a6407706c09b6f2be9702af1c12f53423 Mon Sep 17 00:00:00 2001 From: John Pangalos Date: Wed, 27 Jan 2021 13:55:49 +0100 Subject: [PATCH 21/21] We need to remove the spaces for URI.file to work --- server/src/utils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/utils.ts b/server/src/utils.ts index 55f5e6430..230be693a 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -162,9 +162,8 @@ export let parseDiagnosticLocation = (location: string): Range => { let findLocationSeparator = (fileAndLocation: string) => { // Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.." - // and the two spaces at the start of the line if (process.platform === "win32") { - return fileAndLocation.indexOf(":", 4); + return fileAndLocation.indexOf(":", 2); } else { return fileAndLocation.indexOf(":"); } @@ -301,7 +300,7 @@ export let parseCompilerLogOutput = ( parsedDiagnostics.forEach((parsedDiagnostic) => { let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content; - let [file, location] = separateFileAndLocation(fileAndLocationLine); + let [file, location] = separateFileAndLocation(fileAndLocationLine.slice(2)); if (result[file] == null) { result[file] = [];