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

fix(CodeEditor): make SQL suggestions case insensitive and show columns for WHEN keyword #4498

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/code-editor/src/CodeEditor/languages/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ function getLastKeyword(model: any, position: any) {
const words = textUntilCursor.split(/[\s,.!?;:()]+/);

for (let i = words.length - 1; i >= 0; i--) {
let word = words[i];
let word = words[i].toUpperCase();

if (word === "BY" || word === "KEY" || word === "JOIN") {
if (["BY", "KEY", "JOIN"].includes(word)) {
const j = i - 1;
if (j !== -1) {
word = `${words[j]} ${word}`;
}
}

if (sqlKeywords.includes(word.toUpperCase())) {
if (sqlKeywords.includes(word)) {
return word;
}
}
Expand All @@ -138,12 +138,13 @@ export const hvSqlCompletionProvider = (monaco: Monaco, schema?: string) => {
"DISTINCT",
"AND",
"OR",
"WHEN",
];

return {
provideCompletionItems: (model: any, position: any) => {
// If no text is typed, show a suggestion to select all columns from a table
if (model.getValue() === "") {
if (!model.getValue().trim()) {
const emptySuggestions = {
label: "SELECT * FROM",
kind: monaco.languages.CompletionItemKind.Snippet,
Expand All @@ -162,7 +163,7 @@ export const hvSqlCompletionProvider = (monaco: Monaco, schema?: string) => {
sortText: "1",
}));

const lastKeyword = getLastKeyword(model, position);
const lastKeyword = getLastKeyword(model, position).toUpperCase();

if (lastKeyword === "FROM" || lastKeyword.includes("JOIN")) {
const tableSuggestions = tablesNames.map((tableName) => ({
Expand Down
Loading