You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The most basic gesture to get completions in VS Code / Positron is Ctrl + Space. From the IntelliSense docs:
You can trigger IntelliSense in any editor window by typing ⌃Space or by typing a trigger character ...
(BTW this is invoking the command editor.action.triggerSuggest.)
Now, more often, you type a few characters and then you get completions.
Either automatically after 3 characters or because you request with tab or because you trigger with a character, like $ or @.
But what if you want to trigger completions before you've typed anything? You can use
Ctrl + Space to do it.
This should reveal "all completions", for some definition of "all".
But currently ark returns ZERO completions in this scenario.
This causes VS Code / Positron to fall back to this weird language agnostic word based completion list (quote is from Intellisense docs):
VS Code supports word-based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.
Empirically, this list seems to consist of tokens parsed out of ?all the files you have open in the current window?. Something like that.
Ways to experience this:
Ctrl + Space at the R prompt in the Console
Ctrl + Space in an empty R file (looks same as above)
Ctrl + Space on an empty line of a non-empty R file
Why does this happen?
Because the nominal completion node when the user hasn't typed anything yet does not meet our criteria for providing completions.
Mostly because our logic doesn't account for the possibility that there really is no completion node and, instead, always latches on to something "nearby", in find_closest_node_to_point():
We then fail to pass the is_identifier_like() test when getting composite completions, which means we never consult keywords, snippets, the search path, the current document, or the current workspace.
And thus ark returns zero completions and the fallback list kicks in.
In the log, you can see the completion search just ends abruptly.
[R] 2025-04-10T15:47:27.133734Z INFO Getting completions from composite sources
[R] 2025-04-10T15:47:27.133751Z INFO Trying completions from source: call
[R] 2025-04-10T15:47:27.133796Z INFO Trying completions from source: pipe
[R] 2025-04-10T15:47:27.133816Z INFO Trying completions from source: subset
This happens in two different ways:
The document really is empty, so the node type is 'Program' and the node text is the empty string. Cases 1 and 2 in the list above. How it looks in the log:
The document is not empty, so ast.root_node().find_closest_node_to_point(point) latches on to a bit of code elsewhere in the document. The node text varies, of course, but generally it fails the is_identifier_like() test. Case 3 in the list above. Examples of how this looks in the log:
Add the empty string or the 'Program' node as a special case that satisfies is_identifier_like(). See PR Be willing to complete in the face of emptiness #772 for this. This feels like a bandaid. But it is a really good bandaid that fixes one route into this problem.
Recognize it's possible that the completion node is actually undefined and account for this when constructing and processing a DocumentContext. This is a bigger undertaking.
I need to discuss with others before moving forward.
This analysis has brought up some other ideas:
Store the the completion node's kind and text in the CompletionContext, alongside features like parameters hints and pipe root. You end up wanting to know these facts in various places downstream, for logging and branching, and it's a bit of a PITA to inline that repeatedly.
Maybe we really should make "is identifier like" into another feature that we store in the completion context and can branch on. For example, I think we can probably skip all unique sources if that is false. Then, for composite sources, we could push that check down into the implementation of each composite source. We've discussed this before and already thought this might be a good idea.
The text was updated successfully, but these errors were encountered:
Anecdotally, when asking for completions in one of these valid-but-empty contexts, different folks are getting different results at different times. I don't have complete clarity on this, but approximately:
"No suggestions" is seen in release builds of Positron (?)
The word-based completions are seen in dev builds of Positron (?), as shown in plenty of screenshots above
The most basic gesture to get completions in VS Code / Positron is Ctrl + Space. From the IntelliSense docs:
(BTW this is invoking the command
editor.action.triggerSuggest
.)Now, more often, you type a few characters and then you get completions.
Either automatically after 3 characters or because you request with tab or because you trigger with a character, like
$
or@
.But what if you want to trigger completions before you've typed anything? You can use
Ctrl + Space to do it.
This should reveal "all completions", for some definition of "all".
But currently ark returns ZERO completions in this scenario.
This causes VS Code / Positron to fall back to this weird language agnostic word based completion list (quote is from Intellisense docs):
Empirically, this list seems to consist of tokens parsed out of ?all the files you have open in the current window?. Something like that.
Ways to experience this:
Ctrl + Space at the R prompt in the Console
Ctrl + Space in an empty R file (looks same as above)
Ctrl + Space on an empty line of a non-empty R file
Why does this happen?
Because the nominal completion node when the user hasn't typed anything yet does not meet our criteria for providing completions.
Mostly because our logic doesn't account for the possibility that there really is no completion node and, instead, always latches on to something "nearby", in
find_closest_node_to_point()
:ark/crates/ark/src/lsp/document_context.rs
Line 28 in 4074f51
We then fail to pass the
is_identifier_like()
test when getting composite completions, which means we never consult keywords, snippets, the search path, the current document, or the current workspace.ark/crates/ark/src/lsp/completions/sources/composite.rs
Lines 58 to 60 in 4074f51
And thus ark returns zero completions and the fallback list kicks in.
In the log, you can see the completion search just ends abruptly.
This happens in two different ways:
The document really is empty, so the node type is 'Program' and the node text is the empty string. Cases 1 and 2 in the list above. How it looks in the log:
The document is not empty, so
ast.root_node().find_closest_node_to_point(point)
latches on to a bit of code elsewhere in the document. The node text varies, of course, but generally it fails theis_identifier_like()
test. Case 3 in the list above. Examples of how this looks in the log:Thoughts about how to solve this:
is_identifier_like()
. See PR Be willing to complete in the face of emptiness #772 for this. This feels like a bandaid. But it is a really good bandaid that fixes one route into this problem.DocumentContext
. This is a bigger undertaking.I need to discuss with others before moving forward.
This analysis has brought up some other ideas:
CompletionContext
, alongside features like parameters hints and pipe root. You end up wanting to know these facts in various places downstream, for logging and branching, and it's a bit of a PITA to inline that repeatedly.The text was updated successfully, but these errors were encountered: