Skip to content

Commit 61b847a

Browse files
authored
Merge pull request #3431 from RedisInsight/fe/feature/RI-5770_Enchance_autocomplite_sqlite
#RI-5770 - Enhance auto-completion
2 parents c8503b5 + 0d542bc commit 61b847a

File tree

32 files changed

+537
-171
lines changed

32 files changed

+537
-171
lines changed

jest.config.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module.exports = {
1212
'uiSrc/(.*)': '<rootDir>/redisinsight/ui/src/$1',
1313
'monaco-editor': '<rootDir>/redisinsight/__mocks__/monacoMock.js',
1414
'monaco-yaml': '<rootDir>/redisinsight/__mocks__/monacoYamlMock.js',
15-
'monaco-sql-languages': '<rootDir>/redisinsight/__mocks__/monacoMock.js',
1615
unified: '<rootDir>/redisinsight/__mocks__/unified.js',
1716
'remark-parse': '<rootDir>/redisinsight/__mocks__/remarkParse.js',
1817
'remark-gfm': '<rootDir>/redisinsight/__mocks__/remarkGfm.js',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@
244244
"lodash": "^4.17.21",
245245
"lz4js": "^0.2.0",
246246
"monaco-editor": "^0.48.0",
247-
"monaco-sql-languages": "^0.12.0",
248247
"monaco-yaml": "^5.1.1",
249248
"msgpackr": "^1.10.1",
250249
"pako": "^2.1.0",

redisinsight/ui/src/components/MonacoEnvironmentInitializer/MonacoEnvironmentInitializer.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { useEffect } from 'react'
2-
import { LanguageIdEnum } from 'monaco-sql-languages'
32

4-
import 'monaco-sql-languages/esm/languages/mysql/mysql.contribution'
53
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
64
import JSONWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
75
import TypeScriptWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
8-
import MySQLWorker from 'monaco-sql-languages/esm/languages/mysql/mysql.worker?worker'
96
// https://github.com/remcohaszing/monaco-yaml?tab=readme-ov-file#why-doesnt-it-work-with-vite
107
import YamlWorker from './yaml.worker?worker'
118

@@ -23,8 +20,6 @@ const MonacoEnvironmentInitializer = () => {
2320
case 'javascript':
2421
case 'typescript':
2522
return new TypeScriptWorker()
26-
case LanguageIdEnum.MYSQL:
27-
return new MySQLWorker()
2823
default:
2924
throw new Error(`MonacoWorker: Unknown label ${label}`)
3025
}

redisinsight/ui/src/components/monaco-editor/components/dedicated-editor/DedicatedEditor.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ describe('DedicatedEditor', () => {
2828
expect(render(<DedicatedEditor {...instance(mockedProps)} />)).toBeTruthy()
2929
})
3030
it('should not render select languages if langs.length < 2', () => {
31-
const { queryByTestId } = render(<DedicatedEditor {...instance(mockedProps)} langs={[DSL.sql]} />)
31+
const { queryByTestId } = render(<DedicatedEditor {...instance(mockedProps)} langs={[DSL.sqliteFunctions]} />)
3232

3333
expect(queryByTestId(SELECT_LANGUAGES_TEST_ID!)).not.toBeInTheDocument()
3434
})
3535
it('should render select languages if langs.length >= 2', () => {
36-
const { queryByTestId } = render(<DedicatedEditor {...instance(mockedProps)} langs={[DSL.sql, DSL.jmespath]} />)
36+
const { queryByTestId } = render(<DedicatedEditor {...instance(mockedProps)} langs={[DSL.sqliteFunctions, DSL.jmespath]} />)
3737

3838
expect(queryByTestId(SELECT_LANGUAGES_TEST_ID!)).toBeInTheDocument()
3939
})

redisinsight/ui/src/constants/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export enum CommandRSSearchArgument {
118118
export enum DSL {
119119
cypher = 'cypher',
120120
lua = 'lua',
121-
sql = 'sql',
121+
sqliteFunctions = 'sqliteFunctions',
122122
jmespath = 'jmespath',
123123
}
124124

@@ -129,6 +129,6 @@ export interface IDSLNaming {
129129
export const DSLNaming: IDSLNaming = {
130130
[DSL.cypher]: 'Cypher',
131131
[DSL.lua]: 'Lua',
132-
[DSL.sql]: 'SQL',
132+
[DSL.sqliteFunctions]: 'SQLite functions',
133133
[DSL.jmespath]: 'JMESPath',
134134
}

redisinsight/ui/src/constants/monaco/monaco.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { monaco as monacoEditor } from 'react-monaco-editor'
2-
import { LanguageIdEnum } from 'monaco-sql-languages'
32
import { getCompletionProvider } from 'uiSrc/utils/monaco/completionProvider'
43
import { getCypherMonarchTokensProvider } from 'uiSrc/utils/monaco/monarchTokens/cypherTokens'
54
import { getJmespathMonarchTokensProvider } from 'uiSrc/utils/monaco/monarchTokens/jmespathTokens'
5+
import { getSqliteFunctionsMonarchTokensProvider } from 'uiSrc/utils/monaco/monarchTokens/sqliteFunctionsTokens'
66
import {
77
cypherLanguageConfiguration,
88
KEYWORDS as cypherKeywords,
@@ -11,6 +11,7 @@ import {
1111
import {
1212
jmespathLanguageConfiguration,
1313
} from './jmespath'
14+
import { sqliteFunctionsLanguageConfiguration, SQLITE_FUNCTIONS } from './sqliteFunctions'
1415
import { DSL, DSLNaming } from '../commands'
1516

1617
export interface MonacoSyntaxLang {
@@ -36,7 +37,7 @@ export enum MonacoLanguage {
3637
Redis = 'redisLanguage',
3738
Cypher = 'cypherLanguage',
3839
JMESPath = 'jmespathLanguage',
39-
SQL = LanguageIdEnum?.MYSQL,
40+
SQLiteFunctions = 'sqliteFunctions',
4041
Text = 'text',
4142
}
4243

@@ -54,10 +55,18 @@ export const DEDICATED_EDITOR_LANGUAGES: MonacoSyntaxObject = {
5455
}),
5556
tokensProvider: getCypherMonarchTokensProvider,
5657
},
57-
[DSL.sql]: {
58-
name: DSLNaming[DSL.sql],
59-
id: DSL.sql,
60-
language: MonacoLanguage.SQL,
58+
[DSL.sqliteFunctions]: {
59+
name: DSLNaming[DSL.sqliteFunctions],
60+
id: DSL.sqliteFunctions,
61+
language: MonacoLanguage.SQLiteFunctions,
62+
config: sqliteFunctionsLanguageConfiguration,
63+
completionProvider: () => ({
64+
...getCompletionProvider([], SQLITE_FUNCTIONS)
65+
}),
66+
tokensProvider: () => (
67+
{ ...getSqliteFunctionsMonarchTokensProvider(
68+
SQLITE_FUNCTIONS.map(({ label }) => label.toString())
69+
) }),
6170
},
6271
[DSL.jmespath]: {
6372
name: DSLNaming[DSL.jmespath],
@@ -75,7 +84,7 @@ export const DEDICATED_EDITOR_LANGUAGES: MonacoSyntaxObject = {
7584
functions: monacoEditor.languages.CompletionItem[] = [],
7685
) => (
7786
{ ...getJmespathMonarchTokensProvider(
78-
functions.map(({ label }) => (label.toString()))
87+
functions.map(({ label }) => label.toString())
7988
) }),
8089
},
8190
}
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
export default {
2+
date: {
3+
summary: 'returns the date as text in this format: YYYY-MM-DD',
4+
arguments: [
5+
{
6+
name: 'time_value',
7+
type: 'number',
8+
display_text: 'optional time value',
9+
optional: false
10+
},
11+
{
12+
name: 'modifier',
13+
type: 'string',
14+
display_text: 'optional one or more modifiers',
15+
optional: true
16+
}
17+
]
18+
},
19+
time: {
20+
summary: 'returns the time as text in this format: HH:MM:SS',
21+
arguments: [
22+
{
23+
name: 'time_value',
24+
type: 'number',
25+
display_text: 'optional time value',
26+
optional: false
27+
},
28+
{
29+
name: 'modifier',
30+
type: 'string',
31+
display_text: 'optional one or more modifiers',
32+
optional: true
33+
}
34+
]
35+
},
36+
datetime: {
37+
summary: 'returns the date and time as text in this formats: YYYY-MM-DD HH:MM:SS',
38+
arguments: [
39+
{
40+
name: 'time_value',
41+
type: 'number',
42+
display_text: 'optional time value',
43+
optional: false
44+
},
45+
{
46+
name: 'modifier',
47+
type: 'string',
48+
display_text: 'optional one or more modifiers',
49+
optional: true
50+
}
51+
]
52+
},
53+
julianday: {
54+
summary: 'the fractional number of days since noon in Greenwich on November 24, 4714 B.C.',
55+
arguments: [
56+
{
57+
name: 'time_value',
58+
type: 'number',
59+
display_text: 'optional time value',
60+
optional: false
61+
},
62+
{
63+
name: 'modifier',
64+
type: 'string',
65+
display_text: 'optional one or more modifiers',
66+
optional: true
67+
}
68+
]
69+
},
70+
unixepoch: {
71+
summary: 'returns a unix timestamp - the number of seconds since 1970-01-01 00:00:00 UTC.',
72+
arguments: [
73+
{
74+
name: 'time_value',
75+
type: 'number',
76+
display_text: 'optional time value',
77+
optional: false
78+
},
79+
{
80+
name: 'modifier',
81+
type: 'string',
82+
display_text: 'optional one or more modifiers',
83+
optional: true
84+
}
85+
]
86+
},
87+
strftime: {
88+
summary: 'returns the date formatted according to the format string specified as the first argument. The format string supports the most common substitutions found in the strftime() function from the standard C library plus two new substitutions, %f and %J',
89+
arguments: [
90+
{
91+
name: 'format',
92+
type: 'string',
93+
display_text: 'supports the most common substitutions found in the strftime() function',
94+
optional: false
95+
},
96+
{
97+
name: 'time_value',
98+
type: 'number',
99+
display_text: 'optional time value',
100+
optional: false
101+
},
102+
{
103+
name: 'modifier',
104+
type: 'string',
105+
display_text: 'optional one or more modifiers',
106+
optional: true
107+
}
108+
]
109+
},
110+
timediff: {
111+
summary: 'returns a string that describes the amount of time that must be added to B in order to reach time A. The format of the timediff() result is designed to be human-readable. The format is:(+|-)YYYY-MM-DD HH:MM:SS.SSS',
112+
arguments: [
113+
{
114+
name: 'time_value',
115+
type: 'number',
116+
display_text: 'time to start from',
117+
optional: false
118+
},
119+
]
120+
},
121+
avg: {
122+
summary: 'returns the average value of all non-NULL X within a group. String and BLOB values that do not look like numbers are interpreted as 0.',
123+
arguments: [
124+
{
125+
name: 'column_name',
126+
type: 'string',
127+
display_text: 'column name',
128+
optional: false
129+
}
130+
]
131+
},
132+
count: {
133+
summary: 'returns a count of the number of times that X is not NULL in a group.',
134+
arguments: [
135+
{
136+
name: 'column_name',
137+
type: 'string',
138+
display_text: 'column name',
139+
optional: false
140+
}
141+
]
142+
},
143+
group_concat: {
144+
summary: "The group_concat() function returns a string which is the concatenation of all non-NULL values of X. If parameter Y is present then it is used as the separator between instances of X.A comma (',') is used as the separator if Y is omitted.",
145+
arguments: [
146+
{
147+
name: 'column_name',
148+
type: 'string',
149+
display_text: 'column name',
150+
optional: false
151+
},
152+
{
153+
name: 'separator',
154+
type: 'string',
155+
display_text: 'separator',
156+
optional: true
157+
}
158+
]
159+
},
160+
string_agg: {
161+
summary: "The group_concat() function returns a string which is the concatenation of all non-NULL values of X. If parameter Y is present then it is used as the separator between instances of X.A comma (',') is used as the separator if Y is omitted.",
162+
arguments: [
163+
{
164+
name: 'column_name',
165+
type: 'string',
166+
display_text: 'column name',
167+
optional: false
168+
},
169+
{
170+
name: 'separator',
171+
type: 'string',
172+
display_text: 'separator',
173+
optional: true
174+
}
175+
]
176+
},
177+
max: {
178+
summary: 'returns the maximum value of all values in the group',
179+
arguments: [
180+
{
181+
name: 'column_name',
182+
type: 'string',
183+
display_text: 'column name',
184+
optional: false
185+
}
186+
]
187+
},
188+
min: {
189+
summary: 'returns the minimum value of all values in the group',
190+
arguments: [
191+
{
192+
name: 'column_name',
193+
type: 'string',
194+
display_text: 'column name',
195+
optional: false
196+
}
197+
]
198+
},
199+
sum: {
200+
summary: 'return the sum of all non-NULL values in the group.',
201+
arguments: [
202+
{
203+
name: 'column_name',
204+
type: 'string',
205+
display_text: 'column name',
206+
optional: false
207+
}
208+
]
209+
},
210+
total: {
211+
summary: 'return the sum of all non-NULL values in the group.',
212+
arguments: [
213+
{
214+
name: 'column_name',
215+
type: 'string',
216+
display_text: 'column name',
217+
optional: false
218+
}
219+
]
220+
}
221+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './monacoSQLiteFunctions'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { monaco as monacoEditor } from 'react-monaco-editor'
2+
import sqliteFunctions from './functions'
3+
import { generateArgsNames, generateArgsForInsertText, getCommandMarkdown } from '../../../utils/commands'
4+
5+
export const sqliteFunctionsLanguageConfiguration: monacoEditor.languages.LanguageConfiguration = {
6+
brackets: [
7+
['(', ')'],
8+
['{', '}'],
9+
['[', ']'],
10+
["'", "'"],
11+
['"', '"']
12+
],
13+
}
14+
15+
const sqliteFunctionsParsed: monacoEditor.languages.CompletionItem[] = Object.entries(sqliteFunctions)
16+
.map(([labelInit, func]) => {
17+
const { arguments: args } = func
18+
const label = labelInit.toUpperCase()
19+
const range = { startLineNumber: 0, endLineNumber: 0, startColumn: 0, endColumn: 0 }
20+
const detail = `${label}(${generateArgsNames('', args).join(', ')})`
21+
const argsNames = generateArgsNames('', args, false, true)
22+
const insertText = `${label}(${generateArgsForInsertText(argsNames, ', ')})`
23+
24+
return {
25+
label,
26+
detail,
27+
range,
28+
documentation: {
29+
value: getCommandMarkdown(func)
30+
},
31+
insertText,
32+
kind: monacoEditor.languages.CompletionItemKind.Function,
33+
insertTextRules: monacoEditor.languages.CompletionItemInsertTextRule.InsertAsSnippet,
34+
}
35+
})
36+
37+
export const SQLITE_FUNCTIONS: monacoEditor.languages.CompletionItem[] = sqliteFunctionsParsed

redisinsight/ui/src/pages/rdi/pipeline-management/pages/job/Job.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const Job = (props: Props) => {
196196
value={value}
197197
onChange={handleChange}
198198
disabled={loading}
199-
dedicatedEditorLanguages={[DSL.sql, DSL.jmespath]}
199+
dedicatedEditorLanguages={[DSL.sqliteFunctions, DSL.jmespath]}
200200
dedicatedEditorFunctions={jobFunctions as monacoEditor.languages.CompletionItem[]}
201201
dedicatedEditorOptions={{
202202
suggest: { preview: false, showIcons: true, showStatusBar: true }

0 commit comments

Comments
 (0)