Skip to content

Commit 4008d78

Browse files
committed
#RI-6264 - fix highlighting and suggestion when query command starts with number
1 parent 66c842b commit 4008d78

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const findSuggestionsByArg = (
6262

6363
if (foundArg?.stopArg?.token && !foundArg?.isBlocked) {
6464
return handleCommonSuggestions(
65-
command.fullQuery,
65+
command.commandQuery,
6666
foundArg,
6767
allArgs,
6868
additionData.fields || [],
@@ -80,7 +80,7 @@ export const findSuggestionsByArg = (
8080
return handleQuerySuggestions(foundArg)
8181
}
8282
default: {
83-
return handleCommonSuggestions(command.fullQuery, foundArg, allArgs, fields, cursorContext, isEscaped)
83+
return handleCommonSuggestions(command.commandQuery, foundArg, allArgs, fields, cursorContext, isEscaped)
8484
}
8585
}
8686
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface IMonacoCommand {
1010
export interface IMonacoQuery {
1111
name: string
1212
fullQuery: string
13+
commandQuery: string
1314
args: [string[], string[]],
1415
cursor: {
1516
isCursorInQuotes: boolean,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const STRING_DOUBLE = 'string.double'
88
export const getRedisMonarchTokensProvider = (commands: IRedisCommand[]): monacoEditor.languages.IMonarchLanguage => {
99
const commandRedisCommands = [...commands]
1010
const searchCommands = remove(commandRedisCommands, ({ token }) => token?.startsWith(ModuleCommandPrefix.RediSearch))
11-
const COMMON_COMMANDS_REGEX = `^\\s*(${commandRedisCommands.map(({ token }) => token).join('|')})\\b`
12-
const SEARCH_COMMANDS_REGEX = `^\\s*(${searchCommands.map(({ token }) => token).join('|')})\\b`
11+
const COMMON_COMMANDS_REGEX = `^\\s*(\\d+\\s+)?(${commandRedisCommands.map(({ token }) => token).join('|')})\\b`
12+
const SEARCH_COMMANDS_REGEX = `^\\s*(\\d+\\s+)?(${searchCommands.map(({ token }) => token).join('|')})\\b`
1313

1414
return {
1515
defaultToken: '',
@@ -20,13 +20,12 @@ export const getRedisMonarchTokensProvider = (commands: IRedisCommand[]): monaco
2020
{ open: '[', close: ']', token: 'delimiter.square' },
2121
{ open: '(', close: ')', token: 'delimiter.parenthesis' },
2222
],
23-
keywords: commands.map(({ token }) => token),
23+
keywords: [],
2424
operators: [],
2525
tokenizer: {
2626
root: [
2727
{ include: '@startOfLine' },
2828
{ include: '@whitespace' },
29-
{ include: '@numbers' },
3029
{ include: '@strings' },
3130
{ include: '@keyword' },
3231
[/[;,.]/, 'delimiter'],
@@ -42,6 +41,7 @@ export const getRedisMonarchTokensProvider = (commands: IRedisCommand[]): monaco
4241
},
4342
],
4443
[/[<>=!%&+\-*/|~^]/, 'operator'],
44+
{ include: '@numbers' },
4545
],
4646
keyword: [
4747
[COMMON_COMMANDS_REGEX, { token: 'keyword' }],

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { monaco as monacoEditor } from 'react-monaco-editor'
2-
import { first, isEmpty, isUndefined, reject, without } from 'lodash'
2+
import { first, isEmpty, isNaN, isUndefined, reject, toNumber, without } from 'lodash'
33
import { decode } from 'html-entities'
44
import { ICommand, ICommands } from 'uiSrc/constants'
55
import {
@@ -266,13 +266,15 @@ export const findCompleteQuery = (
266266
compositeArgs,
267267
)
268268

269-
const [[commandNameFromQuery]] = args
269+
const [beforeCursorArgs] = args
270+
const commandNameFromQuery = isNaN(toNumber(beforeCursorArgs[0])) ? beforeCursorArgs[0] : beforeCursorArgs[1]
270271
const matchedCommand = commandsArray
271272
.find((command) => commandNameFromQuery?.toUpperCase() === command.toUpperCase())
272273

273274
const cursorContext = {
274275
position,
275276
fullQuery,
277+
commandQuery: fullQuery.replace(/^\d+\s+/, ''),
276278
args,
277279
allArgs: args.flat(),
278280
cursor,

redisinsight/ui/src/utils/monaco/monarchTokens/redisearchTokensSubRedis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ export const getRediSearchSubRedisMonarchTokensProvider = (
7777
[/[\w@#$.]+/, 'identifier']
7878
],
7979
keywords: [
80-
[`^\\s*(${generateKeywords(withNextQueryIndexSuggestions).join('|')})\\b`, { token: 'keyword', next: '@index.query' }],
81-
[`^\\s*(${generateKeywords(withNextIndexSuggestions).join('|')})\\b`, { token: 'keyword', next: '@index' }],
82-
[`^\\s*(${generateKeywords(withoutIndexSuggestions).join('|')})\\b`, { token: 'keyword', next: '@root' }],
80+
[`^\\s*(\\d\\s)?(${generateKeywords(withNextQueryIndexSuggestions).join('|')})\\b`, { token: 'keyword', next: '@index.query' }],
81+
[`^\\s*(\\d\\s)?(${generateKeywords(withNextIndexSuggestions).join('|')})\\b`, { token: 'keyword', next: '@index' }],
82+
[`^\\s*(\\d\\s)?(${generateKeywords(withoutIndexSuggestions).join('|')})\\b`, { token: 'keyword', next: '@root' }],
8383
],
8484
...tokens,
8585
...generateQuery(),

0 commit comments

Comments
 (0)