3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { monaco } from '@osd/monaco' ;
7
- import {
8
- ColumnValuePredicate ,
9
- CursorPosition ,
10
- OpenSearchSqlAutocompleteResult ,
11
- } from '../shared/types' ;
6
+ import { CursorPosition , OpenSearchSqlAutocompleteResult } from '../shared/types' ;
12
7
import { openSearchSqlAutocompleteData } from './opensearch_sql_autocomplete' ;
13
- import { SQL_SUGGESTION_IMPORTANCE , SQL_SYMBOLS } from './constants' ;
14
8
import { QuerySuggestion , QuerySuggestionGetFnArgs } from '../../autocomplete' ;
15
- import {
16
- fetchColumnValues ,
17
- formatFieldsToSuggestions ,
18
- formatValuesToSuggestions ,
19
- parseQuery ,
20
- } from '../shared/utils' ;
21
- import { SuggestionItemDetailsTags } from '../shared/constants' ;
22
-
23
- export interface SuggestionParams {
24
- position : monaco . Position ;
25
- query : string ;
26
- }
27
-
28
- export interface ISuggestionItem {
29
- text : string ;
30
- type : string ;
31
- fieldType ?: string ;
32
- }
9
+ import { parseQuery } from '../shared/utils' ;
33
10
11
+ /**
12
+ * @deprecated SQL suggestion provider has been moved to the query_enhancements plugin.
13
+ * This function is kept for backward compatibility and will be removed in a future release.
14
+ */
34
15
export const getSuggestions = async ( {
35
16
selectionStart,
36
17
selectionEnd,
@@ -40,129 +21,14 @@ export const getSuggestions = async ({
40
21
query,
41
22
services,
42
23
} : QuerySuggestionGetFnArgs ) : Promise < QuerySuggestion [ ] > => {
43
- if ( ! services || ! services . appName || ! indexPattern ) return [ ] ;
44
- try {
45
- const { lineNumber, column } = position || { } ;
46
- const suggestions = getOpenSearchSqlAutoCompleteSuggestions ( query , {
47
- line : lineNumber || selectionStart ,
48
- column : column || selectionEnd ,
49
- } ) ;
50
-
51
- const finalSuggestions : QuerySuggestion [ ] = [ ] ;
52
-
53
- // Fetch columns and values
54
- if ( suggestions . suggestColumns ?. tables ?. length ) {
55
- finalSuggestions . push ( ...formatFieldsToSuggestions ( indexPattern , ( f : any ) => `${ f } ` , '2' ) ) ;
56
- }
57
-
58
- if ( suggestions . suggestColumnValuePredicate ) {
59
- switch ( suggestions . suggestColumnValuePredicate ) {
60
- case ColumnValuePredicate . COLUMN : {
61
- finalSuggestions . push (
62
- ...formatFieldsToSuggestions ( indexPattern , ( f : any ) => `${ f } ` , '2' )
63
- ) ;
64
- break ;
65
- }
66
- case ColumnValuePredicate . OPERATOR : {
67
- finalSuggestions . push ( {
68
- text : '=' ,
69
- insertText : '= ' ,
70
- type : monaco . languages . CompletionItemKind . Operator ,
71
- detail : SuggestionItemDetailsTags . Operator ,
72
- sortText : '0' ,
73
- } ) ;
74
- break ;
75
- }
76
- case ColumnValuePredicate . LPAREN : {
77
- finalSuggestions . push ( {
78
- text : '(' ,
79
- insertText : '( ' ,
80
- type : monaco . languages . CompletionItemKind . Keyword ,
81
- detail : SuggestionItemDetailsTags . Keyword ,
82
- sortText : '0' ,
83
- } ) ;
84
- break ;
85
- }
86
- case ColumnValuePredicate . END_IN_TERM : {
87
- finalSuggestions . push ( {
88
- text : ',' ,
89
- insertText : ', ' ,
90
- type : monaco . languages . CompletionItemKind . Keyword ,
91
- detail : SuggestionItemDetailsTags . Keyword ,
92
- sortText : '0' ,
93
- } ) ;
94
- finalSuggestions . push ( {
95
- text : ')' ,
96
- insertText : ') ' ,
97
- type : monaco . languages . CompletionItemKind . Keyword ,
98
- detail : SuggestionItemDetailsTags . Keyword ,
99
- sortText : '08' ,
100
- } ) ;
101
- break ;
102
- }
103
- case ColumnValuePredicate . VALUE : {
104
- if ( suggestions . suggestValuesForColumn ) {
105
- finalSuggestions . push (
106
- ...formatValuesToSuggestions (
107
- await fetchColumnValues (
108
- indexPattern . title ,
109
- suggestions . suggestValuesForColumn ,
110
- services ,
111
- indexPattern . fields . find (
112
- ( field ) => field . name === suggestions . suggestValuesForColumn
113
- ) ,
114
- datasetType
115
- ) . catch ( ( ) => [ ] ) ,
116
- ( val : any ) => ( typeof val === 'string' ? `'${ val } ' ` : `${ val } ` )
117
- )
118
- ) ;
119
- }
120
- break ;
121
- }
122
- }
123
- }
124
-
125
- // Fill in aggregate functions
126
- if ( suggestions . suggestAggregateFunctions ) {
127
- finalSuggestions . push (
128
- ...SQL_SYMBOLS . AGREGATE_FUNCTIONS . map ( ( af ) => ( {
129
- text : af ,
130
- type : monaco . languages . CompletionItemKind . Function ,
131
- insertText : `${ af } ` ,
132
- detail : SuggestionItemDetailsTags . AggregateFunction ,
133
- } ) )
134
- ) ;
135
- }
136
-
137
- if ( suggestions . suggestViewsOrTables ) {
138
- finalSuggestions . push ( {
139
- text : indexPattern . title ,
140
- type : monaco . languages . CompletionItemKind . Struct ,
141
- insertText : `${ indexPattern . title } ` ,
142
- detail : SuggestionItemDetailsTags . Table ,
143
- } ) ;
144
- }
145
-
146
- // Fill in SQL keywords
147
- if ( suggestions . suggestKeywords ?. length ) {
148
- finalSuggestions . push (
149
- ...suggestions . suggestKeywords . map ( ( sk ) => ( {
150
- text : sk . value ,
151
- type : monaco . languages . CompletionItemKind . Keyword ,
152
- insertText : `${ sk . value } ` ,
153
- detail : SuggestionItemDetailsTags . Keyword ,
154
- sortText : SQL_SUGGESTION_IMPORTANCE . get ( sk . id ) ?? '9' + sk . value . toLowerCase ( ) ,
155
- } ) )
156
- ) ;
157
- }
158
-
159
- return finalSuggestions ;
160
- } catch ( error ) {
161
- // TODO: Handle errors appropriately, possibly logging or displaying a message to the user
162
- return [ ] ;
163
- }
24
+ // Return empty array - the actual implementation has been moved to query_enhancements plugin
25
+ return [ ] ;
164
26
} ;
165
27
28
+ /**
29
+ * Helper function to get SQL autocomplete suggestions
30
+ * This is still exported for use by the query_enhancements plugin
31
+ */
166
32
export const getOpenSearchSqlAutoCompleteSuggestions = (
167
33
query : string ,
168
34
cursor : CursorPosition
0 commit comments