fix(editor): teach auto-uppercase every keyword autocomplete offers - #2912
Merged
Merged
Conversation
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
This file contains hidden or 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
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.
Two lists decide what counts as a SQL keyword and nothing made them agree. Found while investigating #2833.
The defect
SQLKeywords.keywordSetis built fromSQLKeywords.keywordsalone, and it is the only vocabulary Auto-uppercase consults. The completion provider offers keywords from 31 clause-specific arrays written inline ingetCandidates, and 21 single words in those arrays were never added to the catalogue.Reproduction. Settings > Editor, turn on Auto-uppercase keywords. Type:
Result:
ALTER TABLE users add COLUMN note TEXT;addis the one word left alone, becauseALTER,TABLE,COLUMNandTEXTare in the catalogue andADDis not, even though autocomplete had offeredADDa keystroke earlier. Same shape formerge into ...andcall proc().The fix
The 21 missing words go into
SQLKeywords.keywords, in the groups they belong to:ADD,CHANGE,AFTER,COMMENT,COLLATE,CHARSET,ENGINE,TABLESPACE,MERGE,UPSERT,REPLACE,CALL,USE,SIGNED,UNSIGNED,RANGE,GROUPS, and the index access methodsBTREE,HASH,GIN,GIST.The index methods are included deliberately. They are unreserved keywords in the
CREATE INDEX ... USINGposition, uppercasing them produces valid SQL, and excluding four words on the grounds that they might also be column names is exactly the unprincipled special-casing that produced the gap.DATE,TEXT,KEY,SETandTIMEalready have that property and are already in the catalogue.Why a test rather than a refactor
The structural fix would be to hoist all 31 clause arrays into
SQLKeywordsso one union feeds both consumers. I did not, because those arrays are what makes each arm ofgetCandidatesreadable, and that function is already at the SwiftLint body limit; replacing 31 inline vocabularies with 31 constant names moves the cost rather than removing it.KeywordVocabularyParityTestsinstead readsSQLCompletionProvider.swiftand fails when it offers a single-word keyword the catalogue does not hold. You cannot now add a keyword to a clause arm without teaching the uppercaser about it. This is the shape the repo already uses for the same class of problem, inHealthMonitorOptOutParityTestsandSyncMapperFieldAccessTests.The guard catches the original defect. Run against the unfixed catalogue it fails
offeredKeywordsAreUppercasable,reportedStatementUppercasesConsistently, and every case ofreportedKeywordsAreKnown.Verification
generatePASS,testPASS (231 of 231 acrossKeywordVocabularyParityTests,SQLKeywordsTests,KeywordUppercaseHelperTests,SQLCompletionProviderTests,CompletionEngineTests),lintPASS.Docs already describe the setting generically ("Uppercases SQL keywords on word boundaries"), which stays accurate.
No UI change, so no screenshots.
Note
This and #2902 both add a line under
### Fixedin the CHANGELOG, so whichever merges second needs that one-line rebase. They touch no source file in common.