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

Fix LSP crash when a resolved import term fails to typecheck #1191

Merged
merged 11 commits into from Mar 30, 2023

Conversation

ebresafegaga
Copy link
Contributor

@ebresafegaga ebresafegaga commented Mar 20, 2023

Currently, when we open a Nickel file and some of content of one or more imports don't typecheck, the LSP crashes.

This pull request fixes that.

@ebresafegaga ebresafegaga self-assigned this Mar 20, 2023
@github-actions github-actions bot temporarily deployed to pull request March 20, 2023 15:59 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 22, 2023 15:37 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 23, 2023 16:12 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 23, 2023 16:32 Inactive
@ebresafegaga ebresafegaga marked this pull request as ready for review March 27, 2023 13:37
@github-actions github-actions bot temporarily deployed to pull request March 27, 2023 13:39 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 27, 2023 15:55 Inactive
Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

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

I think there are two things in one: not crashing on typechecking failure, and showing a nice error message. I have reservation with respect to the second point; however, the first one is valuable in itself. So if you want to separate the two (and remove the error-reporting part), I'm fine merging the first part already.

lsp/nls/src/cache.rs Outdated Show resolved Hide resolved
// We do this to get a list of the imports that have been resolved
// but don't typecheck, and then, we give an appriopiate diagnostics
let mut errors = Vec::new();
let term = term.traverse::<_, _, ()>(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think traversing the whole term again unconditionally (even if no import failed) is reasonable. Some terms might be huge (@vkleen's auto-generated contracts).

If you need this information, would that be possible to build it up during linearization? Keeping e.g. a list of tuples (location, import_id), or even a map HashMap<FileId, Vec<TermPos>>. I won't include the imports that are in a file which failed to parse or typecheck, but I think it's fine for now: at least, a well-typed file will show if there is an issue with its imports.

Secondly, we might want to know if the previous for succeeded, in case we can avoid to do this search in the first place.

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 won't include the imports that are in a file which failed to parse or typecheck

Why though? Isn't the point of having such map to be able to tell the exact position of the import term in the file for a particular import_id?

Copy link
Member

Choose a reason for hiding this comment

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

Because it seems harder to do. If you build the import during linearization, but the current file fails to typecheck, you might not have visited all the terms and the import node.

Also, the need is maybe less clear cut (at least to me): if the current file doesn't even typecheck, the user has already some local red squiggles to work on anyway. Then, once the current file typechecks, we can show imports that has failed, in a second time.

So, put differently, I believe ignoring the import statements in a file which doesn't typecheck seems easier to do, and the consequence doesn't seem too bad.

@ebresafegaga
Copy link
Contributor Author

Sure, I've made a separate pull request for the diagnostics part here #1214

@ebresafegaga ebresafegaga merged commit 02c7d22 into master Mar 30, 2023
4 checks passed
@ebresafegaga ebresafegaga deleted the lsp/typecheck-crash branch March 30, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants