-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix negative number returned by rulerefs provider issue #894
Conversation
Since character position is a `uint`, this would fail when returned to the Go handler. Also: - Remove some prints we did to debug performance - Some cleanups to align rulerefs with other providers Fixes #887 Signed-off-by: Anders Eknert <anders@styra.com>
|
||
position := location.to_position(input.regal.context.location) | ||
|
||
line := input.regal.file.lines[position.line] | ||
|
||
last_word := regal.last(regex.split(`\s+`, trim_space(line))) | ||
word := location.ref_at(line, input.regal.context.location.col) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an added bonus — and quite a nice one too! — we'll now also get completions for refs even when the ref is not the last thing being typed on the line.
"range": { | ||
"start": { | ||
"line": position.line, | ||
"character": position.character - count(last_word), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's where the result could previously be a negative number.
@@ -98,11 +100,11 @@ another_local_rule := imp`]) | |||
}, | |||
"context": {"location": { | |||
"row": 10, | |||
"col": 21, | |||
"col": 26, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how this worked before 😅 I've used |
to mark col
21 and 26 respectively below, and col 21 is in the middle of :=
🤔
another_local_rule :|= imp|
Either way, after the change to use location.ref_at
that function found no word at the given location, and would thus determine the "word" to be ""
— which typically means the completion was manually invoked and that all possible completions should be returned.
some provider | ||
completion := data.regal.lsp.completion.providers[provider].items[_] | ||
|
||
item := object.union(completion, {"_regal": {"provider": provider}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the rulerefs
provider used to return this before, but knowing which provider is responsible for a suggestion is really helpful for debugging, so I moved this to the main router to get it for all providers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 great to get this one sorted.
Since character position is a `uint`, this would fail when returned to the Go handler. Also: - Remove some prints we did to debug performance - Some cleanups to align rulerefs with other providers Fixes StyraInc#887 Signed-off-by: Anders Eknert <anders@styra.com>
Since character position is a
uint
, this would fail when returned to the Go handler.Also:
Fixes #887