-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
171 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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
54 changes: 54 additions & 0 deletions
54
packages/web-console/src/scenes/Editor/Monaco/questdb-sql/getColumnCompletions.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { uniq } from "../../../../utils" | ||
import { CompletionItemPriority, InformationSchemaColumn } from "./types" | ||
import { IRange } from "monaco-editor" | ||
import { languages } from "monaco-editor" | ||
|
||
export const getColumnCompletions = ({ | ||
columns, | ||
range, | ||
withTableName, | ||
priority, | ||
}: { | ||
columns: InformationSchemaColumn[] | ||
range: IRange | ||
withTableName: boolean | ||
priority: CompletionItemPriority | ||
}) => { | ||
// For JOIN ON ... completions, return `table.column` text | ||
if (withTableName) { | ||
return columns.map((item) => ({ | ||
label: { | ||
label: `${item.table_name}.${item.column_name}`, | ||
detail: "", | ||
description: item.data_type, | ||
}, | ||
kind: languages.CompletionItemKind.Enum, | ||
insertText: `${item.table_name}.${item.column_name}`, | ||
sortText: priority, | ||
range, | ||
})) | ||
// For everything else, return a list of unique column names. | ||
} else { | ||
return uniq(columns.map((item) => item.column_name)).map((columnName) => { | ||
const tableNames = columns | ||
.filter((item) => item.column_name === columnName) | ||
.map((item) => item.table_name) | ||
return { | ||
label: { | ||
label: columnName, | ||
detail: ` (${tableNames.sort().join(", ")})`, | ||
// If the column is present in multiple tables, show their list here, otherwise return the column type. | ||
description: | ||
tableNames.length > 1 | ||
? "" | ||
: columns.find((item) => item.column_name === columnName) | ||
?.data_type, | ||
}, | ||
kind: languages.CompletionItemKind.Enum, | ||
insertText: columnName, | ||
sortText: priority, | ||
range, | ||
} | ||
}) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/web-console/src/scenes/Editor/Monaco/questdb-sql/getLanguageCompletions.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { IRange } from "monaco-editor" | ||
import { languages } from "monaco-editor" | ||
import { operators } from "./operators" | ||
import { dataTypes, functions, keywords } from "@questdb/sql-grammar" | ||
|
||
export const getLanguageCompletions = (range: IRange) => [ | ||
...functions.map((qdbFunction) => { | ||
return { | ||
label: qdbFunction, | ||
kind: languages.CompletionItemKind.Function, | ||
insertText: qdbFunction, | ||
range, | ||
} | ||
}), | ||
...dataTypes.map((item) => { | ||
return { | ||
label: item, | ||
kind: languages.CompletionItemKind.Keyword, | ||
insertText: item, | ||
range, | ||
} | ||
}), | ||
...keywords.map((item) => { | ||
const keyword = item.toUpperCase() | ||
return { | ||
label: keyword, | ||
kind: languages.CompletionItemKind.Keyword, | ||
insertText: keyword, | ||
range, | ||
} | ||
}), | ||
...operators.map((item) => { | ||
const operator = item.toUpperCase() | ||
return { | ||
label: operator, | ||
kind: languages.CompletionItemKind.Operator, | ||
insertText: operator.toUpperCase(), | ||
range, | ||
} | ||
}), | ||
] |
32 changes: 32 additions & 0 deletions
32
packages/web-console/src/scenes/Editor/Monaco/questdb-sql/getTableCompletions.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Table } from "../../../../utils" | ||
import { CompletionItemPriority } from "./types" | ||
import { IRange } from "monaco-editor" | ||
import { languages } from "monaco-editor" | ||
|
||
export const getTableCompletions = ({ | ||
tables, | ||
range, | ||
priority, | ||
openQuote, | ||
nextCharQuote, | ||
}: { | ||
tables: Table[] | ||
range: IRange | ||
priority: CompletionItemPriority | ||
openQuote: boolean | ||
nextCharQuote: boolean | ||
}) => { | ||
return tables.map((item) => { | ||
return { | ||
label: item.table_name, | ||
kind: languages.CompletionItemKind.Class, | ||
insertText: openQuote | ||
? item.table_name + (nextCharQuote ? "" : '"') | ||
: /^[a-z0-9_]+$/i.test(item.table_name) | ||
? item.table_name | ||
: `"${item.table_name}"`, | ||
sortText: priority, | ||
range, | ||
} | ||
}) | ||
} |
This file contains 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