Skip to content

Commit 79eb909

Browse files
authored
Merge pull request #46 from questdb/fix-autocomplete-newlines
Fix triggering autocomplete on newlines
2 parents d960dff + d6f9ba0 commit 79eb909

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/components/questdb-sql/createSchemaCompletionProvider.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,23 @@ export const createSchemaCompletionProvider = (
8484
const openQuote = textUntilPosition.substr(-1) === '"'
8585
const nextCharQuote = nextChar === '"'
8686

87+
// get text value in the current line
88+
const textInLine = model.getValueInRange({
89+
startLineNumber: position.lineNumber,
90+
startColumn: 1,
91+
endLineNumber: position.lineNumber,
92+
endColumn: position.column,
93+
})
94+
// check if `textInLine` contains whitespaces only
95+
const isWhitespaceOnly = /^\s*$/.test(textInLine)
96+
8797
if (
88-
/(FROM|INTO|(ALTER|BACKUP|DROP|REINDEX|RENAME|TRUNCATE|VACUUM) TABLE|JOIN|UPDATE)\s$/gim.test(
89-
textUntilPosition,
90-
) ||
91-
(/'$/gim.test(textUntilPosition) &&
92-
!textUntilPosition.endsWith("= '"))
98+
(/(FROM|INTO|(ALTER|BACKUP|DROP|REINDEX|RENAME|TRUNCATE|VACUUM) TABLE|JOIN|UPDATE)\s$/gim.test(
99+
textUntilPosition,
100+
) ||
101+
(/'$/gim.test(textUntilPosition) &&
102+
!textUntilPosition.endsWith("= '"))) &&
103+
!isWhitespaceOnly
93104
) {
94105
return {
95106
suggestions: getTableCompletions({
@@ -102,16 +113,6 @@ export const createSchemaCompletionProvider = (
102113
}
103114
}
104115

105-
// get text value in the current line
106-
const textInLine = model.getValueInRange({
107-
startLineNumber: position.lineNumber,
108-
startColumn: 1,
109-
endLineNumber: position.lineNumber,
110-
endColumn: position.column,
111-
})
112-
// check if `textInLine` contains whitespaces only
113-
const isWhitespaceOnly = /^\s*$/.test(textInLine)
114-
115116
if (
116117
/(?:(SELECT|UPDATE).*?(?:(?:,(?:COLUMN )?)|(?:ALTER COLUMN ))?(?:WHERE )?(?: BY )?(?: ON )?(?: SET )?$|ALTER COLUMN )/gim.test(
117118
textUntilPosition,

0 commit comments

Comments
 (0)