jfecher / ante

A safe, easy systems language
http://antelang.org
MIT License
1.9k stars 80 forks source link

Typechecker diagnostic messages in language server #184

Closed ehllie closed 9 months ago

ehllie commented 9 months ago

Further work towards #179

ehllie commented 9 months ago

I've left some relevant comments. This should be good to merge as is, but I have one idea/ suggestion for a change to the compiler that would help with the language server. It would be something akin to passing a file handler to the compiler and cache, and rather than reading files by creating a File, it would ask the handler for the file contents. That way the lsp could provide access to files that first goes through the document_map, allowing the compiler to run even if the edits made to the files are not saved to the disk, and also possibly speed up compilation by skipping the need to do filesystem io each time.

ehllie commented 9 months ago

image Amazing 🤩! Next steps would be to remove the full file path and source line from the error message I think. If we have access to the original Diagnostic, the inner DiagnosticKind should give us just the error message itself.

I agree with your suggestions you gave as well, it'd be good if we could retrieve the file contents directly from the ls and didn't have to re-read them.

It'd also be nice if we were able to make use of the check method in ante/src/main.rs so we don't have to repeat logic for lexing, parsing, name resolution, and type checking in the language server.

It's interesting how it's using absolute paths for you. It should be using relative paths to the root of the project, and at least it's doing that for me. But I guess I'm currently doing it by "lying" to the compiler about what path the file is at, and it could be done in a smarter way.

![image](https://github.com/jfecher/ante/assets/20847625/99a468fa-3bee-4d35-91bf-6c18cbd1f1e4)