Skip to content

Commit a63ebf5

Browse files
committed
* #RI-1874 - [Workbench] Display additional hints in autocomplete
* #RI-2096 - Wrong shortcut for "Clear the screen"
1 parent 1e6366b commit a63ebf5

File tree

16 files changed

+171
-24
lines changed

16 files changed

+171
-24
lines changed

redisinsight/api/config/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default {
8080
redijsonUrl: process.env.COMMANDS_REDIJSON_URL
8181
|| 'https://raw.githubusercontent.com/RedisJSON/RedisJSON/master/commands.json',
8282
redistimeseriesUrl: process.env.COMMANDS_REDISTIMESERIES_URL
83-
|| 'https://raw.githubusercontent.com/RedisTimeSeries/RedisTimeSeries/master/src/commands.json',
83+
|| 'https://raw.githubusercontent.com/RedisTimeSeries/RedisTimeSeries/master/commands.json',
8484
redisaiUrl: process.env.COMMANDS_REDISAI_URL
8585
|| 'https://raw.githubusercontent.com/RedisAI/RedisAI/master/commands.json',
8686
redisgraphUrl: process.env.COMMANDS_REDISGRAPH_URL

redisinsight/api/src/constants/agreements-spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"disabled": false,
5050
"since": "1.0.4",
5151
"title": "Server Side Public License",
52-
"label": "I have read and understood the <a target=\"_blank\" href=\"https://github.com/RedisInsight/RedisInsight/blob/master/LICENSE\">Server Side Public License</a>",
52+
"label": "I have read and understood the <a target=\"_blank\" href=\"https://github.com/RedisInsight/RedisInsight/blob/main/LICENSE\">Server Side Public License</a>",
5353
"requiredText": "Accept the Server Side Public License"
5454
}
5555
}

redisinsight/ui/src/components/query/Query/Query.tsx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { compact, findIndex } from 'lodash'
44
import cx from 'classnames'
55
import { EuiButtonIcon, EuiText, EuiToolTip } from '@elastic/eui'
66
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api'
7-
import MonacoEditor from 'react-monaco-editor'
7+
import MonacoEditor, { monaco } from 'react-monaco-editor'
88

