diff --git a/redisinsight/ui/src/pages/workbench/constants.ts b/redisinsight/ui/src/pages/workbench/constants.ts index 1c732c67ce..b894704f29 100644 --- a/redisinsight/ui/src/pages/workbench/constants.ts +++ b/redisinsight/ui/src/pages/workbench/constants.ts @@ -98,3 +98,10 @@ export const FIELD_START_SYMBOL = '@' export enum EmptySuggestionsIds { NoIndexes = 'no-indexes' } + +export const SORTED_SEARCH_COMMANDS = [ + 'FT.SEARCH', + 'FT.CREATE', + 'FT.EXPLAIN', + 'FT.PROFILE' +] diff --git a/redisinsight/ui/src/pages/workbench/utils/searchSuggestions.ts b/redisinsight/ui/src/pages/workbench/utils/searchSuggestions.ts index 3ef7caec10..0d408b170f 100644 --- a/redisinsight/ui/src/pages/workbench/utils/searchSuggestions.ts +++ b/redisinsight/ui/src/pages/workbench/utils/searchSuggestions.ts @@ -37,7 +37,7 @@ export const findSuggestionsByArg = ( const [beforeOffsetArgs, [currentOffsetArg]] = args const scopedList = command.name - ? listOfCommands.filter(({ name }) => name === command?.name) + ? listOfCommands.filter(({ token }) => token === command?.name) : listOfCommands const foundArg = findCurrentArgument(scopedList, beforeOffsetArgs) @@ -97,7 +97,7 @@ const handleIndexSuggestions = ( cursorContext: CursorContext ) => { const isIndex = indexes.length > 0 - const helpWidget = { isOpen: isIndex, data: { parent: command.info, currentArg: foundArg?.stopArg } } + const helpWidget = { isOpen: isIndex, data: { parent: foundArg.parent, currentArg: foundArg?.stopArg } } const currentCommand = command.info if (COMMANDS_WITHOUT_INDEX_PROPOSE.includes(command.name || '')) { diff --git a/redisinsight/ui/src/pages/workbench/utils/suggestions.ts b/redisinsight/ui/src/pages/workbench/utils/suggestions.ts index e7e1f5c1cc..9e443d3f06 100644 --- a/redisinsight/ui/src/pages/workbench/utils/suggestions.ts +++ b/redisinsight/ui/src/pages/workbench/utils/suggestions.ts @@ -104,6 +104,14 @@ export const getFunctionsSuggestions = (functions: IRedisCommand[], range: monac detail: summary })) +export const getSortingForCommand = (command: IRedisCommand) => { + if (!command.token?.startsWith(ModuleCommandPrefix.RediSearch)) return command.token + if (!SORTED_SEARCH_COMMANDS.includes(command.token)) return command.token + + const index = findIndex(SORTED_SEARCH_COMMANDS, (token) => token === command.token) + return `${ModuleCommandPrefix.RediSearch}_${index}` +} + export const getCommandsSuggestions = (commands: IRedisCommand[], range: monaco.IRange) => commands.map((command) => buildSuggestion(command, range, { detail: generateDetail(command), @@ -111,6 +119,7 @@ export const getCommandsSuggestions = (commands: IRedisCommand[], range: monaco. documentation: { value: getCommandMarkdown(command as any) }, + sortText: getSortingForCommand(command) })) export const getMandatoryArgumentSuggestions = ( @@ -176,7 +185,8 @@ export const getGeneralSuggestions = ( if (foundArg && !foundArg.isComplete) { return { suggestions: getMandatoryArgumentSuggestions(foundArg, fields, range), - helpWidgetData: { isOpen: !!foundArg?.stopArg, + helpWidgetData: { + isOpen: !!foundArg?.stopArg, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg, diff --git a/redisinsight/ui/src/pages/workbench/utils/tests/test-cases/ft-search.ts b/redisinsight/ui/src/pages/workbench/utils/tests/test-cases/ft-search.ts index 436308a7a3..a9d54d33e3 100644 --- a/redisinsight/ui/src/pages/workbench/utils/tests/test-cases/ft-search.ts +++ b/redisinsight/ui/src/pages/workbench/utils/tests/test-cases/ft-search.ts @@ -179,7 +179,8 @@ export const findArgumentftSearchTests = [ append: [], isBlocked: false, isComplete: true, - parent: expect.any(Object) + parent: expect.any(Object), + token: expect.any(Object) } }, { diff --git a/redisinsight/ui/src/utils/monaco/monacoUtils.ts b/redisinsight/ui/src/utils/monaco/monacoUtils.ts index db18fedb03..9a98e4dc5b 100644 --- a/redisinsight/ui/src/utils/monaco/monacoUtils.ts +++ b/redisinsight/ui/src/utils/monaco/monacoUtils.ts @@ -238,13 +238,6 @@ export const findCompleteQuery = ( fullQuery = `\n${fullQuery}` } - const matchedCommand = commandsArray - .find((command) => commandName?.trim().toUpperCase().startsWith(command.toUpperCase())) - - if (isUndefined(matchedCommand)) { - return null - } - const commandCursorPosition = fullQuery.length // find args in the next lines const linesCount = model.getLineCount() @@ -273,6 +266,14 @@ export const findCompleteQuery = ( compositeArgs, ) + const [[firstQueryArg]] = args + const matchedCommand = commandsArray + .find((command) => firstQueryArg?.toUpperCase() === command.toUpperCase()) + + if (isUndefined(matchedCommand)) { + return null + } + return { position, commandPosition,