Skip to content

Commit

Permalink
feat: Switch to vscode-url library to better support Windows paths (#62)
Browse files Browse the repository at this point in the history
* Use vscode-uri to simplify file uri parsing

* windows specific handling of filename is no longer required

* Package lock file updates

* Still need to make sure driver letters are upper case on Windows

* UNC paths don't require drive letter processing

* Remove standard javascript extension specific config
  • Loading branch information
Luis Arias committed May 10, 2021
1 parent ecbb40d commit 66cfa08
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
3 changes: 1 addition & 2 deletions editor-extensions/vscode/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion editor-extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions editor-extensions/vscode/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion editor-extensions/vscode/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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": {}
}
27 changes: 11 additions & 16 deletions editor-extensions/vscode/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "vscode-languageserver";

import { TextDocument } from "vscode-languageserver-textdocument";
import { URI } from 'vscode-uri';

import * as childProcess from "child_process";

Expand All @@ -34,22 +35,15 @@ const isWindows = /^win32/.test(process.platform);
const needsCMD =
isWindows && process.env.ComSpec && /cmd.exe$/.test(process.env.ComSpec);

const fileProtocol = "file://";
const fileScheme = "file";

function filenameFromUri(textDocumentUri: string) {
let filename = textDocumentUri.substring(fileProtocol.length);
function filenameFromUri(uri: URI) {
let filename = uri.fsPath;

// Fix for VSCode creating invalid URIs on Windows
// Ref https://github.com/microsoft/vscode-languageserver-node/issues/105
if (isWindows) {
filename = filename.replace("%3A", ":");

// `grainc` doesn't understand a Windows path starting with `/C:/` as absolute, only `C:/`
if (filename.startsWith("/")) {
filename = filename.substring(1);
}

// Packaged Grain doesn't understand lowercase drive letters
// Packaged Grain doesn't understand lowercase drive letters.
// If authority is not empty, then we can skip since this is
// a UNC path.
if (isWindows && uri.authority === '') {
filename = filename[0].toUpperCase() + filename.substring(1);
}

Expand Down Expand Up @@ -281,8 +275,9 @@ async function validateWithCompiler(textDocumentUri: string): Promise<void> {
connection.console.log("Validating " + textDocumentUri);
}

if (textDocumentUri.startsWith(fileProtocol)) {
let filename = filenameFromUri(textDocumentUri);
let uri = URI.parse(textDocumentUri);
if (uri.scheme == fileScheme) {
let filename = filenameFromUri(uri);
let cliPath = settings.cliPath;

// If we are executing Grain on Windows in `cmd.exe`,
Expand Down

0 comments on commit 66cfa08

Please sign in to comment.