monaco-yql-languages 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/completion.d.ts +1 -1
- package/build/completion.js +8 -2
- package/build/utils.d.ts +1 -0
- package/build/utils.js +11 -0
- package/build/yql/autocomplete/__tests__/generateSuggestions.test.js +17 -17
- package/build/yql/autocomplete/__tests__/utils.test.js +2 -1
- package/build/yql/autocomplete/generateSuggestions.js +2 -1
- package/build/yql/autocomplete/utils.d.ts +0 -1
- package/build/yql/autocomplete/utils.js +0 -11
- package/package.json +1 -1
package/build/completion.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { CancellationToken, Position, editor, languages } from './fillers/m
|
|
|
2
2
|
export type CompletionListProvider = {
|
|
3
3
|
(content: string, offset: number, signal?: AbortSignal | null): Promise<string[]>;
|
|
4
4
|
};
|
|
5
|
-
export declare function provideCompletionItems(getCompletionList: CompletionListProvider): (model: editor.ITextModel, position: Position, context: languages.CompletionContext, token: CancellationToken) => languages.ProviderResult<languages.CompletionList>;
|
|
5
|
+
export declare function provideCompletionItems(getCompletionList: CompletionListProvider, preserveOrder?: boolean): (model: editor.ITextModel, position: Position, context: languages.CompletionContext, token: CancellationToken) => languages.ProviderResult<languages.CompletionList>;
|
|
6
6
|
export type CompletionLists = Partial<Record<`${Uncapitalize<keyof typeof languages.CompletionItemKind>}List`, Readonly<string[]>>>;
|
|
7
7
|
export declare function getCompletionItemsProvider(completions: CompletionLists, completionItemKind: typeof languages.CompletionItemKind): {
|
|
8
8
|
provideCompletionItems(model: editor.ITextModel, position: Position, _context: languages.CompletionContext, _token: CancellationToken): languages.CompletionList | undefined;
|
package/build/completion.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { suggestionIndexToWeight } from './utils';
|
|
1
2
|
const allUpperCaseRe = new RegExp('^[$A-Z_\\s]+$');
|
|
2
|
-
export function provideCompletionItems(getCompletionList) {
|
|
3
|
+
export function provideCompletionItems(getCompletionList, preserveOrder) {
|
|
3
4
|
return (model, position, context, token) => {
|
|
4
5
|
const controller = new AbortController();
|
|
5
6
|
const signal = controller.signal;
|
|
@@ -49,7 +50,12 @@ export function provideCompletionItems(getCompletionList) {
|
|
|
49
50
|
range,
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
|
-
return {
|
|
53
|
+
return {
|
|
54
|
+
suggestions: preserveOrder
|
|
55
|
+
? suggestions.map((item, index) => (Object.assign(Object.assign({}, item), { sortText: suggestionIndexToWeight(index) })))
|
|
56
|
+
: suggestions,
|
|
57
|
+
incomplete: suggestions.length > 0,
|
|
58
|
+
};
|
|
53
59
|
});
|
|
54
60
|
};
|
|
55
61
|
}
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function suggestionIndexToWeight(index: number): string;
|
package/build/utils.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
|
|
2
|
+
export function suggestionIndexToWeight(index) {
|
|
3
|
+
const characterInsideAlphabet = alphabet[index];
|
|
4
|
+
if (characterInsideAlphabet) {
|
|
5
|
+
return characterInsideAlphabet;
|
|
6
|
+
}
|
|
7
|
+
const duplicateTimes = Math.floor(index / alphabet.length);
|
|
8
|
+
const remains = index % alphabet.length;
|
|
9
|
+
const lastCharacter = alphabet.slice(-1);
|
|
10
|
+
return lastCharacter.repeat(duplicateTimes) + alphabet[remains];
|
|
11
|
+
}
|
|
@@ -46,7 +46,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
46
46
|
kind: 1,
|
|
47
47
|
detail: 'Column',
|
|
48
48
|
range: mockRange,
|
|
49
|
-
sortText: '
|
|
49
|
+
sortText: 'aa',
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
label: { label: 'col2', description: undefined },
|
|
@@ -54,7 +54,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
54
54
|
kind: 1,
|
|
55
55
|
detail: 'Column',
|
|
56
56
|
range: mockRange,
|
|
57
|
-
sortText: '
|
|
57
|
+
sortText: 'ab',
|
|
58
58
|
},
|
|
59
59
|
]);
|
|
60
60
|
});
|
|
@@ -72,7 +72,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
72
72
|
kind: 1,
|
|
73
73
|
detail: 'Column',
|
|
74
74
|
range: mockRange,
|
|
75
|
-
sortText: '
|
|
75
|
+
sortText: 'aa',
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
label: { label: 'table2.col2', description: undefined },
|
|
@@ -80,7 +80,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
80
80
|
kind: 1,
|
|
81
81
|
detail: 'Column',
|
|
82
82
|
range: mockRange,
|
|
83
|
-
sortText: '
|
|
83
|
+
sortText: 'ab',
|
|
84
84
|
},
|
|
85
85
|
]);
|
|
86
86
|
});
|
|
@@ -95,7 +95,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
95
95
|
kind: 1,
|
|
96
96
|
detail: 'Column',
|
|
97
97
|
range: mockRange,
|
|
98
|
-
sortText: '
|
|
98
|
+
sortText: 'aa',
|
|
99
99
|
},
|
|
100
100
|
]);
|
|
101
101
|
});
|
|
@@ -111,7 +111,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
111
111
|
kind: 1,
|
|
112
112
|
detail: 'Column',
|
|
113
113
|
range: mockRange,
|
|
114
|
-
sortText: '
|
|
114
|
+
sortText: 'aa',
|
|
115
115
|
},
|
|
116
116
|
]);
|
|
117
117
|
});
|
|
@@ -130,7 +130,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
130
130
|
kind: 1,
|
|
131
131
|
detail: 'Column',
|
|
132
132
|
range: mockRange,
|
|
133
|
-
sortText: '
|
|
133
|
+
sortText: 'aa',
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
label: { label: 'table2.col2', description: undefined },
|
|
@@ -138,14 +138,14 @@ describe('generateColumnsSuggestion', () => {
|
|
|
138
138
|
kind: 1,
|
|
139
139
|
detail: 'Column',
|
|
140
140
|
range: mockRange,
|
|
141
|
-
sortText: '
|
|
141
|
+
sortText: 'ab',
|
|
142
142
|
},
|
|
143
143
|
{
|
|
144
144
|
label: 'table1.col1, table2.col2',
|
|
145
145
|
insertText: 'table1.col1, table2.col2',
|
|
146
146
|
kind: 1,
|
|
147
147
|
range: mockRange,
|
|
148
|
-
sortText: '
|
|
148
|
+
sortText: 'a',
|
|
149
149
|
},
|
|
150
150
|
]);
|
|
151
151
|
});
|
|
@@ -163,7 +163,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
163
163
|
kind: 1,
|
|
164
164
|
detail: 'Column',
|
|
165
165
|
range: mockRange,
|
|
166
|
-
sortText: '
|
|
166
|
+
sortText: 'aa',
|
|
167
167
|
},
|
|
168
168
|
{
|
|
169
169
|
label: { label: 'col1', description: undefined },
|
|
@@ -171,7 +171,7 @@ describe('generateColumnsSuggestion', () => {
|
|
|
171
171
|
kind: 1,
|
|
172
172
|
detail: 'Column',
|
|
173
173
|
range: mockRange,
|
|
174
|
-
sortText: '
|
|
174
|
+
sortText: 'ab',
|
|
175
175
|
},
|
|
176
176
|
]);
|
|
177
177
|
});
|
|
@@ -207,7 +207,7 @@ describe('generateEntitiesSuggestion', () => {
|
|
|
207
207
|
endColumn: 1,
|
|
208
208
|
},
|
|
209
209
|
command: undefined,
|
|
210
|
-
sortText: '
|
|
210
|
+
sortText: 'aa',
|
|
211
211
|
},
|
|
212
212
|
{
|
|
213
213
|
label: 'entity2/',
|
|
@@ -222,7 +222,7 @@ describe('generateEntitiesSuggestion', () => {
|
|
|
222
222
|
endColumn: 1,
|
|
223
223
|
},
|
|
224
224
|
command: { id: 'editor.action.triggerSuggest', title: '' },
|
|
225
|
-
sortText: '
|
|
225
|
+
sortText: 'ab',
|
|
226
226
|
},
|
|
227
227
|
]);
|
|
228
228
|
});
|
|
@@ -246,7 +246,7 @@ describe('generateEntitiesSuggestion', () => {
|
|
|
246
246
|
endColumn: 1,
|
|
247
247
|
},
|
|
248
248
|
command: undefined,
|
|
249
|
-
sortText: '
|
|
249
|
+
sortText: 'aa',
|
|
250
250
|
},
|
|
251
251
|
{
|
|
252
252
|
label: 'entity2/',
|
|
@@ -261,7 +261,7 @@ describe('generateEntitiesSuggestion', () => {
|
|
|
261
261
|
endColumn: 1,
|
|
262
262
|
},
|
|
263
263
|
command: { id: 'editor.action.triggerSuggest', title: '' },
|
|
264
|
-
sortText: '
|
|
264
|
+
sortText: 'ab',
|
|
265
265
|
},
|
|
266
266
|
]);
|
|
267
267
|
});
|
|
@@ -285,7 +285,7 @@ describe('generateEntitiesSuggestion', () => {
|
|
|
285
285
|
endColumn: 1,
|
|
286
286
|
},
|
|
287
287
|
command: { id: 'editor.action.triggerSuggest', title: '' },
|
|
288
|
-
sortText: '
|
|
288
|
+
sortText: 'aa',
|
|
289
289
|
},
|
|
290
290
|
{
|
|
291
291
|
label: 'entity2',
|
|
@@ -300,7 +300,7 @@ describe('generateEntitiesSuggestion', () => {
|
|
|
300
300
|
endColumn: 1,
|
|
301
301
|
},
|
|
302
302
|
command: undefined,
|
|
303
|
-
sortText: '
|
|
303
|
+
sortText: 'ab',
|
|
304
304
|
},
|
|
305
305
|
]);
|
|
306
306
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { suggestionIndexToWeight
|
|
1
|
+
import { suggestionIndexToWeight } from '../../../utils';
|
|
2
|
+
import { wrapStringToBackticks } from '../utils';
|
|
2
3
|
describe('wrapStringToBackticks', () => {
|
|
3
4
|
it('should return the same string if it already starts and ends with backticks', () => {
|
|
4
5
|
expect(wrapStringToBackticks('`test`')).toBe('`test`');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as monaco from '../../fillers/monaco-editor-core';
|
|
2
|
-
import { getSuggestionIndex, isVariable, removeBackticks, removeStringDuplicates,
|
|
2
|
+
import { getSuggestionIndex, isVariable, removeBackticks, removeStringDuplicates, wrapStringToBackticks, } from './utils';
|
|
3
|
+
import { suggestionIndexToWeight } from '../../utils';
|
|
3
4
|
export async function generateSimpleTypesSuggestion(rangeToInsertSuggestion, simpleTypes = []) {
|
|
4
5
|
return simpleTypes.map((el) => ({
|
|
5
6
|
label: el,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { YqlAutocompleteResult } from '@gravity-ui/websql-autocomplete/yql';
|
|
2
2
|
type SuggestionType = keyof Omit<YqlAutocompleteResult, 'errors' | 'suggestDatabases'> | 'suggestAllColumns';
|
|
3
3
|
export declare function getSuggestionIndex(suggestionType: SuggestionType): number;
|
|
4
|
-
export declare function suggestionIndexToWeight(index: number): string;
|
|
5
4
|
export declare function isVariable(value: string): boolean;
|
|
6
5
|
export declare function removeStringDuplicates(value?: string[]): string[];
|
|
7
6
|
export declare function getEntitiesToFetchColumns(suggestColumns: YqlAutocompleteResult['suggestColumns']): string[];
|
|
@@ -20,17 +20,6 @@ const SuggestionsWeight = {
|
|
|
20
20
|
export function getSuggestionIndex(suggestionType) {
|
|
21
21
|
return SuggestionsWeight[suggestionType];
|
|
22
22
|
}
|
|
23
|
-
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
|
|
24
|
-
export function suggestionIndexToWeight(index) {
|
|
25
|
-
const characterInsideAlphabet = alphabet[index];
|
|
26
|
-
if (characterInsideAlphabet) {
|
|
27
|
-
return characterInsideAlphabet;
|
|
28
|
-
}
|
|
29
|
-
const duplicateTimes = Math.floor(index / alphabet.length);
|
|
30
|
-
const remains = index % alphabet.length;
|
|
31
|
-
const lastCharacter = alphabet.slice(-1);
|
|
32
|
-
return lastCharacter.repeat(duplicateTimes) + alphabet[remains];
|
|
33
|
-
}
|
|
34
23
|
export function isVariable(value) {
|
|
35
24
|
return value.startsWith('$');
|
|
36
25
|
}
|