teal-language / vscode-teal

Teal language support for Visual Studio Code
MIT License
76 stars 11 forks source link

Errors can show up in the wrong file #12

Closed pdesaulniers closed 4 years ago

pdesaulniers commented 4 years ago

If test1.tl requires test2.tl and test2.tl contains errors, then the squiggly lines for test2.tl will show up in test1.tl...

factubsio commented 4 years ago

Yeah I have this too, it basically makes multiple files unusable, I will try to look at why it's happening but this is a pretty major thing.

pdesaulniers commented 4 years ago

@factubsio Great! I think it's a matter of setting the right URI here: https://github.com/teal-language/vscode-teal/blob/1985c89ed5f2572e119b4125eb4ba278be276eb9/server/server.ts#L240

factubsio commented 4 years ago

Ah ace, I will dig into this thanks!

factubsio commented 4 years ago

Well this is fun, it doesn't always exhibit the behaviour. 🤔

factubsio commented 4 years ago

Ok so I can get rid of the wrong errors but we lose the errors from the required file.

The issue is we need to get a full uri of the required file, but that is resolved inside tl check which is, among other things, dependent on the tlconfig.lua.

I think the best path (no pun intended) is for tl check to have an option, via an option in tlconfig and/or a command line arg, to return full paths for errors. I will open an issue/PR there.

pdesaulniers commented 4 years ago

Yeah, sounds like a good idea!

One potential issue though is that, right now, the language server copies the current text buffer into a temporary file and runs tl check on that file. That way, we don't have to save the .tl file to trigger the type-checking.

The URI should not point towards the temporary file, but towards the actual document...

Can you find some way around this?

factubsio commented 4 years ago

😬 I wonder if it would be OK to only show errors for files in your workspace.

As far as I can tell tl check always returns paths relative to where you run it from, even with tlconfig.lua includes.

i.e.

.
├── inc_dir
│   ├── point.d.tl
│   └── test.tl
└── tlconfig.lua

1 directory, 3 files
mcw@DESKTOP-A0LAQ1C:/mnt/c/Users/micha/fullpatherr$ cat tlconfig.lua
return {
    include = {
        "inc_dir"
    }
}

mcw@DESKTOP-A0LAQ1C:/mnt/c/Users/micha/fullpatherr$ ../tl/tl check inc_dir/test.tl
========================================
1 syntax error:
inc_dir/point.d.tl:6:5: attempt to redeclare field 'y' (only functions can be overloaded)
mcw@DESKTOP-A0LAQ1C:/mnt/c/Users/micha/fullpatherr$

which means I think we can just check if (pseudocode): ${workspacePath} .. / .. errorPath exists, and only return the error if it does?

This means errors for files outside the workspace would be dropped. I am seeing what tl gives if the error is outside the workspace, but the workspace also contains a file with that name.

factubsio commented 4 years ago

Also, whenever the language server crashes vscode crashes with Error: Cannot find module 'vscode' - I have done an npm install but that doesn't seem to fix the issue, do you know what I'm supposed to do to set up vscode properly to debug?

(I can set breakpoints fine, but if it crashes it crashes hard).

factubsio commented 4 years ago

Oh gosh it's because I'm in the language server itself...

factubsio commented 4 years ago

image