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

Parse document for tokens on every LSP on_change event #1195

Merged
merged 4 commits into from
Apr 8, 2022

Conversation

JoshuaBatty
Copy link
Member

see #1177 for context.

closes #1177 and closes #1147

@JoshuaBatty JoshuaBatty self-assigned this Apr 8, 2022
@JoshuaBatty JoshuaBatty added the language server LSP server label Apr 8, 2022
@JoshuaBatty JoshuaBatty force-pushed the josh/lsp_parse_document branch from 077950e to 55ff6b9 Compare April 8, 2022 03:09
session.update_text_document(&params.text_document.uri, params.content_changes)
) -> Vec<Diagnostic> {
let path = params.text_document.uri.path();
let _ = session.update_text_document(&params.text_document.uri, params.content_changes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a Result might be getting ignored here now?

Perhaps the return type of this method should be:

-> Result<Vec<Diagnostic>, DocumentError>

And this line should be:

session.update_text_document(&params.text_document.uri, params.content_changes)?;

Otherwise if there's a reason it's ignored, we should add a comment to justify it.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a fair point. The original possible error comes from using the path as the key into a HashMap of files, if the key doesn't exist an error is returned. The error is being ignored because we never want our server to crash. There is probably no point in returning an error at all then from the update_text_document fn. I'll update that fn now.

Copy link
Contributor

@mitchmindtree mitchmindtree left a comment

Choose a reason for hiding this comment

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

Nice one chap, I think this approach makes a lot of sense at least until we notice re-parsing the whole document causing performance issues downstream!

When/if we do re-visit manually updating small sections of a doc for optimisation purposes, we might want to do so alongside a discussion around incremental parsing in sway-core itself.

if let Some(ref mut document) = self.documents.get_mut(url.path()) {
changes.iter().for_each(|change| {
document.apply_change(change);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess once we get some logging we could do something like log::warn!("no document for url: {}", url); or something along those lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah exactly, logging warnings to the console makes more sense to report errors than crashing for an LSP server.

@JoshuaBatty
Copy link
Member Author

When/if we do re-visit manually updating small sections of a doc for optimisation purposes, we might want to do so alongside a discussion around incremental parsing in sway-core itself.

Yeah exactly, makes a lot of sense for the functionality to come from sway-core. Everything still feels pretty snappy on my end for now anyway.

@JoshuaBatty JoshuaBatty merged commit cc321ff into master Apr 8, 2022
@JoshuaBatty JoshuaBatty deleted the josh/lsp_parse_document branch April 8, 2022 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants