Skip to content

Commit eebde4e

Browse files
committed
#RI-6226 - add sorting for list of commands
#RI-6244 - fix finding of command
1 parent 52f9c79 commit eebde4e

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ export const FIELD_START_SYMBOL = '@'
9898
export enum EmptySuggestionsIds {
9999
NoIndexes = 'no-indexes'
100100
}
101+
102+
export const SORTED_SEARCH_COMMANDS = [
103+
'FT.SEARCH',
104+
'FT.CREATE',
105+
'FT.EXPLAIN',
106+
'FT.PROFILE'
107+
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const findSuggestionsByArg = (
3737
const [beforeOffsetArgs, [currentOffsetArg]] = args
3838

3939
const scopedList = command.name
40-
? listOfCommands.filter(({ name }) => name === command?.name)
40+
? listOfCommands.filter(({ token }) => token === command?.name)
4141
: listOfCommands
4242
const foundArg = findCurrentArgument(scopedList, beforeOffsetArgs)
4343

@@ -97,7 +97,7 @@ const handleIndexSuggestions = (
9797
cursorContext: CursorContext
9898
) => {
9999
const isIndex = indexes.length > 0
100-
const helpWidget = { isOpen: isIndex, data: { parent: command.info, currentArg: foundArg?.stopArg } }
100+
const helpWidget = { isOpen: isIndex, data: { parent: foundArg.parent, currentArg: foundArg?.stopArg } }
101101
const currentCommand = command.info
102102

103103
if (COMMANDS_WITHOUT_INDEX_PROPOSE.includes(command.name || '')) {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,22 @@ export const getFunctionsSuggestions = (functions: IRedisCommand[], range: monac
104104
detail: summary
105105
}))
106106

107+
export const getSortingForCommand = (command: IRedisCommand) => {
108+
if (!command.token?.startsWith(ModuleCommandPrefix.RediSearch)) return command.token
109+
if (!SORTED_SEARCH_COMMANDS.includes(command.token)) return command.token
110+
111+
const index = findIndex(SORTED_SEARCH_COMMANDS, (token) => token === command.token)
112+
return `${ModuleCommandPrefix.RediSearch}_${index}`
113+
}
114+
107115
export const getCommandsSuggestions = (commands: IRedisCommand[], range: monaco.IRange) =>
108116
commands.map((command) => buildSuggestion(command, range, {
109117
detail: generateDetail(command),
110118
insertTextRules: monacoEditor.languages.CompletionItemInsertTextRule.InsertAsSnippet,
111119
documentation: {
112120
value: getCommandMarkdown(command as any)
113121
},
122+
sortText: getSortingForCommand(command)
114123
}))
115124

116125
export const getMandatoryArgumentSuggestions = (
@@ -176,7 +185,8 @@ export const getGeneralSuggestions = (
176185
if (foundArg && !foundArg.isComplete) {
177186
return {
178187
suggestions: getMandatoryArgumentSuggestions(foundArg, fields, range),
179-
helpWidgetData: { isOpen: !!foundArg?.stopArg,
188+
helpWidgetData: {
189+
isOpen: !!foundArg?.stopArg,
180190
data: {
181191
parent: foundArg?.parent,
182192
currentArg: foundArg?.stopArg,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ export const findArgumentftSearchTests = [
179179
append: [],
180180
isBlocked: false,
181181
isComplete: true,
182-
parent: expect.any(Object)
182+
parent: expect.any(Object),
183+
token: expect.any(Object)
183184
}
184185
},
185186
{

redisinsight/ui/src/utils/monaco/monacoUtils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@ export const findCompleteQuery = (
238238
fullQuery = `\n${fullQuery}`
239239
}
240240

241-
const matchedCommand = commandsArray
242-
.find((command) => commandName?.trim().toUpperCase().startsWith(command.toUpperCase()))
243-
244-
if (isUndefined(matchedCommand)) {
245-
return null
246-
}
247-
248241
const commandCursorPosition = fullQuery.length
249242
// find args in the next lines
250243
const linesCount = model.getLineCount()
@@ -273,6 +266,14 @@ export const findCompleteQuery = (
273266
compositeArgs,
274267
)
275268

269+
const [[firstQueryArg]] = args
270+
const matchedCommand = commandsArray
271+
.find((command) => firstQueryArg?.toUpperCase() === command.toUpperCase())
272+
273+
if (isUndefined(matchedCommand)) {
274+
return null
275+
}
276+
276277
return {
277278
position,
278279
commandPosition,

0 commit comments

Comments
 (0)