-
Notifications
You must be signed in to change notification settings - Fork 58
Use the vendored parser to drive autocomplete. #388
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
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1393eba
to
aad4b61
Compare
First step: find the parsetree expression for the item to be completed.
aad4b61
to
ef2f7bf
Compare
<div x=Outer.Inner. name="" /> parses as x=Outer.Inner.name
Sometimes "Foo. " is followed by "bar" and the parser's behaviour is to parse as "Foo.bar". This gets back the intended path "Foo."
Complete with anything in scope including open modules and pervasives.
When completing `x=`, if the following contains `name=...`, then the parser interprets it as `x=name`. Now detect that the cursor is after the label `x` but before `name`, and don;t interpret the situation as label completion.
Use symbol "_" like in other places in the parser.
cristianoc
added a commit
to rescript-lang/syntax
that referenced
this pull request
Apr 22, 2022
More fine grained error recovery from parsing longidents. E.g. Foo. gives Foo._ instead of a default expression which erases info on what's parser already. From: rescript-lang/rescript-vscode#388
cristianoc
added a commit
to rescript-lang/syntax
that referenced
this pull request
Apr 22, 2022
More fine grained error recovery from parsing longidents. E.g. Foo. gives Foo._ instead of a default expression which erases info on what's parser already. From: rescript-lang/rescript-vscode#388
cristianoc
added a commit
to rescript-lang/syntax
that referenced
this pull request
Apr 22, 2022
More fine grained error recovery from parsing longidents. E.g. Foo. gives Foo._ instead of a default expression which erases info on what's parser already. From: rescript-lang/rescript-vscode#388
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The vendored parser has a recovery mechanism where parsing continues past an error. This makes it suitable to support autocomplete, which is triggered on incomplete code which would normally not parse.
This replaces the previous hand-crafted mini-parser used specifically for autocomplete, which would start from the cursor position, and try to parse backwards figuring out the context the cursor happens to be in.
The new mechanism starts from the current position and the parse tree produced by the parser. For example,
List.
gets parsed asList._
where the dummy identifier_
is inserted by the recovery mechanism.If the cursor position is immediately after
.
, the mechanism finds the relevant node in the parse tree which represents expressionList._
, and uses that information for autocomplete.One of the benefits of this new approach is that relying on the actual parser gives a better handling of corner cases (e.g. support for template literals inside strings comes for free), and avoids the maintenance burden of supporting/extending the ad-hoc parser.
Another benefit is that the parser provides contextual information, which can be used to decide whether e.g. the current context is a value context or type context, or variant context, or field name context. So that
let x = List.m
will complete values fromList
, whilelet f : Js.Promise.
will complete types from moduleJs.Promise
.