monaco-yql-languages 2.2.0 → 2.2.1

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.
@@ -0,0 +1,79 @@
1
+ import { YQLAutocomplete } from '../yqlAutocomplete';
2
+ jest.mock('../../../fillers/monaco-editor-core', () => ({
3
+ languages: {
4
+ CompletionItemKind: {
5
+ Property: 1,
6
+ },
7
+ },
8
+ }));
9
+ function extractCursor(inputWithCursor) {
10
+ const offset = inputWithCursor.indexOf('|');
11
+ if (offset === -1) {
12
+ throw new Error('Input must contain cursor marker');
13
+ }
14
+ return {
15
+ input: inputWithCursor.replace('|', ''),
16
+ offset,
17
+ };
18
+ }
19
+ function createEmptyRange(column) {
20
+ return {
21
+ startLineNumber: 1,
22
+ startColumn: column,
23
+ endLineNumber: 1,
24
+ endColumn: column,
25
+ };
26
+ }
27
+ describe('YQLAutocomplete settings suggestions range', () => {
28
+ it('should return encoding suggestions with empty range inside autoclosed parentheses', async () => {
29
+ const parseQuery = jest.fn(async () => ({ suggestEncodingSettings: true }));
30
+ const getEncodingSettings = jest.fn(async () => ['AUTO', 'DICT', 'PLAIN']);
31
+ const autocomplete = new YQLAutocomplete({
32
+ getQueryParser: async () => parseQuery,
33
+ getEncodingSettings,
34
+ });
35
+ const { input, offset } = extractCursor('ALTER TABLE test_table ALTER COLUMN id SET ENCODING(|)');
36
+ const suggestions = await autocomplete.getSuggestions(input, offset);
37
+ const expectedRange = createEmptyRange(offset + 1);
38
+ expect(getEncodingSettings).toHaveBeenCalledWith('');
39
+ expect(suggestions).toEqual([
40
+ expect.objectContaining({ label: 'AUTO', range: expectedRange }),
41
+ expect.objectContaining({ label: 'DICT', range: expectedRange }),
42
+ expect.objectContaining({ label: 'PLAIN', range: expectedRange }),
43
+ ]);
44
+ });
45
+ it('should return encoding suggestions after whitespace inside autoclosed parentheses', async () => {
46
+ const parseQuery = jest.fn(async () => ({ suggestEncodingSettings: true }));
47
+ const getEncodingSettings = jest.fn(async () => ['AUTO', 'DICT', 'PLAIN']);
48
+ const autocomplete = new YQLAutocomplete({
49
+ getQueryParser: async () => parseQuery,
50
+ getEncodingSettings,
51
+ });
52
+ const { input, offset } = extractCursor('ALTER TABLE test_table ALTER COLUMN id SET ENCODING( |)');
53
+ const suggestions = await autocomplete.getSuggestions(input, offset);
54
+ const expectedRange = createEmptyRange(offset + 1);
55
+ expect(getEncodingSettings).toHaveBeenCalledWith('');
56
+ expect(suggestions).toEqual([
57
+ expect.objectContaining({ label: 'AUTO', range: expectedRange }),
58
+ expect.objectContaining({ label: 'DICT', range: expectedRange }),
59
+ expect.objectContaining({ label: 'PLAIN', range: expectedRange }),
60
+ ]);
61
+ });
62
+ it('should return compression suggestions with empty range inside autoclosed parentheses', async () => {
63
+ const parseQuery = jest.fn(async () => ({ suggestCompressionSettings: true }));
64
+ const getCompressionSettings = jest.fn(async () => ['AUTO', 'LZ4', 'ZSTD']);
65
+ const autocomplete = new YQLAutocomplete({
66
+ getQueryParser: async () => parseQuery,
67
+ getCompressionSettings,
68
+ });
69
+ const { input, offset } = extractCursor('ALTER TABLE test_table ALTER COLUMN id SET COMPRESSION(|)');
70
+ const suggestions = await autocomplete.getSuggestions(input, offset);
71
+ const expectedRange = createEmptyRange(offset + 1);
72
+ expect(getCompressionSettings).toHaveBeenCalledWith('');
73
+ expect(suggestions).toEqual([
74
+ expect.objectContaining({ label: 'AUTO', range: expectedRange }),
75
+ expect.objectContaining({ label: 'LZ4', range: expectedRange }),
76
+ expect.objectContaining({ label: 'ZSTD', range: expectedRange }),
77
+ ]);
78
+ });
79
+ });
@@ -8,7 +8,7 @@ function getCursorPosition(input, offset) {
8
8
  column: lines[lines.length - 1].length + 1,
9
9
  };
10
10
  }
11
- const prefixRegexp = /([^\s]+)$/;
11
+ const prefixRegexp = /([^\s()]+)$/;
12
12
  function getCursorPrefix(input, offset, re = prefixRegexp) {
13
13
  const prevText = input.slice(0, offset);
14
14
  const match = prevText.match(re);
@@ -17,7 +17,7 @@ function getCursorPrefix(input, offset, re = prefixRegexp) {
17
17
  }
18
18
  return '';
19
19
  }
20
- const prefixToReplaceRegexp = /([^\\/\s`]+)$/;
20
+ const prefixToReplaceRegexp = /([^\\/\s`()]+)$/;
21
21
  function getRangeToInsertSuggestion(input, offset) {
22
22
  const cursorPosition = getCursorPosition(input, offset);
23
23
  const cursorPrefix = getCursorPrefix(input, offset, prefixToReplaceRegexp);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monaco-yql-languages",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "YQL languages for the Monaco Editor, based on monaco-languages.",
5
5
  "author": "YDB",
6
6
  "license": "MIT",