99
import {
1010
Theme,
@@ -13,10 +13,12 @@ import {
1313
KEYBOARD_SHORTCUTS,
1414
} from 'uiSrc/constants'
1515
import {
16+
actionTriggerParameterHints,
1617
decoration,
17-
geMonacoAction,
18+
getMonacoAction,
1819
getRedisCompletionProvider,
1920
getRedisMonarchTokensProvider,
21+
getRedisSignatureHelpProvider,
2022
MonacoAction,
2123
Nullable,
2224
toModelDeltaDecoration
@@ -53,19 +55,21 @@ const Query = (props: Props) => {
5355
const { theme } = useContext(ThemeContext)
5456
const monacoObjects = useRef<Nullable<IEditorMount>>(null)
5557
let disposeCompletionItemProvider = () => {}
58+
let disposeSignatureHelpProvider = () => {}
5659

5760
useEffect(() =>
5861
// componentWillUnmount
5962
() => {
6063
disposeCompletionItemProvider()
64+
disposeSignatureHelpProvider()
6165
},
6266
[])
6367

6468
useEffect(() => {
6569
if (!monacoObjects.current) return
6670
const commands = query.split('\n')
6771
const { monaco, editor } = monacoObjects.current
68-
const notCommandRegEx = /^[\s|//]/
72+
const notCommandRegEx = /^\s|\/\//
6973

7074
const newDecorations = compact(commands.map((command, index) => {
7175
if (!command || notCommandRegEx.test(command)) return null
@@ -94,6 +98,32 @@ const Query = (props: Props) => {
9498
onSubmit(value)
9599
}
96100

101+
const onTriggerParameterHints = () => {
102+
if (!monacoObjects.current) return
103+
104+
const { editor } = monacoObjects?.current
105+
const model = editor.getModel()
106+
const { lineNumber = 0 } = editor.getPosition() ?? {}
107+
const lineContent = model?.getLineContent(lineNumber)?.trim() ?? ''
108+
const matchedCommand = REDIS_COMMANDS_ARRAY.find((command) => lineContent?.trim().startsWith(command)) ?? ''
109+
// trigger parameter hints only ones between command and arguments in the same line
110+
const isTriggerHints = lineContent.split(' ').length < (2 + matchedCommand.split(' ').length)
111+
112+
if (isTriggerHints) {
113+
actionTriggerParameterHints(editor)
114+
}
115+
}
116+
117+
const onKeyDownMonaco = (e:monacoEditor.IKeyboardEvent) => {
118+
if (
119+
e.keyCode === monaco.KeyCode.Tab
120+
|| e.keyCode === monaco.KeyCode.Space
121+
|| e.keyCode === monaco.KeyCode.Enter
122+
) {
123+
onTriggerParameterHints()
124+
}
125+
}
126+
97127
const editorDidMount = (
98128
editor: monacoEditor.editor.IStandaloneCodeEditor,
99129
monaco: typeof monacoEditor
@@ -103,8 +133,12 @@ const Query = (props: Props) => {
103133
editor.focus()
104134
setQueryEl(editor)
105135

136+
editor.onKeyDown(onKeyDownMonaco)
137+
106138
setupMonacoRedisLang(monaco)
107-
editor.addAction(geMonacoAction(MonacoAction.Submit, (editor) => handleSubmit(editor.getValue()), monaco))
139+
editor.addAction(
140+
getMonacoAction(MonacoAction.Submit, (editor) => handleSubmit(editor.getValue()), monaco)
141+
)
108142
}
109143

110144
const setupMonacoRedisLang = (monaco: typeof monacoEditor) => {
@@ -117,6 +151,12 @@ const Query = (props: Props) => {
117151
MonacoLanguage.Redis,
118152
getRedisCompletionProvider(REDIS_COMMANDS_SPEC)
119153
).dispose
154+
155+
disposeSignatureHelpProvider = monaco.languages.registerSignatureHelpProvider(
156+
MonacoLanguage.Redis,
157+
getRedisSignatureHelpProvider(REDIS_COMMANDS_SPEC, REDIS_COMMANDS_ARRAY)
158+
).dispose
159+
120160
monaco.languages.setLanguageConfiguration(MonacoLanguage.Redis, redisLanguageConfig)
121161
monaco.languages.setMonarchTokensProvider(
122162
MonacoLanguage.Redis,
@@ -131,6 +171,11 @@ const Query = (props: Props) => {
131171
automaticLayout: true,
132172
formatOnPaste: false,
133173
glyphMargin: true,
174+
suggest: {
175+
preview: true,
176+
showStatusBar: true,
177+
showIcons: false,
178+
},
134179
lineNumbersMinChars: 4
135180
// fontFamily: 'Inconsolata',
136181
// fontSize: 16,

redisinsight/ui/src/components/shortcuts-flyout/schema.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const SHORTCUTS: ShortcutGroup[] = [
3636
items: [
3737
KEYBOARD_SHORTCUTS.workbench.runQuery,
3838
KEYBOARD_SHORTCUTS.workbench.nextLine,
39-
KEYBOARD_SHORTCUTS.workbench.listOfCommands
39+
KEYBOARD_SHORTCUTS.workbench.listOfCommands,
40+
KEYBOARD_SHORTCUTS.workbench.triggerHints,
4041
]
4142
},
4243
]

redisinsight/ui/src/components/shortcuts-flyout/styles.module.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
:global(.badgeArrowUp), :global(.badgeArrowDown), :global(.shiftSymbol) {
2626
position: relative;
27-
top: -3px
28-
}
29-
30-
:global(.shiftSymbol) {
31-
top: -2px
3227
}
3328

3429
:global(.cmdSymbol) {

redisinsight/ui/src/constants/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface ICommands {
33
}
44

55
export interface ICommand {
6+
name?: string;
67
summary: string;
78
complexity?: string;
89
arguments?: ICommandArg[];

redisinsight/ui/src/constants/keyboardShortcuts.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const COMMON_SHORTCUTS = {
4949
listOfCommands: {
5050
description: 'Display the list of commands and information about commands and their arguments in the suggestion list',
5151
keys: ['Ctrl', 'Space']
52+
},
53+
triggerHints: {
54+
description: 'Trigger Command Hints',
55+
keys: ['Ctrl', 'Shift', 'Space']
5256
}
5357
}
5458
}
@@ -76,7 +80,7 @@ const MAC_SHORTCUTS = {
7680
},
7781
clearSearch: {
7882
description: 'Clear the screen',
79-
keys: [(<span className="cmdSymbol"></span>), 'L']
83+
keys: [(<span className="cmdSymbol"></span>), 'K']
8084
},
8185
prevCommand: {
8286
description: 'Return to the previous command',
@@ -100,6 +104,10 @@ const MAC_SHORTCUTS = {
100104
listOfCommands: {
101105
description: 'Display the list of commands and information about commands and their arguments in the suggestion list',
102106
keys: [(<span className="cmdSymbol"></span>), 'Space']
107+
},
108+
triggerHints: {
109+
description: 'Trigger Command Hints',
110+
keys: [(<span className="cmdSymbol"></span>), (<span className="shiftSymbol"></span>), 'Space']
103111
}
104112
}
105113
}

redisinsight/ui/src/styles/base/_monaco.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515
margin: 16px 0;
1616
font-size: 1.6em;
1717
}
18-
}
1918

20-
.monaco-editor.redisLanguage-editor .suggest-icon {
21-
display: none !important;
19+
a {
20+
color: var(--euiTextSubduedColor) !important;
21+
text-decoration: underline !important;
22+
23+
&:hover {
24+
text-decoration: none !important;
25+
}
26+
}
2227
}
2328

2429
.monaco-glyph-run-command {

redisinsight/ui/src/styles/components/_buttons.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import '@elastic/eui/src/global_styling/index';
1+
@import '../../../../../node_modules/@elastic/eui/src/global_styling/index';
22

33
.euiButton {
44
&.euiButton--secondary {

redisinsight/ui/src/utils/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ export * from './longNames'
2222
export * from './cli'
2323
export * from './commands'
2424
export * from './workbench'
25-
export * from './monaco'
2625
export * from './formatBytes'
2726
export * from './instanceModules'
27+
export * from './monacoUtils'
28+
export * from './monacoInterfaces'
2829
export * from './monacoRedisComplitionProvider'
2930
export * from './monacoRedisMonarchTokensProvider'
31+
export * from './monacoRedisSignatureHelpProvider'
3032
export * from './monacoActions'
3133
export * from './monacoDecorations'
3234
export * from './handlePlatforms'

0 commit comments

Comments
 (0)