Skip to content

Commit 2388fa2

Browse files
John Pangalosmewhhaha
John Pangalos
andauthored
Windows fixes (#71)
* Add windows fixes for files * Remove dependencies not in original repo * Change const to let again * Remove amusing letants * Remove space * Remove the two first spaces since it is trimmed * Refactor separatefileandlocation function * Fix spacing * Add one space * Move findlocationseparator into other function * Reformatted some code * Revert package.json Reverting package.json as it is a unnecessary change * Update from comments * Revert clien package-lock.json * Use vscode uri utils for file scheme * Add semicolons * Add two semicolons * Remove trim call as to follow repos best practices * Move to lockfile package 2 This is a reversion * Include spaces in colon separator search * We need to remove the spaces for URI.file to work Co-authored-by: mewhhaha <kopatheonlyone@hotmail.com>
1 parent 2084121 commit 2388fa2

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package-lock.json

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"dependencies": {
1515
"vscode-languageserver": "^6.1.1",
16-
"vscode-languageserver-textdocument": "^1.0.1"
16+
"vscode-languageserver-textdocument": "^1.0.1",
17+
"vscode-uri": "^3.0.2"
1718
},
1819
"scripts": {}
1920
}

server/src/utils.ts

+33-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as path from "path";
66
import * as t from "vscode-languageserver-types";
77
import fs from "fs";
88
import * as os from "os";
9+
import { URI } from 'vscode-uri';
910

1011
let tempFilePrefix = "rescript_format_file_" + process.pid + "_";
1112
let tempFileId = 0;
@@ -105,10 +106,15 @@ export let runBsbWatcherUsingValidBsbPath = (
105106
bsbPath: p.DocumentUri,
106107
projectRootPath: p.DocumentUri
107108
) => {
108-
let process = childProcess.execFile(bsbPath, ["-w"], {
109-
cwd: projectRootPath,
110-
});
111-
return process;
109+
if (process.platform === "win32") {
110+
return childProcess.exec(`${bsbPath}.cmd -w`, {
111+
cwd: projectRootPath,
112+
});
113+
} else {
114+
return childProcess.execFile(bsbPath, ["-w"], {
115+
cwd: projectRootPath,
116+
})
117+
}
112118
// try {
113119
// let result = childProcess.execFileSync(bsbPath, [], { stdio: 'pipe', cwd: projectRootPath })
114120
// return {
@@ -154,6 +160,25 @@ export let parseDiagnosticLocation = (location: string): Range => {
154160
}
155161
};
156162

163+
let findLocationSeparator = (fileAndLocation: string) => {
164+
// Exclude the two first letters in windows paths to avoid the first colon in eg "c:\\.."
165+
if (process.platform === "win32") {
166+
return fileAndLocation.indexOf(":", 2);
167+
} else {
168+
return fileAndLocation.indexOf(":");
169+
}
170+
};
171+
172+
let separateFileAndLocation = (fileAndLocation: string): [string, string] => {
173+
let locationSeparator = findLocationSeparator(fileAndLocation);
174+
let file = fileAndLocation.slice(0, locationSeparator);
175+
let location = fileAndLocation.slice(locationSeparator + 1);
176+
177+
return [URI.file(file).toString(), location];
178+
};
179+
180+
181+
157182
type filesDiagnostics = {
158183
[key: string]: p.Diagnostic[];
159184
};
@@ -273,10 +298,10 @@ export let parseCompilerLogOutput = (
273298

274299
let result: filesDiagnostics = {};
275300
parsedDiagnostics.forEach((parsedDiagnostic) => {
276-
let [fileAndLocation, ...diagnosticMessage] = parsedDiagnostic.content;
277-
let locationSeparator = fileAndLocation.indexOf(":");
278-
let file = fileAndLocation.substring(2, locationSeparator);
279-
let location = fileAndLocation.substring(locationSeparator + 1);
301+
let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content;
302+
303+
let [file, location] = separateFileAndLocation(fileAndLocationLine.slice(2));
304+
280305
if (result[file] == null) {
281306
result[file] = [];
282307
}

0 commit comments

Comments
 (0)