Commit 74c488b
authored
More precise completions and namespace member completions (#1947)
## Feature overview
This PR enables:
1. Much more precise keyword completions where we only show the relevant
syntax at a particular cursor location. For example:
```qsharp
within { } |
```
At the cursor location indicated by `|`, we should only get the keyword
`apply` .
2. More precise completions for names where we take the syntactic
context into account. For example:
```qsharp
operation Foo(x : | )
```
Here, we should only get type names.
3. Namespace member completions. For example:
```qsharp
import Std.Diagnostics.|
```
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.
- Introduce the `WordKinds` flags to define the different kinds of word
tokens that the parser can expect during parsing. (See
`compiler/qsc_parse/src/completion/word_kinds.rs` for longer
description)
- See `compiler/qsc_parse/src/completion/collector.rs` for a description
of how this all works.
- Sprinkle `expect()`s at all possible locations in the parser where we
expect a word.
### Error recovery - AST changes
- Introduce `PathKind::Ok` and `PathKind::Err` .
- This new approach allows for a valid AST node to exist even when path
parsing fails for a partial path. This is good for syntax such as "`open
Std.`" where we need:
- The identifier nodes preceding `.` to be valid, so we can use them to
look up possible completions.
- The `open` statement to also be a valid node, so we can tell that the
context requires a namespace (and not, say, a type name).
- Most existing code will continue to only process valid paths.
- Remove `Idents` struct and replace it with a trait implemented by
various types such as `Path` and `Ident` slices. This should make the
convenience methods easier to use without cloning in/out of the
different types we need.
### Error recovery - parser changes
- Recovering struct parsing, so that e.g. `new Foo.` is still parsed as
a valid struct expression node, allowing us to access the `Foo` ident
from the AST
- Recovering `open` statement parsing so that `open Foo.` can be
recognized as an open item in the AST.
### Language service
In `language_service` is essentially a complete rewrite of
`completions.rs`, so I suggest reviewing the new code only and ditching
the diff.
### Other parser changes
- Move implicit namespace parsing a bit so that it works better with the
completion mechanism.
- This also fixes the spurious "expected item, found eof" error when
document only contains one token
- Delete the dead path `path_field_op`
- Add some missing keywords to item parsing recovery (`export`,
`import`)
### Other notes
- Locals completions exclude `import`s from locals (they conflict with
globals already added to completion) (fix in `resolve.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.
- Only include the samples snippets in empty documents, because now with
the more concise completion list, it gets quite intrusive for them to
show up at every word when typing code.
- Update integration test to account for the fact that completions are
more accurate now.
### Not in this PR (coming next)
- Struct and UDT field access completions.1 parent 2856c76 commit 74c488b
File tree
56 files changed
+5943
-1918
lines changed- compiler
- qsc_ast/src
- qsc_codegen/src
- qsc_doc_gen/src
- qsc_frontend/src
- compile
- preprocess
- resolve
- typeck
- qsc_linter/src/linter
- qsc_parse
- src
- completion
- item
- prim
- tests
- ty
- qsc_qasm3/src
- qsc/src
- interpret
- packages
- language_service/src
- completion
- definition
- references
- state
- playground/src
- vscode
- src
- test/suites/language-service
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
56 files changed
+5943
-1918
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1346 | 1346 | | |
1347 | 1347 | | |
1348 | 1348 | | |
1349 | | - | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
1350 | 1352 | | |
1351 | 1353 | | |
1352 | 1354 | | |
| |||
1865 | 1867 | | |
1866 | 1868 | | |
1867 | 1869 | | |
1868 | | - | |
| 1870 | + | |
1869 | 1871 | | |
1870 | 1872 | | |
1871 | 1873 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | 240 | | |
265 | 241 | | |
266 | 242 | | |
| |||
0 commit comments