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 not giving completion when an identifier is prefixed by a delimiting character #1043

Merged
merged 6 commits into from
Jan 16, 2023

Conversation

ebresafegaga
Copy link
Contributor

Closes #1040

@ebresafegaga ebresafegaga self-assigned this Jan 16, 2023
@github-actions github-actions bot temporarily deployed to pull request January 16, 2023 12:25 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.

Left a few questions, but overall the change is fine

let path = path
.split('.')
.map(|str| {
let (str, is_unicode) = remove_quotes(str);
Copy link
Member

Choose a reason for hiding this comment

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

the is_unicode name is a bit unsettling here. The documentation of remove_quotes says that the return value indicate if one of the fields was quoted, isn't it? What's the relation to unicode?

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 guess most static fields are quoted because they probably have a character that isn't allowed in a Nickel identifier (e.g unicode characters). But you're right, a it might not be a unicode string. I've made changes, thank you!

static ref RE: regex::Regex = regex::Regex::new(r"[_a-zA-Z0-9-']*[a-zA-Z]_?").unwrap();
// unwraps are safe here because we know these are correct regexes.
// This regexp must be the same as the regex for identifiers in the lexer (nickel_lang::parser::lexer)
static ref RE: regex::Regex = regex::Regex::new(r"_?[a-zA-Z][_a-zA-Z0-9-']*").unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

In retrospective, RE is a pretty bad name. I guess it's the regular expression for an identifier? RE_IDENTIFIER might be more explicit.

@@ -287,16 +298,21 @@ fn get_identifier_path(text: &str) -> Option<Vec<String>> {

let result: Vec<_> = RE_SPACE.split(text.as_ref()).map(String::from).collect();
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't have to be addressed in this PR, but I guess this won't work well with spaces within a quoted field, like foo."bar baz".blarg ?

Copy link
Member

Choose a reason for hiding this comment

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

On possibility for the future, which might be more resilient, could be to run the lexer on the text, and pop the tokens. Doing so, we are sure to handle it in the same way the Nickel parser would do.

Copy link
Contributor Author

@ebresafegaga ebresafegaga Jan 16, 2023

Choose a reason for hiding this comment

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

Ah yes, this will require us to use the lexer/parser (I was trying to avoid this, but we will have to use it now). I'll create another issue to track this.

Copy link
Member

Choose a reason for hiding this comment

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

@ebresafegaga I think the lexer is enough for that, and it's both simpler and lighter than the parser I guess. There might just a bit of concatenation to do when emitting string chunks.

@github-actions github-actions bot temporarily deployed to pull request January 16, 2023 15:13 Inactive
@ebresafegaga ebresafegaga merged commit 9f32c43 into master Jan 16, 2023
@ebresafegaga ebresafegaga deleted the lsp/delim-prefix branch January 16, 2023 16:57
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.

No LSP completion when an identifier is prefixed by a delimiting character
3 participants