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
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ const Query = (props: Props) => {
const suggestionsRef = useRef<monacoEditor.languages.CompletionItem[]>([])
const helpWidgetRef = useRef<any>({
isOpen: false,
parent: null,
currentArg: null
data: {}
})
const indexesRef = useRef<RedisResponseBuffer[]>([])
const attributesRef = useRef<any>([])
Expand Down Expand Up @@ -581,11 +580,10 @@ const Query = (props: Props) => {
)

if (helpWidget) {
const { isOpen, parent, currentArg } = helpWidget
const { isOpen, data } = helpWidget
helpWidgetRef.current = {
isOpen,
parent: parent || helpWidgetRef.current.parent,
currentArg: currentArg || helpWidgetRef.current.currentArg
data: data || helpWidgetRef.current.data
}
}

Expand Down
1 change: 1 addition & 0 deletions redisinsight/ui/src/pages/workbench/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface FoundCommandArgument {
isBlocked: boolean
append: Maybe<Array<IRedisCommandTree[]>>
parent: Maybe<IRedisCommand>
token: Maybe<IRedisCommand>
}

export interface CursorContext {
Expand Down
28 changes: 22 additions & 6 deletions redisinsight/ui/src/pages/workbench/utils/monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { monaco } from 'react-monaco-editor'
import * as monacoEditor from 'monaco-editor'
import { isString } from 'lodash'
import { generateDetail } from 'uiSrc/pages/workbench/utils/query'
import { Maybe } from 'uiSrc/utils'
import { Maybe, Nullable } from 'uiSrc/utils'
import { IRedisCommand, ICommandTokenType } from 'uiSrc/constants'

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

export const getRediSearchSignutureProvider = (options: Maybe<{
isOpen: boolean
currentArg: IRedisCommand
parent: Maybe<IRedisCommand>
data: {
currentArg: IRedisCommand
parent: Maybe<IRedisCommand>
token: Maybe<IRedisCommand>
}
}>) => {
const { isOpen, currentArg, parent } = options || {}
const { isOpen, data } = options || {}
const { currentArg, parent, token } = data || {}
if (!isOpen) return null

const label = generateDetail(parent)
let signaturePosition: Nullable<[number, number]> = null
const arg = currentArg?.type === ICommandTokenType.Block
? currentArg?.arguments?.[0]?.name
? (currentArg?.arguments?.[0]?.name || currentArg?.token || '')
: (currentArg?.name || currentArg?.type || '')

// we may have several the same args inside documentation, so we get proper arg after token
const numberOfArgsInside = label.split(arg).length - 1
if (token && numberOfArgsInside > 1) {
const parentToken = token.token || token.arguments?.[0]?.token
const parentTokenPosition = parentToken ? label.indexOf(parentToken) : 0
const startPosition = label.indexOf(arg, parentTokenPosition)
signaturePosition = [startPosition, startPosition + arg.length]
}

return {
dispose: () => {},
value: {
activeParameter: 0,
activeSignature: 0,
signatures: [{
label: label || '',
parameters: [{ label: arg }]
parameters: [
{ label: signaturePosition || arg }
],
}]
}
}
Expand Down
1 change: 1 addition & 0 deletions redisinsight/ui/src/pages/workbench/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const findCurrentArgument = (
// this is the main function which creates the list of arguments
return {
...getArgumentSuggestions({ tokenArgs: pastArgs, untilTokenArgs }, commandArgs, parent),
token,
parent: parent || token
}
}
Expand Down
15 changes: 9 additions & 6 deletions redisinsight/ui/src/pages/workbench/utils/searchSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ export const findSuggestionsByArg = (
const { prevCursorChar } = cursor
const [beforeOffsetArgs, [currentOffsetArg]] = args

const foundArg = findCurrentArgument(listOfCommands, beforeOffsetArgs)
const scopedList = command.name
? listOfCommands.filter(({ name }) => name === command?.name)
: listOfCommands
const foundArg = findCurrentArgument(scopedList, beforeOffsetArgs)

if (!command.name.startsWith(ModuleCommandPrefix.RediSearch)) {
return {
helpWidget: { isOpen: !!foundArg, parent: foundArg?.parent, currentArg: foundArg?.stopArg },
helpWidget: { isOpen: !!foundArg, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } },
suggestions: asSuggestionsRef([])
}
}
Expand Down Expand Up @@ -94,7 +97,7 @@ const handleIndexSuggestions = (
cursorContext: CursorContext
) => {
const isIndex = indexes.length > 0
const helpWidget = { isOpen: isIndex, parent: command.info, currentArg: foundArg?.stopArg }
const helpWidget = { isOpen: isIndex, data: { parent: command.info, currentArg: foundArg?.stopArg } }
const currentCommand = command.info

if (COMMANDS_WITHOUT_INDEX_PROPOSE.includes(command.name || '')) {
Expand Down Expand Up @@ -132,7 +135,7 @@ const handleIndexSuggestions = (
}

const handleQuerySuggestions = (foundArg: FoundCommandArgument) => ({
helpWidget: { isOpen: true, parent: foundArg?.parent, currentArg: foundArg?.stopArg },
helpWidget: { isOpen: true, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } },
suggestions: asSuggestionsRef([], false)
})

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

const { isCursorInQuotes, offset, argLeftOffset } = cursorContext
if (!isCursorInQuotes) {
Expand Down Expand Up @@ -182,7 +185,7 @@ const handleCommonSuggestions = (
const shouldHideSuggestions = isCursorInQuotes || nextCursorChar || (prevCursorChar && isEscaped)
if (shouldHideSuggestions) {
return {
helpWidget: { isOpen: !!foundArg, parent: foundArg?.parent, currentArg: foundArg?.stopArg },
helpWidget: { isOpen: !!foundArg, data: { parent: foundArg?.parent, currentArg: foundArg?.stopArg } },
suggestions: asSuggestionsRef([])
}
}
Expand Down
16 changes: 14 additions & 2 deletions redisinsight/ui/src/pages/workbench/utils/suggestions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { monaco } from 'react-monaco-editor'
import * as monacoEditor from 'monaco-editor'
import { findIndex } from 'lodash'
import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
import { bufferToString, formatLongName, generateArgsForInsertText, getCommandMarkdown, Nullable } from 'uiSrc/utils'
import { FoundCommandArgument } from 'uiSrc/pages/workbench/types'
import { DefinedArgumentName, EmptySuggestionsIds } from 'uiSrc/pages/workbench/constants'
import {
DefinedArgumentName,
EmptySuggestionsIds,
ModuleCommandPrefix,
SORTED_SEARCH_COMMANDS
} from 'uiSrc/pages/workbench/constants'
import { getUtmExternalLink } from 'uiSrc/utils/links'
import { IRedisCommand } from 'uiSrc/constants'
import { generateDetail, removeNotSuggestedArgs } from './query'
Expand Down Expand Up @@ -170,7 +176,13 @@ export const getGeneralSuggestions = (
if (foundArg && !foundArg.isComplete) {
return {
suggestions: getMandatoryArgumentSuggestions(foundArg, fields, range),
helpWidgetData: { isOpen: !!foundArg?.stopArg, parent: foundArg?.parent, currentArg: foundArg?.stopArg }
helpWidgetData: { isOpen: !!foundArg?.stopArg,
data: {
parent: foundArg?.parent,
currentArg: foundArg?.stopArg,
token: foundArg?.token
}
}
}
}

Expand Down
18 changes: 12 additions & 6 deletions redisinsight/ui/src/pages/workbench/utils/tests/monaco.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ const getRediSearchSignatureProviderTests = [
{
input: {
isOpen: false,
currentArg: {},
parent: {}
data: {
currentArg: {},
parent: {}
}
},
result: null
},
{
input: {
isOpen: true,
currentArg: ftAggregateCommand.arguments.find(({ name }) => name === 'groupby'),
parent: null
data: {
currentArg: ftAggregateCommand.arguments.find(({ name }) => name === 'groupby'),
parent: null
}
},
result: {
dispose: expect.any(Function),
Expand All @@ -33,8 +37,10 @@ const getRediSearchSignatureProviderTests = [
{
input: {
isOpen: true,
currentArg: { name: 'expression' },
parent: ftAggregateCommand.arguments.find(({ name }) => name === 'apply')
data: {
currentArg: { name: 'expression' },
parent: ftAggregateCommand.arguments.find(({ name }) => name === 'apply')
}
},
result: {
dispose: expect.any(Function),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: true,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['WITHSCORES', 'VERBATIM', 'FILTER', 'SORTBY', 'RETURN'],
appendNotIncludes: ['DIALECT']
Expand All @@ -19,7 +20,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: true,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['REDUCE', 'APPLY', 'SORTBY', 'GROUPBY'],
appendNotIncludes: ['AS'],
Expand All @@ -36,7 +38,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: true,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['AS', 'REDUCE', 'APPLY', 'SORTBY', 'GROUPBY'],
},
Expand All @@ -47,7 +50,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: true,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['DIALECT', 'EXPANDER', 'INKEYS', 'LIMIT'],
appendNotIncludes: ['ASC'],
Expand Down Expand Up @@ -107,7 +111,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: false,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['AS', 'GEO', 'TEXT', 'VECTOR'],
appendNotIncludes: ['SCHEMA', 'SCORE', 'NOHL'],
Expand All @@ -119,7 +124,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: true,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['INDEXEMPTY', 'SORTABLE', 'WITHSUFFIXTRIE'],
appendNotIncludes: ['SCHEMA', 'SCORE', 'NOHL'],
Expand All @@ -131,7 +137,8 @@ export const commonfindCurrentArgumentCases = [
append: expect.any(Array),
isBlocked: false,
isComplete: false,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: ['SCHEMA', 'SKIPINITIALSCAN'],
appendNotIncludes: ['ADD'],
Expand All @@ -152,7 +159,8 @@ export const commonfindCurrentArgumentCases = [
append: [],
isBlocked: true,
isComplete: false,
parent: expect.any(Object)
parent: expect.any(Object),
token: expect.any(Object)
},
appendIncludes: [],
appendNotIncludes: [expect.any(String)],
Expand All @@ -169,6 +177,7 @@ export const commonfindCurrentArgumentCases = [
isBlocked: true,
isComplete: false,
parent: expect.any(Object),
token: expect.any(Object),
stopArg: {
multiple: true,
name: 'term',
Expand All @@ -187,7 +196,8 @@ export const commonfindCurrentArgumentCases = [
stopArg: {
name: 'score',
type: 'double'
}
},
token: expect.any(Object)
},
appendIncludes: [],
},
Expand Down
Loading