Skip to content

Commit afea07c

Browse files
feat: add support for 'select_complete' context in SQL intellisense
1 parent fd5ec87 commit afea07c

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/renderer/lib/intellisense/IntellisenseProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export abstract class IntellisenseProvider {
6969
suggestions.push(...this.getColumnSuggestions(context, schema, position, range))
7070
suggestions.push(...this.getFunctionSuggestions(context, schema, position, range))
7171
break
72+
case 'select_complete':
73+
suggestions.push(...this.getKeywordSuggestions(context, schema, position, range))
74+
suggestions.push(...this.getColumnSuggestions(context, schema, position, range))
75+
suggestions.push(...this.getFunctionSuggestions(context, schema, position, range))
76+
break
7277
case 'function':
7378
suggestions.push(...this.getFunctionSuggestions(context, schema, position, range))
7479
break

src/renderer/lib/intellisense/parsers/SQLContextParser.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ export class SQLContextParser {
9494

9595
switch (lastKeywordMatch.type) {
9696
case 'select':
97-
context.type = hasContent ? 'column' : 'select'
97+
if (hasContent) {
98+
// Check if we're at the end of the SELECT clause and should suggest keywords
99+
const endsWithSpace = textBefore.endsWith(' ')
100+
const hasFrom = this.hasFromClause(lowerText)
101+
const shouldSuggestKeywords = endsWithSpace && !hasFrom
102+
103+
context.type = shouldSuggestKeywords ? 'select_complete' : 'column'
104+
} else {
105+
context.type = 'select'
106+
}
98107
context.currentClause = 'SELECT'
99108
break
100109

@@ -136,6 +145,10 @@ export class SQLContextParser {
136145
}
137146
}
138147

148+
private hasFromClause(text: string): boolean {
149+
return this.keywordPatterns.from.test(text)
150+
}
151+
139152
private findLastKeyword(text: string): { type: string; keyword: string; index: number } | null {
140153
let lastMatch: { type: string; keyword: string; index: number } | null = null
141154
let lastIndex = -1

src/renderer/lib/intellisense/types.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ export interface Position {
2222
}
2323

2424
export interface SQLContext {
25-
type: 'select' | 'from' | 'where' | 'join' | 'column' | 'function' | 'keyword' | 'unknown'
25+
type:
26+
| 'select'
27+
| 'from'
28+
| 'where'
29+
| 'join'
30+
| 'column'
31+
| 'function'
32+
| 'keyword'
33+
| 'unknown'
34+
| 'select_complete'
2635
currentClause?: string
2736
tableAliases: Map<string, string>
2837
availableTables: string[]

0 commit comments

Comments
 (0)