Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions redisinsight/ui/src/pages/workbench/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 || '')) {
Expand Down
12 changes: 11 additions & 1 deletion redisinsight/ui/src/pages/workbench/utils/suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@ 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),
insertTextRules: monacoEditor.languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: {
value: getCommandMarkdown(command as any)
},
sortText: getSortingForCommand(command)
}))

export const getMandatoryArgumentSuggestions = (
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ export const findArgumentftSearchTests = [
append: [],
isBlocked: false,
isComplete: true,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
}
},
{
Expand Down
15 changes: 8 additions & 7 deletions redisinsight/ui/src/utils/monaco/monacoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down