Skip to content

[WIP] Fixed open declaration completions when there is no identifier#4106

Closed
TIHan wants to merge 6 commits intodotnet:masterfrom
TIHan:fix-open2
Closed

[WIP] Fixed open declaration completions when there is no identifier#4106
TIHan wants to merge 6 commits intodotnet:masterfrom
TIHan:fix-open2

Conversation

@TIHan
Copy link
Copy Markdown
Contributor

@TIHan TIHan commented Dec 11, 2017

Referring to this issue: #4078

We are getting all symbols when we do completions for open delcarations that do not have an identifier. The reason is because the parser is giving us nothing useful at this specific point.

This fix modifies the parser slightly to give us something to work with. It also gives us a different error message if there is no identifier, "Identifier expected". This is what C# does as well.

This needs a bit of discussion.

In pars.fsy, I'm not entirely sure this is a good idea returning:
[ SynModuleDecl.Open(Ast.LongIdentWithDots([], []), rhsm) ].

rhsm is the range of the OPEN token. Normally the range that is passed to SynModuleDecl.Open is the entire range of Ast.LongIdentWithDots when there is an identifier.

This could be a little confusing. Perhaps there is a better way to represent this kind of thing. I need the range of the OPEN token when there is no identifier in order have completions that result in compilable code.

Also, need to add a little more tests.

@TIHan TIHan requested review from KevinRansom and dsyme December 11, 2017 02:49
Comment thread src/fsharp/pars.fsy
%type <Ast.SynExceptionDefnRepr> exconCore
%type <Ast.SynModuleDecl list> moduleDefnsOrExprPossiblyEmptyOrBlock
%type <Ast.LongIdentWithDots> openDecl
%type <Ast.LongIdentWithDots option> openDecl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Doesn’t this change the F# grammar, allowing empty open statements? If so, is it ok?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later on when we check the option, if it is None, we throw an error, "Identifier expected", so it doesn't pass-through.

@vasily-kirichenko
Copy link
Copy Markdown
Contributor

Having range for open token is nice, I've wanted it on symbols level to gray out the entire "open xxx" in unused open decl analyzer.

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Dec 11, 2017

Maybe SynModuleDecl.Open's range value should include the OPEN token range, and/or be another value separate: Open of openTokenRange : range * longDotId : LongIdentWithDots * range : range

@vasily-kirichenko
Copy link
Copy Markdown
Contributor

Either way would work for my purpose. Would you add this right into this PR?

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Dec 11, 2017

I've added openTokenRange. The final range is the combined openTokenRange and longDotId.Range.

I'll definitely need some feedback regarding this approach. I feel better adding the openTokenRange, but AFAIK there isn't anything that indicates we include other token ranges anywhere in the syntax tree. So this one is special, wondering if it's appropriate.

@vasily-kirichenko
Copy link
Copy Markdown
Contributor

vasily-kirichenko commented Dec 12, 2017

This is great, thanks!

About tokens in parse tree, they are not there for two reasons, I think: they are not needed for compilation, and they should not "pollute" the next compilation stage, as parse tree does not pollute TAST. But, we do need it for tooling, so I’m appreciate this PR.

@vasily-kirichenko
Copy link
Copy Markdown
Contributor

Why it's not merged yet?

@TIHan
Copy link
Copy Markdown
Contributor Author

TIHan commented Jun 4, 2018

Because it's not finished yet.

Looking at this again, I remember I might need @dsyme's feedback if this is how we should start including keyword ranges into the AST.

@KevinRansom
Copy link
Copy Markdown
Contributor

@TIHan, is this still an active PR?

@KevinRansom
Copy link
Copy Markdown
Contributor

@TIHan please reopen when you have time to complete this work.

Thanks

Kevin

@KevinRansom KevinRansom closed this Oct 2, 2018
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.

3 participants