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 negative number returned by rulerefs provider issue #894

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

anderseknert
Copy link
Member

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

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 <[email protected]>

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)
Copy link
Member Author

@anderseknert anderseknert Jul 2, 2024

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),
Copy link
Member Author

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,
Copy link
Member Author

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}})
Copy link
Member Author

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.

Copy link
Member

@charlieegan3 charlieegan3 left a 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.

@anderseknert anderseknert merged commit 4ec7018 into main Jul 3, 2024
3 checks passed
@anderseknert anderseknert deleted the completion-fix branch July 3, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Moving back to edit before accepted suggestion results in error
2 participants