diff --git a/packages/core/expressions/src/components/ExpressionsEditor.vue b/packages/core/expressions/src/components/ExpressionsEditor.vue index 1236fcd77c..4b7faeec8d 100644 --- a/packages/core/expressions/src/components/ExpressionsEditor.vue +++ b/packages/core/expressions/src/components/ExpressionsEditor.vue @@ -25,6 +25,7 @@ const props = withDefaults(defineProps<{ parseDebounce?: number, inactiveUntilFocused?: boolean, allowEmptyInput?: boolean, + defaultShowDetails?: boolean, editorOptions?: Monaco.editor.IEditorOptions }>(), { parseDebounce: 500, @@ -80,6 +81,10 @@ onMounted(() => { ...props.editorOptions, }) + if (props.defaultShowDetails) { + editor.getContribution & Monaco.editor.IEditorContribution>('editor.contrib.suggestController') + ?.widget?.value._setDetailsVisible(true) + } editor.onDidChangeModelContent(() => { const value = editor!.getValue() expression.value = value diff --git a/packages/core/expressions/src/monaco.ts b/packages/core/expressions/src/monaco.ts index c88a3107cd..43393036c1 100644 --- a/packages/core/expressions/src/monaco.ts +++ b/packages/core/expressions/src/monaco.ts @@ -1,5 +1,5 @@ import * as monaco from 'monaco-editor' -import { type Schema, type SchemaDefinition } from './schema' +import { type Schema } from './schema' interface MonarchLanguage extends monaco.languages.IMonarchLanguage { keywords: string[]; @@ -8,12 +8,14 @@ interface MonarchLanguage extends monaco.languages.IMonarchLanguage { interface Token { detail?: string; children?: Record; + documentation?: string; } -const buildTokenTree = (schemaDefinition: SchemaDefinition) => { +const buildTokenTree = (schema: Schema) => { + const { definition, documentation } = schema const root: Token = {} - for (const [kind, fields] of Object.entries(schemaDefinition)) { + for (const [kind, fields] of Object.entries(definition)) { for (const field of fields) { let token = root for (const t of field.split('.')) { @@ -26,6 +28,9 @@ const buildTokenTree = (schemaDefinition: SchemaDefinition) => { token = token.children[t] } token.detail = kind + if (documentation?.[field] !== undefined) { + token.documentation = documentation[field] + } } } @@ -61,7 +66,7 @@ export const registerLanguage = (schema: Schema) => { return { languageId } } - const tokenTree = buildTokenTree(schema.definition) + const tokenTree = buildTokenTree(schema) const keywords = ['not', 'in', 'contains'] @@ -153,6 +158,7 @@ export const registerLanguage = (schema: Schema) => { detail: props.detail, insertText: token === '*' ? '' : token, range, + documentation: props.documentation, })), } }, diff --git a/packages/core/expressions/src/schema.ts b/packages/core/expressions/src/schema.ts index 45cb62e272..9c4edd4abb 100644 --- a/packages/core/expressions/src/schema.ts +++ b/packages/core/expressions/src/schema.ts @@ -7,6 +7,7 @@ export type SchemaDefinition = { export interface Schema { name: string; definition: SchemaDefinition; + documentation?: Record; } export const createSchema = (definition: SchemaDefinition) => {