grain-lang/grain-language-server

Errors on Windows

phated opened this issue · 13 comments

With my work on getting the Grain compiler to work on Windows, I wanted to test the LSP. However, I ran into a couple of issues.

Upon startup, this is logged:

[1125/135810.399:ERROR:registration_protocol_win.cc(103)] CreateFile: The system cannot find the file specified. (0x2)

And then if I turn on tracing, I get this error a single time and then nothing else (even upon changing the file, etc):

Validating file:///c%3A/Users/User/GitHub/grain/test.gr
Exception:

I think the compiler makes sure the file location passed, in this case /c%3A/Users/User/GitHub/grain/test.gr, exists before it will do anything.

I'll get this set up on Windows and take a look.

Thanks! There are a couple PRs that still need to land before the compiler will work on Windows from the master branch, but https://github.com/grain-lang/grain/tree/windows-static-linking is building programs for me now.

LSP mode runs off stdin, so I test on a Mac like this:

cat test.gr | grain lsp test.gr

It still checks for the existance of the file for several reasons:

cmdliner is hard to understand - it would be good to be able to specify the file path isn't needed in lsp mode, but ...
I think the file path is used to resolve relative references, so I kept it in for safety.

Several things to look at - how Windows handles stdin, and that escaped path: /c%3A/Users

Does the file at that path exist btw?

I'm pretty sure it's the uri escaped path. The file exists at C:\Users\User\GitHub\grain\test.gr

Testing with a relative path probably won't work for this case because the vscode extension is passing an escaped absolute path.

Looks like this is a known issue that they don't want to solve upstream: microsoft/vscode-languageserver-node#105

Woot, I found the 2 problems. We actually need to default the command to grain.cmd and clean up that path escaping when on Windows!

I might not be able to submit a patch tonight, but I'll try to put something together when I have time.

Sorry, just waking up on this side of the world! I'll take a look at the path escaping - is grainc happy with Windows style paths internally?

Well, I just landed grain-lang/grain#433 which makes grainc accept either \ or / on Windows, so we don't really need to do any escaping. We just need to make sure that a Windows path doesn't start with / but instead a drive letter as the root, and that the colon is passed unescaped.

How do we solve the grain.cmd issue? I guess at the moment it can be set in the LSP settings, but not sure how to support dual names. I've not done any research yet tbh.

I think the easiest way is just to change the default based on the OS. I think there's a way to make cp.execSync handle the non-cmd version, but I don't want to research that 🤣

Fixed by #20