-
Notifications
You must be signed in to change notification settings - Fork 131
More precise completions and namespace member completions #1947
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
Conversation
Change in memory usage detected by benchmark. Memory Report for 6fbbec5
|
I ran some tests to narrow it down. This increase is attributable entirely to the changes in the AST. A bunch of I can't think of a way to shrink the AST any further, we are storing more information in there after all. So I think the 0.04% increase in memory usage is a worthwhile tradeoff for the feature. |
Change in memory usage detected by benchmark. Memory Report for c119d44
|
Change in memory usage detected by benchmark. Memory Report for a9e7e76
|
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.
partially reviewed, will continue to review
@idavis found a bug: Trying to complete import QIR.in; causes a panic since Working on the fix. |
Fixed with my latest commit. |
Change in memory usage detected by benchmark. Memory Report for 96002f0
|
Okay, I regressed things pretty badly with this fix, as @ScottCarda-MS discovered through testing (thanks!). The following piece of code should produce a mostly valid AST (save for the error on line 3). namespace Sample {
operation BellStates() : (Result, Result)[] {
Std.
let bellStateTuples = [];
for (label, prepare) in bellStateTuples {}
return measurements;
}
/// doc comment
operation PreparePhiPlus() : Unit {
}
} With my latest commit, there's no AST at all. cc reviewers @idavis @swernli . I'm going to have to go back to the drawing board with the "keyword after dot" fix that handles |
I pushed what I think is my final update. The parser change to fix the last issue ended up being minimal! Please sign off if no more concerns. |
…tarks/member-completions
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.
Discussed offline that the merge conflict is minor. Everything else looks good, and I tested out the feature manually.
Change in memory usage detected by benchmark. Memory Report for 145b6e6
|
Builds on #1947 . Enables: 1. Field access completions, for example: ```qsharp let x = Complex(1.0, 2.0); x.| ``` At the cursor location indicated by `|`, completions should include `Real` since it's a field of `Complex`. 2. Field assignment completions, for example: ```qsharp struct Foo { bar: Int } new Foo { | } ``` Here, completions should include `Bar`.
Fixing the behavior that regressed in #1947 when I was attempting to limit samples to empty documents only.
Feature overview
This PR enables:
At the cursor location indicated by
|
, we should only get the keywordapply
.Here, we should only get type names.
The completions here should return only items that exist under
Std.Diagnostics
.Code changes
Parser completions module
Introduce the
completion
module in the parser.possible_words_at_offset_in_source
- a new API to return completions at a particular offset . Uses the parser directly as the best source of knowledge about what tokens to expect.WordKinds
flags to define the different kinds of word tokens that the parser can expect during parsing. (Seecompiler/qsc_parse/src/completion/word_kinds.rs
for longer description)compiler/qsc_parse/src/completion/collector.rs
for a description of how this all works.expect()
s at all possible locations in the parser where we expect a word.Error recovery - AST changes
PathKind::Ok
andPathKind::Err
.open Std.
" where we need:.
to be valid, so we can use them to look up possible completions.open
statement to also be a valid node, so we can tell that the context requires a namespace (and not, say, a type name).Idents
struct and replace it with a trait implemented by various types such asPath
andIdent
slices. This should make the convenience methods easier to use without cloning in/out of the different types we need.Error recovery - parser changes
new Foo.
is still parsed as a valid struct expression node, allowing us to access theFoo
ident from the ASTopen
statement parsing so thatopen Foo.
can be recognized as an open item in the AST.Language service
In
language_service
is essentially a complete rewrite ofcompletions.rs
, so I suggest reviewing the new code only and ditching the diff.Other parser changes
path_field_op
export
,import
)Other notes
import
s from locals (they conflict with globals already added to completion) (fix inresolve.rs
)language-configuration.json
: and removed wonky word pattern in playground and VS Code because we don't need it anymore now that we have proper.
completions! Also update trigger characters.Not in this PR (coming next)