-
Notifications
You must be signed in to change notification settings - Fork 7
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
Adds backticks to dbNames/aliases if needed #310
Conversation
🦋 Changeset detectedLatest commit: a011d66 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/language-support/src/autocompletion/completionCoreCompletions.ts
Show resolved
Hide resolved
32b7c93
to
4a9391c
Compare
return parameterSuggestions.map((completionItem) => ({ | ||
label: completionItem.label, | ||
kind: completionItem.kind, | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these mappings to label and kind? This is not doing anything I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used to backtick if needed parameters too (so had insertText: backtickIfNeeded(...label) too), but they could not be added with backticks yet. Looks like I forgot to remove the whole thing.
Either way, since we're changing the parser-file for creating params, maybe we should just add backticks if needed here already, so once it's valid, we're good to go?
return result.map((completionItem) => ({ | ||
label: completionItem.label, | ||
kind: completionItem.kind, | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
].map((completionItem) => ({ | ||
label: completionItem.label, | ||
kind: completionItem.kind, | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
test('Correctly completes database names/aliases with special symbols using backticks', () => { | ||
const query = 'SHOW DATABASE '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is unnecessary, you could just add the completions to the existing test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split it on purpose so you would see that only this test failed if something purely related to backticks broke. You don't think there's any value to this?
], | ||
}); | ||
}); | ||
|
||
test('Correctly completes database names and aliases in SHOW DATABASE', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a SHOW ALIAS
test in this file which you should add the corresponding checks to
return parameterSuggestions.map((completionItem) => ({ | ||
label: completionItem.label, | ||
kind: completionItem.kind, | ||
insertText: backtickDbNameIfNeeded(completionItem.label), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a parameter include the .
, otherwise this should be backtickIfNeeded
, no? Same for some of the uses below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, this is not valid
return undefined; | ||
} | ||
const namePart = e.slice(1); | ||
if (e[0] == '$') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I even have this test, or just trust the backtickParam... -method to only be called with params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay to have double guards in case something goes wrong in the other part of the code.
… of parameters (for now)
bec5e8c
to
050a918
Compare
I think what is new from your last review is just the PR shifting to $ |
if (/[^\p{L}\p{N}_]/u.test(namePart) || /[^\p{L}_]/u.test(namePart[0])) { | ||
return '$' + `\`${namePart}\``; | ||
} else { | ||
return undefined; | ||
} | ||
} else { | ||
return backtickIfNeeded(e); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could refactor all this method to depend on the backtickIfNeeded
as:
function backtickParamIfNeeded(e: string): string | undefined {
if (e == null || e == '') {
return undefined;
}
const namePart = e.slice(1);
const backticked = backtickIfNeeded(namePart);
if (backticked) {
return '$' + backticked;
} else {
return undefined;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like fixing comment 2 will actually mean I can get ahead of adding the $ and just use backtickIfNeeded from scratch
return parameterSuggestions.map((completionItem) => ({ | ||
label: completionItem.label, | ||
kind: completionItem.kind, | ||
insertText: backtickParamIfNeeded(completionItem.label), | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move the insertText thing to where the parameterSuggestions are defined instead of repeating this in the code a few times
return { | ||
label: `$${paramName}`, | ||
kind: CompletionItemKind.Variable, | ||
...(backtickedName != undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comparison needs to be !==
I think.
You can just do this instead
backtickedName ? { insertText: `$${backtickIfNeeded(paramName)}` } : {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Address my last comment please and ready to go 😄
Before autocompletions for database names/aliases would be like:
Ex. database name = "matrix-db"
SHOW DATABASE ^
->SHOW DATABASE matrix-db
which can not be parsednow we get
->
SHOW DATABASE `matrix-db`
Note: we might allow parameters to have escaped names too (
my-param
) in which case we should update their usages for db-name-suggestions tooFurther possibility for stuff that might need backticks - constraints/indexes once we suggest for these.