Skip to content

Commit

Permalink
Fix issue in command-line parsing on Windows with paths of the form `…
Browse files Browse the repository at this point in the history
…c:/...:line:column`

See rescript-lang/rescript-vscode#25
  • Loading branch information
cristianoc authored and chenglou committed Apr 24, 2021
1 parent 8d1e62b commit c1c293b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Support syntax highlight in hover fenced blocks.
- Fix printing of variant arguments.
- Use outcome printer from the syntax to print type declarations.
- Fix issue in command-line parsing on Windows with paths of the form `c:/...:line:column`.

## Release 1.0.0 of rescript-vscode
This [commit](https://github.com/rescript-lang/rescript-editor-support/commit/d45f45793a307a3bb87dcac0542fd412669f1b6e) is vendored in [rescript-vscode 1.0.0](https://github.com/rescript-lang/rescript-vscode/releases/tag/1.0.0).
29 changes: 17 additions & 12 deletions src/rescript-editor-support/EditorSupportCommands.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ let dumpLocations = (state, ~package, ~file, ~extra, ~selectPos, uri) => {
Json.stringify(locationsInfo);
};

// Split (line,char) from filepath:line:char
let splitLineChar = pathWithPos => {
let mkPos = (line, char) =>
Some((line |> int_of_string, char |> int_of_string));
switch (pathWithPos |> String.split_on_char(':')) {
| [filePath, line, char] => (filePath, mkPos(line, char))
| [drive, rest, line, char] =>
// c:\... on Windows
(drive ++ ":" ++ rest, mkPos(line, char))
| _ => (pathWithPos, None)
};
};

let dump = files => {
Shared.cacheTypeToString := true;
let rootPath = Unix.getcwd();
Expand All @@ -118,15 +131,8 @@ let dump = files => {
},
};
files
|> List.iter(filePath => {
let (filePath, selectPos) =
switch (filePath |> String.split_on_char(':')) {
| [filePath, line, char] => (
filePath,
Some((line |> int_of_string, char |> int_of_string)),
)
| _ => (filePath, None)
};
|> List.iter(pathWithPos => {
let (filePath, selectPos) = pathWithPos |> splitLineChar;
let filePath = maybeConcat(Unix.getcwd(), filePath);
let uri = Utils.toUri(filePath);
let result =
Expand Down Expand Up @@ -241,9 +247,8 @@ let complete = (~pathWithPos, ~currentFile) => {
autoRebuild: false,
},
};
switch (pathWithPos |> String.split_on_char(':')) {
| [filePath, line, char] =>
let pos = (line |> int_of_string, char |> int_of_string);
switch (pathWithPos |> splitLineChar) {
| (filePath, Some(pos)) =>
let filePath = maybeConcat(Unix.getcwd(), filePath);
let uri = Utils.toUri(filePath);
let result =
Expand Down

0 comments on commit c1c293b

Please sign in to comment.