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 @@ -5,15 +5,17 @@ import { IRedisCommand } from 'uiSrc/constants'

const STRING_DOUBLE = 'string.double'

const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

Comment on lines 5 to +9
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escapeRegex utility function is duplicated across three different files. Consider extracting it to a shared utility module (e.g., utils/regex.ts) and importing it to maintain DRY principles and ensure consistency.

Suggested change
const STRING_DOUBLE = 'string.double'
const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
import { escapeRegex } from 'uiSrc/utils/regex'
const STRING_DOUBLE = 'string.double'

Copilot uses AI. Check for mistakes.
export const getRedisMonarchTokensProvider = (
commands: IRedisCommand[],
): monacoEditor.languages.IMonarchLanguage => {
const commandRedisCommands = [...commands]
const searchCommands = remove(commandRedisCommands, ({ token }) =>
token?.startsWith(ModuleCommandPrefix.RediSearch),
)
const COMMON_COMMANDS_REGEX = `^\\s*(\\d+\\s+)?(${commandRedisCommands.map(({ token }) => token).join('|')})\\b`
const SEARCH_COMMANDS_REGEX = `^\\s*(\\d+\\s+)?(${searchCommands.map(({ token }) => token).join('|')})\\b`
const COMMON_COMMANDS_REGEX = `^\\s*(\\d+\\s+)?(${commandRedisCommands.map(({ token }) => escapeRegex(token || '')).join('|')})\\b`
const SEARCH_COMMANDS_REGEX = `^\\s*(\\d+\\s+)?(${searchCommands.map(({ token }) => escapeRegex(token || '')).join('|')})\\b`

return {
defaultToken: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { curryRight } from 'lodash'
import { Maybe } from 'uiSrc/utils'
import { IRedisCommand } from 'uiSrc/constants'

// Escape special regex characters in tokens
const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

Comment on lines 5 to +8
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escapeRegex utility function is duplicated across three different files. Consider extracting it to a shared utility module (e.g., utils/regex.ts) and importing it to maintain DRY principles and ensure consistency.

Suggested change
// Escape special regex characters in tokens
const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
import { escapeRegex } from 'uiSrc/utils/regex'

Copilot uses AI. Check for mistakes.
const appendToken = (token: string, name: Maybe<string>) =>
name ? `${token}.${name}` : token
export const generateQuery = (
Expand All @@ -17,7 +20,7 @@ export const generateQuery = (
): languages.IMonarchLanguageRule =>
args?.length
? [
`(${args?.map(({ token }) => token).join('|')})\\b`,
`(${args?.map(({ token }) => escapeRegex(token || '')).join('|')})\\b`,
{ token: 'function', next: appendTokenName(tokenName) },
]
: [/_/, '']
Expand Down
6 changes: 4 additions & 2 deletions redisinsight/ui/src/utils/monaco/redisearch/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { generateQuery } from 'uiSrc/utils/monaco/monarchTokens/redisearchTokens
import { ICommandTokenType, IRedisCommand } from 'uiSrc/constants'
import { DefinedArgumentName } from 'uiSrc/pages/workbench/constants'

const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

Comment on lines 7 to +9
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escapeRegex utility function is duplicated across three different files. Consider extracting it to a shared utility module (e.g., utils/regex.ts) and importing it to maintain DRY principles and ensure consistency.

Suggested change
const escapeRegex = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
import { escapeRegex } from 'uiSrc/utils/regex'

Copilot uses AI. Check for mistakes.
export const generateKeywords = (commands: IRedisCommand[]) =>
commands.map(({ name }) => name)
export const generateTokens = (
Expand Down Expand Up @@ -153,7 +155,7 @@ export const getBlockTokens = (

if (tokensWithNextExpression.length) {
result.push([
`(${tokensWithNextExpression.map(({ token }) => token).join('|')})\\b`,
`(${tokensWithNextExpression.map(({ token }) => escapeRegex(token || '')).join('|')})\\b`,
{
token: `argument.block.${lvl}.${name}`,
next: '@query',
Expand All @@ -163,7 +165,7 @@ export const getBlockTokens = (

if (restTokens.length) {
result.push([
`(${restTokens.map(({ token }) => token).join('|')})\\b`,
`(${restTokens.map(({ token }) => escapeRegex(token || '')).join('|')})\\b`,
{ token: `argument.block.${lvl}.${name}`, next: '@root' },
])
}
Expand Down
Loading