Skip to content

Commit c5524cd

Browse files
committed
#RI-6208 - improve switch between redis and search syntax, add command scope
#RI-6211 - fix highlighting when there are several the same args
1 parent dfee34b commit c5524cd

File tree

12 files changed

+158
-71
lines changed

12 files changed

+158
-71
lines changed

redisinsight/ui/src/pages/workbench/components/query/Query/Query.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ const Query = (props: Props) => {
8585
const suggestionsRef = useRef<monacoEditor.languages.CompletionItem[]>([])
8686
const helpWidgetRef = useRef<any>({
8787
isOpen: false,
88-
parent: null,
89-
currentArg: null
88+
data: {}
9089
})
9190
const indexesRef = useRef<RedisResponseBuffer[]>([])
9291
const attributesRef = useRef<any>([])
@@ -581,11 +580,10 @@ const Query = (props: Props) => {
581580
)
582581

583582
if (helpWidget) {
584-
const { isOpen, parent, currentArg } = helpWidget
583+
const { isOpen, data } = helpWidget
585584
helpWidgetRef.current = {
586585
isOpen,
587-
parent: parent || helpWidgetRef.current.parent,
588-
currentArg: currentArg || helpWidgetRef.current.currentArg
586+
data: data || helpWidgetRef.current.data
589587
}
590588
}
591589

redisinsight/ui/src/pages/workbench/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface FoundCommandArgument {
1313
isBlocked: boolean
1414
append: Maybe<Array<IRedisCommandTree[]>>
1515
parent: Maybe<IRedisCommand>
16+
token: Maybe<IRedisCommand>
1617
}
1718

1819
export interface CursorContext {

redisinsight/ui/src/pages/workbench/utils/monaco.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { monaco } from 'react-monaco-editor'
22
import * as monacoEditor from 'monaco-editor'
33
import { isString } from 'lodash'
44
import { generateDetail } from 'uiSrc/pages/workbench/utils/query'
5-
import { Maybe } from 'uiSrc/utils'
5+
import { Maybe, Nullable } from 'uiSrc/utils'
66
import { IRedisCommand, ICommandTokenType } from 'uiSrc/constants'
77

88
export const setCursorPositionAtTheEnd = (editor: monacoEditor.editor.IStandaloneCodeEditor) => {
@@ -39,25 +39,41 @@ export const buildSuggestion = (arg: IRedisCommand, range: monaco.IRange, option
3939

4040
export const getRediSearchSignutureProvider = (options: Maybe<{
4141
isOpen: boolean
42-
currentArg: IRedisCommand
43-
parent: Maybe<IRedisCommand>
42+
data: {
43+
currentArg: IRedisCommand
44+
parent: Maybe<IRedisCommand>
45+
token: Maybe<IRedisCommand>
46+
}
4447
}>) => {
45-
const { isOpen, currentArg, parent } = options || {}
48+
const { isOpen, data } = options || {}
49+
const { currentArg, parent, token } = data || {}
4650
if (!isOpen) return null
4751

4852
const label = generateDetail(parent)
53+
let signaturePosition: Nullable<[number, number]> = null
4954
const arg = currentArg?.type === ICommandTokenType.Block
50-
? currentArg?.arguments?.[0]?.name
55+
? (currentArg?.arguments?.[0]?.name || currentArg?.token || '')
5156
: (currentArg?.name || currentArg?.type || '')
5257

58+
// we may have several the same args inside documentation, so we get proper arg after token
59+
const numberOfArgsInside = label.split(arg).length - 1
60+
if (token && numberOfArgsInside > 1) {
61+
const parentToken = token.token || token.arguments?.[0]?.token
62+
const parentTokenPosition = parentToken ? label.indexOf(parentToken) : 0
63+
const startPosition = label.indexOf(arg, parentTokenPosition)
64+
signaturePosition = [startPosition, startPosition + arg.length]
65+
}
66+
5367
return {
5468
dispose: () => {},
5569
value: {
5670
activeParameter: 0,
5771
activeSignature: 0,
5872
signatures: [{
5973
label: label || '',
60-
parameters: [{ label: arg }]
74+
parameters: [
75+
{ label: signaturePosition || arg }
76+
],
6177
}]
6278
}
6379
}

redisinsight/ui/src/pages/workbench/utils/query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const findCurrentArgument = (
3232
// this is the main function which creates the list of arguments
3333
return {
3434
...getArgumentSuggestions({ tokenArgs: pastArgs, untilTokenArgs }, commandArgs, parent),
35+
token,
3536
parent: parent || token
3637
}
3738
}

redisinsight/ui/src/pages/workbench/utils/searchSuggestions.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ export const findSuggestionsByArg = (
3636
const { prevCursorChar } = cursor
3737
const [beforeOffsetArgs, [currentOffsetArg]] = args
3838

39-
const foundArg = findCurrentArgument(listOfCommands, beforeOffsetArgs)
39+
const scopedList = command.name
40+
? listOfCommands.filter(({ name }) => name === command?.name)
41+
: listOfCommands
42+
const foundArg = findCurrentArgument(scopedList, beforeOffsetArgs)
4043

4144
if (!command.name.startsWith(ModuleCommandPrefix.RediSearch)) {
4245
return {
43-
helpWidget: { isOpen: !!foundArg, parent: foundArg?.parent, currentArg: foundArg?.stopArg },
46+
helpWidget: { isOpen: !!foundArg, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } },
4447
suggestions: asSuggestionsRef([])
4548
}
4649
}
@@ -94,7 +97,7 @@ const handleIndexSuggestions = (
9497
cursorContext: CursorContext
9598
) => {
9699
const isIndex = indexes.length > 0
97-
const helpWidget = { isOpen: isIndex, parent: command.info, currentArg: foundArg?.stopArg }
100+
const helpWidget = { isOpen: isIndex, data: { parent: command.info, currentArg: foundArg?.stopArg } }
98101
const currentCommand = command.info
99102

100103
if (COMMANDS_WITHOUT_INDEX_PROPOSE.includes(command.name || '')) {
@@ -132,7 +135,7 @@ const handleIndexSuggestions = (
132135
}
133136

134137
const handleQuerySuggestions = (foundArg: FoundCommandArgument) => ({
135-
helpWidget: { isOpen: true, parent: foundArg?.parent, currentArg: foundArg?.stopArg },
138+
helpWidget: { isOpen: true, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } },
136139
suggestions: asSuggestionsRef([], false)
137140
})
138141

@@ -141,7 +144,7 @@ const handleExpressionSuggestions = (
141144
foundArg: FoundCommandArgument,
142145
cursorContext: CursorContext,
143146
) => {
144-
const helpWidget = { isOpen: true, parent: foundArg?.parent, currentArg: foundArg?.stopArg }
147+
const helpWidget = { isOpen: true, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } }
145148

146149
const { isCursorInQuotes, offset, argLeftOffset } = cursorContext
147150
if (!isCursorInQuotes) {
@@ -182,7 +185,7 @@ const handleCommonSuggestions = (
182185
const shouldHideSuggestions = isCursorInQuotes || nextCursorChar || (prevCursorChar && isEscaped)
183186
if (shouldHideSuggestions) {
184187
return {
185-
helpWidget: { isOpen: !!foundArg, parent: foundArg?.parent, currentArg: foundArg?.stopArg },
188+
helpWidget: { isOpen: !!foundArg, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } },
186189
suggestions: asSuggestionsRef([])
187190
}
188191
}

redisinsight/ui/src/pages/workbench/utils/suggestions.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { monaco } from 'react-monaco-editor'
22
import * as monacoEditor from 'monaco-editor'
3+
import { findIndex } from 'lodash'
34
import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
45
import { bufferToString, formatLongName, generateArgsForInsertText, getCommandMarkdown, Nullable } from 'uiSrc/utils'
56
import { FoundCommandArgument } from 'uiSrc/pages/workbench/types'
6-
import { DefinedArgumentName, EmptySuggestionsIds } from 'uiSrc/pages/workbench/constants'
7+
import {
8+
DefinedArgumentName,
9+
EmptySuggestionsIds,
10+
ModuleCommandPrefix,
11+
SORTED_SEARCH_COMMANDS
12+
} from 'uiSrc/pages/workbench/constants'
713
import { getUtmExternalLink } from 'uiSrc/utils/links'
814
import { IRedisCommand } from 'uiSrc/constants'
915
import { generateDetail, removeNotSuggestedArgs } from './query'
@@ -170,7 +176,13 @@ export const getGeneralSuggestions = (
170176
if (foundArg && !foundArg.isComplete) {
171177
return {
172178
suggestions: getMandatoryArgumentSuggestions(foundArg, fields, range),
173-
helpWidgetData: { isOpen: !!foundArg?.stopArg, parent: foundArg?.parent, currentArg: foundArg?.stopArg }
179+
helpWidgetData: { isOpen: !!foundArg?.stopArg,
180+
data: {
181+
parent: foundArg?.parent,
182+
currentArg: foundArg?.stopArg,
183+
token: foundArg?.token
184+
}
185+
}
174186
}
175187
}
176188

redisinsight/ui/src/pages/workbench/utils/tests/monaco.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ const getRediSearchSignatureProviderTests = [
77
{
88
input: {
99
isOpen: false,
10-
currentArg: {},
11-
parent: {}
10+
data: {
11+
currentArg: {},
12+
parent: {}
13+
}
1214
},
1315
result: null
1416
},
1517
{
1618
input: {
1719
isOpen: true,
18-
currentArg: ftAggregateCommand.arguments.find(({ name }) => name === 'groupby'),
19-
parent: null
20+
data: {
21+
currentArg: ftAggregateCommand.arguments.find(({ name }) => name === 'groupby'),
22+
parent: null
23+
}
2024
},
2125
result: {
2226
dispose: expect.any(Function),
@@ -33,8 +37,10 @@ const getRediSearchSignatureProviderTests = [
3337
{
3438
input: {
3539
isOpen: true,
36-
currentArg: { name: 'expression' },
37-
parent: ftAggregateCommand.arguments.find(({ name }) => name === 'apply')
40+
data: {
41+
currentArg: { name: 'expression' },
42+
parent: ftAggregateCommand.arguments.find(({ name }) => name === 'apply')
43+
}
3844
},
3945
result: {
4046
dispose: expect.any(Function),

redisinsight/ui/src/pages/workbench/utils/tests/test-cases/common.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const commonfindCurrentArgumentCases = [
77
append: expect.any(Array),
88
isBlocked: false,
99
isComplete: true,
10-
parent: expect.any(Object)
10+
parent: expect.any(Object),
11+
token: expect.any(Object)
1112
},
1213
appendIncludes: ['WITHSCORES', 'VERBATIM', 'FILTER', 'SORTBY', 'RETURN'],
1314
appendNotIncludes: ['DIALECT']
@@ -19,7 +20,8 @@ export const commonfindCurrentArgumentCases = [
1920
append: expect.any(Array),
2021
isBlocked: false,
2122
isComplete: true,
22-
parent: expect.any(Object)
23+
parent: expect.any(Object),
24+
token: expect.any(Object)
2325
},
2426
appendIncludes: ['REDUCE', 'APPLY', 'SORTBY', 'GROUPBY'],
2527
appendNotIncludes: ['AS'],
@@ -36,7 +38,8 @@ export const commonfindCurrentArgumentCases = [
3638
append: expect.any(Array),
3739
isBlocked: false,
3840
isComplete: true,
39-
parent: expect.any(Object)
41+
parent: expect.any(Object),
42+
token: expect.any(Object)
4043
},
4144
appendIncludes: ['AS', 'REDUCE', 'APPLY', 'SORTBY', 'GROUPBY'],
4245
},
@@ -47,7 +50,8 @@ export const commonfindCurrentArgumentCases = [
4750
append: expect.any(Array),
4851
isBlocked: false,
4952
isComplete: true,
50-
parent: expect.any(Object)
53+
parent: expect.any(Object),
54+
token: expect.any(Object)
5155
},
5256
appendIncludes: ['DIALECT', 'EXPANDER', 'INKEYS', 'LIMIT'],
5357
appendNotIncludes: ['ASC'],
@@ -107,7 +111,8 @@ export const commonfindCurrentArgumentCases = [
107111
append: expect.any(Array),
108112
isBlocked: false,
109113
isComplete: false,
110-
parent: expect.any(Object)
114+
parent: expect.any(Object),
115+
token: expect.any(Object)
111116
},
112117
appendIncludes: ['AS', 'GEO', 'TEXT', 'VECTOR'],
113118
appendNotIncludes: ['SCHEMA', 'SCORE', 'NOHL'],
@@ -119,7 +124,8 @@ export const commonfindCurrentArgumentCases = [
119124
append: expect.any(Array),
120125
isBlocked: false,
121126
isComplete: true,
122-
parent: expect.any(Object)
127+
parent: expect.any(Object),
128+
token: expect.any(Object)
123129
},
124130
appendIncludes: ['INDEXEMPTY', 'SORTABLE', 'WITHSUFFIXTRIE'],
125131
appendNotIncludes: ['SCHEMA', 'SCORE', 'NOHL'],
@@ -131,7 +137,8 @@ export const commonfindCurrentArgumentCases = [
131137
append: expect.any(Array),
132138
isBlocked: false,
133139
isComplete: false,
134-
parent: expect.any(Object)
140+
parent: expect.any(Object),
141+
token: expect.any(Object)
135142
},
136143
appendIncludes: ['SCHEMA', 'SKIPINITIALSCAN'],
137144
appendNotIncludes: ['ADD'],
@@ -152,7 +159,8 @@ export const commonfindCurrentArgumentCases = [
152159
append: [],
153160
isBlocked: true,
154161
isComplete: false,
155-
parent: expect.any(Object)
162+
parent: expect.any(Object),
163+
token: expect.any(Object)
156164
},
157165
appendIncludes: [],
158166
appendNotIncludes: [expect.any(String)],
@@ -169,6 +177,7 @@ export const commonfindCurrentArgumentCases = [
169177
isBlocked: true,
170178
isComplete: false,
171179
parent: expect.any(Object),
180+
token: expect.any(Object),
172181
stopArg: {
173182
multiple: true,
174183
name: 'term',
@@ -187,7 +196,8 @@ export const commonfindCurrentArgumentCases = [
187196
stopArg: {
188197
name: 'score',
189198
type: 'double'
190-
}
199+
},
200+
token: expect.any(Object)
191201
},
192202
appendIncludes: [],
193203
},

0 commit comments

Comments
 (0)