Skip to content

Conversation

@dobladez
Copy link
Contributor

@dobladez dobladez commented Dec 7, 2020

What does this PR do?

Provide initial code completion with fields on SELECT clause

What issues does this PR fix or reference?

W-8432064

* Extracts the object referenced in FROM
* Supports nested SELECT statements
* Generate completion item with SELECT FROM snippet only where it applies
* Actual retrieval of SObject fields is responsibility of the LSP client
Copy link
Contributor

@jgellin-sf jgellin-sf left a comment

Choose a reason for hiding this comment

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

Solid work here. One question about the matching algorithm.

Comment on lines +312 to +319
const selectToken = this.selectsStack.pop();
if (selectToken) {
this.matchedSelectFroms.push({
select: selectToken,
from: fromToken,
sobjectName: sobjectName,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does SELECT (SELECT |) FROM X break the stack-based matching? If so, won't SELECT |, (SELECT ) FROM X not match the first SELECT with the X object? Do we need a check to make sure the SELECT and FROM tokens have the same immediate inner query ancestor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!. Hmm... the second case you mention seems to work fine.

On the first case, it proposes completions for X (which is wrong) but it's not "matching" (that is "pairing") of FROMs with SELECTs that's broken, the problem is on method findSObjectName() which is only looking at the matched pairs, ignoring the SELECTs remaining on the stack.
I'll try to fix it.

BTW, How about I rename matchedSelectFroms to pairedSELECT_FROMs or similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ambivalent on the rename. Whatever works. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I was wrong! You are right that the matching fails on the first case!
I've replied too quickly assuming the "pairing" of the FROMs was done on exitSoqlInnerQuery (instead of exitSoqlFromExprs)... so yes, the FROM is paired with the inner SELECT on your first example.

The second example does work, but for the wrong reason ;-): The second SELECT is not recognized by the parser due to the syntax error, thus the FROM is paired with the first SELECT.

Anyway, I'll work on a fix. Thanks again!

@codecov
Copy link

codecov bot commented Dec 9, 2020

Codecov Report

Merging #99 (93ac2f1) into develop (c9c7941) will increase coverage by 0.05%.
The diff coverage is 97.45%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #99      +/-   ##
===========================================
+ Coverage    94.56%   94.62%   +0.05%     
===========================================
  Files           43       43              
  Lines         1215     1283      +68     
  Branches       258      283      +25     
===========================================
+ Hits          1149     1214      +65     
- Misses          64       67       +3     
  Partials         2        2              
Flag Coverage Δ
language-server 96.93% <97.45%> (-0.72%) ⬇️
soql-builder-ui 92.62% <ø> (ø)
soql-model 95.14% <ø> (ø)

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

Impacted Files Coverage Δ
packages/language-server/src/completion.ts 96.79% <97.45%> (-0.94%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c9c7941...93ac2f1. Read the comment docs.

@jgellin-sf jgellin-sf self-requested a review December 10, 2020 19:28
Copy link
Contributor

@jgellin-sf jgellin-sf left a comment

Choose a reason for hiding this comment

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

QA passed. The only issues I found were those already identified and to be covered by W-8558994.

@jgellin-sf jgellin-sf merged commit 0d32428 into develop Dec 10, 2020
@jgellin-sf jgellin-sf deleted the feature/code-completion-SELECT-fields branch December 10, 2020 19:32
dehru added a commit that referenced this pull request Jan 15, 2021
* model WHERE clause (#68)
* Remote SOQL Errors - Language Server Part (#93)
* remove code builder (#92)
* Move from antlr4JS to antlr4TS (#96)
* SOQL code completion for SELECT fields (#99)
* publish language server 0.2.9 (#102)
* Fix LSP dependency (#104)
* Disabled 'Running...' button while query running (#106)
* Add basic code-completion for ORDER BY and other improvements (#107)
* Dehru and JG telemetry - Send GDPR clean data to telemetry when errors/unsupported syntax present (#110)
* Disable WHERE in model (#113)
* Bump versions for publishing (#114)
* Code-completion for WHERE clause expressions (#112)
Co-authored-by: Jonathan Gellin <jgellin@salesforce.com>
Co-authored-by: jgellin-sf <55159130+jgellin-sf@users.noreply.github.com>
Co-authored-by: Chase McCarthy <charles.mccarthy@heroku.com>
Co-authored-by: Jonny Hork <jhork@salesforce.com>
Co-authored-by: Fernando Dobladez <fernandodobladez@salesforce.com>
Co-authored-by: Jonathan Gellin <jgellin@salesforce.com>
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.

2 participants