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 047a00195..1d7a2654b 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "dependencies": { "vscode-languageserver": "^6.1.1", - "vscode-languageserver-textdocument": "^1.0.1" + "vscode-languageserver-textdocument": "^1.0.1", + "vscode-uri": "^3.0.2" }, "engines": { "node": "*" @@ -53,6 +54,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==" + }, + "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": { @@ -87,6 +93,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 c877b2233..230be693a 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; @@ -105,10 +106,15 @@ export let runBsbWatcherUsingValidBsbPath = ( bsbPath: p.DocumentUri, projectRootPath: p.DocumentUri ) => { - let process = childProcess.execFile(bsbPath, ["-w"], { - cwd: projectRootPath, - }); - return process; + if (process.platform === "win32") { + return childProcess.exec(`${bsbPath}.cmd -w`, { + cwd: projectRootPath, + }); + } else { + return childProcess.execFile(bsbPath, ["-w"], { + cwd: projectRootPath, + }) + } // try { // let result = childProcess.execFileSync(bsbPath, [], { stdio: 'pipe', cwd: projectRootPath }) // return { @@ -154,6 +160,25 @@ 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:\\.." + if (process.platform === "win32") { + return fileAndLocation.indexOf(":", 2); + } else { + 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); + + return [URI.file(file).toString(), location]; +}; + + + type filesDiagnostics = { [key: string]: p.Diagnostic[]; }; @@ -273,10 +298,10 @@ export let parseCompilerLogOutput = ( let 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); + let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content; + + let [file, location] = separateFileAndLocation(fileAndLocationLine.slice(2)); + if (result[file] == null) { result[file] = []; }