Skip to content
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

Enable completions inside parenthesized expressions #1221

Merged
merged 5 commits into from Jan 5, 2021

Conversation

shenglol
Copy link
Contributor

@shenglol shenglol commented Dec 23, 2020

Added error recovery for parenthesized expressions. After the change () is parsed as a ParenthesizedExpression (with OpenParen=(, Expression=SkippedTriviaSyntax, and CloseParen=)) rather than a SkippedTriviaSyntax. The existing completion handling logic is good enough to trigger completions inside an incomplete ParenthesizedExpression.

Closes #1223.

@shenglol shenglol enabled auto-merge (squash) December 23, 2020 19:09
@TSunny007
Copy link
Contributor

TSunny007 commented Dec 24, 2020

Is there a plan for intellisense for outside parenthesis? What about intellisense without a closed parenthesis (Error hints that you should probably insert the missing ) first )? I seem to be unfamiliar with using () in bicep outside of functions and if condition

var foo = (deploymentScript['properties']).azCli<Version> // outside parenthesis
var foo = (deploymentScript['properties'].a<zCliVersion> // no closed parenthesis

Additionally, I think parenthesis should be blocked inside PropertyAccessSyntax (or even ObjectSyntax?) when not used in a function syntax,

var foo = (deploymentScript(['apiVersion'] //insert as many closing parenthesis as you want at the end, breaks rest of the file
var foo = (deploymentScript.(location)) //errors but its not quite informative (nothing to lose sleep over though, this is a silly thing to try)

@shenglol
Copy link
Contributor Author

shenglol commented Jan 4, 2021

@TarunSunkaraneni

Is there a plan for intellisense for outside parenthesis

var foo = (deploymentScript['properties']).azCli<Version> // outside parenthesis

This is a good find. We should open an issue and track this as a bug.

What about intellisense without a closed parenthesis (Error hints that you should probably insert the missing ) first )

var foo = (deploymentScript['properties'].a<zCliVersion> // no closed parenthesis

With this PR you now get a "missing )" error.

Additionally, I think parenthesis should be blocked inside PropertyAccessSyntax (or even ObjectSyntax?) when not used in a function syntax

var foo = (deploymentScript(['apiVersion'] //insert as many closing parenthesis as you want at the end, breaks rest of the file
var foo = (deploymentScript.(location)) //errors but its not quite informative (nothing to lose sleep over though, this is a silly thing to try)

These two cases are not syntactically valid. The first line doesn't work because we don't support single-line array. For the second one, I think the parser already handles it correctly, and it feels hacky to me to treat it as a special case.

@majastrz
Copy link
Collaborator

majastrz commented Jan 4, 2021

I think in general we do have a problem with how we handle un-closed parentheses, braces and brackets. c# intellisense continues to function even if you don't close whatever symbol was opened, so I think we will need to do the same in the future regardless. (Requires a bit change to the parser recovery logic.)

For dot property access completions on parenthesized expressions, we are missing the logic to flow the "declared type" through those types of syntax nodes. It should light up once that's fixed.

@@ -70,7 +70,7 @@ module './main.bicep' = if

module './main.bicep' = if (
//@[7:21) [BCP096 (Error)] Expected a module identifier at this location. |'./main.bicep'|
//@[28:28) [BCP009 (Error)] Expected a literal value, an array, an object, a parenthesized expression, or a function call at this location. ||
//@[28:28) [BCP018 (Error)] Expected the ")" character at this location. ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

) [](start = 42, length = 1)

That's actually confusing. The original error message was correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will try to tweak the error recovery logic to restore the original error message.

Copy link
Contributor Author

@shenglol shenglol Jan 5, 2021

Choose a reason for hiding this comment

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

@majastrz I tried several ways and the one works best is to change the type of CloseParen from Token to SyntaxBase in order to call WithRecovery. With this change the original error message is restored, and one bonus side effect is that we now have completions inside an un-closed parenthesized expression (... 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense. The SyntaxBase approach is what we've done in other places too.


In reply to: 552174602 [](ancestors = 552174602)

@codecov-io
Copy link

codecov-io commented Jan 5, 2021

Codecov Report

Merging #1221 (a951ee5) into main (4f4639f) will increase coverage by 0.54%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1221      +/-   ##
==========================================
+ Coverage   94.48%   95.03%   +0.54%     
==========================================
  Files         338      334       -4     
  Lines       16987    16853     -134     
  Branches       14        0      -14     
==========================================
- Hits        16050    16016      -34     
+ Misses        937      837     -100     
Flag Coverage Δ
dotnet 95.03% <100.00%> (+<0.01%) ⬆️
typescript ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Bicep.Core/Parsing/Parser.cs 95.22% <100.00%> (+0.01%) ⬆️
...Bicep.Core/Syntax/ParenthesizedExpressionSyntax.cs 100.00% <100.00%> (ø)
src/vscode-bicep/src/extension.ts
src/vscode-bicep/src/utils/telemetry.ts
src/vscode-bicep/src/language/client.ts
src/vscode-bicep/src/utils/logger.ts
src/Bicep.Core.UnitTests/Utils/CompilerFlags.cs 40.00% <0.00%> (+6.66%) ⬆️

Copy link
Collaborator

@majastrz majastrz left a comment

Choose a reason for hiding this comment

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

Awesome!

@shenglol shenglol merged commit d8b14dc into main Jan 5, 2021
@shenglol shenglol deleted the shenglol/completions-for-conditions branch January 5, 2021 22:13
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.

Completions not working inside empty ()
4 participants