Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows fixes #71

Merged
merged 27 commits into from
Jan 28, 2021
Merged

Windows fixes #71

merged 27 commits into from
Jan 28, 2021

Conversation

johnpangalos
Copy link
Contributor

Some fixes to the extension on windows including showing errors and running bsb.

  • The error path wasn't taking into account that on windows paths often start with C:/ while looking for a ':'.
  • On windows, you have to call child processes differently.

Thanks to @mewhhaha for doing all the work!

Fixes #41

Copy link
Member

@chenglou chenglou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Left some comments =D

cwd: projectRootPath,
});
return process;
switch (os.platform()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use process.platform. Or are we all supposed to switch to os.platform()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed that! Will change to process.platform. 😄

});
return process;
switch (os.platform()) {
case "win32": return childProcess.exec(`${bsbPath}.cmd -w`, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if-else please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe all these switch statements I introduced should be if-else? Would that be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed all of them into if elses.

@@ -1,264 +1,8 @@
{
"name": "rescript-language-client",
"version": "0.0.1",
"lockfileVersion": 2,
"lockfileVersion": 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm I guess this should not be in this diff? Also the team's using a newer version of npm, thus the lockfile version difference

Copy link
Contributor

@mewhhaha mewhhaha Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Should restore the lock-file. 👍

let location = fileAndLocation.substring(locationSeparator + 1);
let [fileAndLocationLine, ...diagnosticMessage] = parsedDiagnostic.content;

let fileAndLocation = fileAndLocationLine.trim()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the trim here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that the lines came in with spacing in front of the path, like: ' C:\rescript-project-template\src\Demo.res:1:14-20\r\r'. Would have to remove the whitespace so it's possible to slice off the drive letter and colon afterwards. I think this was done with .slice(2) before. Would you rather it be done using that method? Is it always 2 spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was substring(2) but that's the issue we saw. It can be done in the original way.

I do feel like trim makes it clearer what's going on, and can be more robust if the compiler decides to change the number of spaces (like @mewhhaha seems to be implying from 'Is it always 2 spaces')

Let us know which you prefer and it's an easy fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, the 2 spaces is guaranteed. I've put a note here just now: https://github.com/rescript-lang/rescript-vscode/blob/20841214830a3a81140f63a8973ab5d08cfcd79f/CONTRIBUTING.md#compilerlog

Whenever it's not, it's a bug that shouldn't be covered up here, but rather fixed int the compiler. We've caught a few compiler diagnostics display bugs this way actually.

In general also, we'd like to avoid trimming: https://github.com/rescript-lang/rescript-vscode/blob/20841214830a3a81140f63a8973ab5d08cfcd79f/CONTRIBUTING.md#formatting-newline

FYI trimming has caused and hidden all sorts of bugs before. Sometime the formatting adds a newline, or two, then the editor trims, adds a new line, or whatever. Lots of little shuffling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go ahead and fix this and change it back to the cutting out the 2 spaces using substring.

@chenglou
Copy link
Member

Btw, what about bsc?

export let formatUsingValidBscPath = (

let file = fileAndLocation.slice(0, locationSeparator)
let location = fileAndLocation.slice(locationSeparator + 1)
if (process.platform === "win32") {
return [`file:\\\\\\${file}`, location];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what's this for?

Copy link
Member

@chenglou chenglou Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat related: I had a note about file: at

// TODO: this doesn't handle file:/// scheme
. Not sure if relevant. I think vscode had some utilities for handling file:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think so too, I'll try it and see if that gives us the same result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working on my Ubuntu and Windows 10. Do you see the current approach (Uri.file(..)) to be an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should be what @chenglou was talking about, the utility vscode has for handling files.

@chenglou
Copy link
Member

Sorry, maybe I got ahead of myself but I thought the vscode-uri util would have been more useful; I guess not right now.
The extra dep isn't worth the one line usage; I'll remove it.

Merging now. Thanks so much! Could you test master afterward? Then I'll make a release.

@chenglou chenglou merged commit 2388fa2 into rescript-lang:master Jan 28, 2021
@mewhhaha
Copy link
Contributor

I tried it on my Windows 10 machine and it worked! Thanks!

@chenglou
Copy link
Member

chenglou commented Jan 28, 2021

I've cleaned up the file and location parsing code to parse even more seriously in fc2e73f. Now it doesn't accidentally parse the wrong :, so doesn't need windows-specific heuristics in that one place anymore.

Will release tomorrow.

@mewhhaha
Copy link
Contributor

It seems like a good idea to match on the consistent part of the incoming line, however this regex doesn't work for me as the incoming line looks like C:\\rescript-project-template\\src\\Demo.res:1:14-20\r\r. I'm guessing these carriage return characters are the issue.

@chenglou
Copy link
Member

You mean \r\n right?

@mewhhaha
Copy link
Contributor

I would've expected \r\n, but the debugger gives me \r\r. Is that just an issue with the debugger?

@chenglou
Copy link
Member

Ah probably because of

let lines = content.split("\n");

@mewhhaha
Copy link
Contributor

mewhhaha commented Jan 28, 2021

Maybe splitting on /\r?\n/ would help?

EDIT: I still get a \r left when splitting on /\r?\n/, which I could have expected (╯°□°)╯︵ ┻━┻

@chenglou
Copy link
Member

I'm splitting on os.EOL now. Try that?

@mewhhaha
Copy link
Contributor

mewhhaha commented Jan 28, 2021

It doesn't work for me. There are still lingering \r characters on some of the lines. Maybe it'd help if I posted the content of what's being read from the compiler.log:

'#Start(359482524)\r\n\r\r\n We've found a bug for you!\r\r\n C:\\rescript-project-template\\src\\Demo.res:1:14-20\r\r\n \r\r\n 1 │ let x: int = "asdas"\r\r\n \r\r\n This has type: string\r\r\n Somewhere wanted: int\r\r\n \r\r\n You can convert string to int with Belt.Int.fromString.\r\r\n \r\r\n#Done(359482556)\r\n'

@chenglou
Copy link
Member

chenglou commented Jan 28, 2021

That log file consists of bsb, ninja and ocaml's format module, so I'm thinking maybe there's some mix of hard-coded \n in there and \r\n from one or more of these that properly handles newline. Except... that wouldn't produce a double \r...? Another way of looking at this is, obviously \r\n is inserted properly, so where does that first extra \r come from?

@mewhhaha
Copy link
Contributor

mewhhaha commented Jan 28, 2021

Splitting on /\r?\r?\n/ would work, but maybe that's circumventing the issue. Seems like it's \r\n that's being translated into \r\r\n at least and it only occurs between #Start and #Done. Perhaps it looked like #Start(..)\n\r\n.. at some point and then all newlines were prefixed with an \r, like (\r)\n\r(\r)\n.

@chenglou
Copy link
Member

Ugh, I guess I'll have to end up using trim() anyway...

chenglou added a commit that referenced this pull request Jan 28, 2021
@chenglou
Copy link
Member

Done!

@mewhhaha
Copy link
Contributor

mewhhaha commented Jan 28, 2021

I think it'd be the most maintainable way of doing it, just trim instead of slice. \r?\r?\n? just feels like someone would go in and accidentally "correct" it later on. But you could limit the trim to Windows if you want. 🎈

@mewhhaha
Copy link
Contributor

I'll try it out!

@mewhhaha
Copy link
Contributor

It's working. Thank you very much! Great work!

@chenglou
Copy link
Member

Np. Don't like the circumvention that hides more bug, but it'll have to do for now =)

@mewhhaha
Copy link
Contributor

mewhhaha commented Jan 28, 2021

Yes, I understand. I think so too. But at least the first impression for Windows users will be much better now!

@chenglou chenglou mentioned this pull request Feb 6, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

on windows, the error diagnostics does not work
3 participants