@gooddata/sdk-ui-metric-component 11.67.0-alpha.2 → 11.67.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +798 -2473
- package/esm/MaqlEditor/codemirror/CodeEditor.d.ts +52 -0
- package/esm/MaqlEditor/codemirror/CodeEditor.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/CodeEditor.js +170 -0
- package/esm/MaqlEditor/codemirror/CodeEditor.styles.d.ts +95 -0
- package/esm/MaqlEditor/codemirror/CodeEditor.styles.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/CodeEditor.styles.js +536 -0
- package/esm/MaqlEditor/codemirror/ContextMenu.d.ts +52 -0
- package/esm/MaqlEditor/codemirror/ContextMenu.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/ContextMenu.js +204 -0
- package/esm/MaqlEditor/codemirror/baseExtensions.d.ts +22 -0
- package/esm/MaqlEditor/codemirror/baseExtensions.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/baseExtensions.js +95 -0
- package/esm/MaqlEditor/codemirror/commands.d.ts +21 -0
- package/esm/MaqlEditor/codemirror/commands.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/commands.js +98 -0
- package/esm/MaqlEditor/codemirror/hooks/useAutofocus.d.ts +7 -0
- package/esm/MaqlEditor/codemirror/hooks/useAutofocus.d.ts.map +1 -0
- package/esm/MaqlEditor/{monaco → codemirror}/hooks/useAutofocus.js +4 -0
- package/esm/MaqlEditor/codemirror/lsp.d.ts +28 -0
- package/esm/MaqlEditor/codemirror/lsp.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/lsp.js +70 -0
- package/esm/MaqlEditor/codemirror/markdown.d.ts +11 -0
- package/esm/MaqlEditor/codemirror/markdown.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/markdown.js +28 -0
- package/esm/MaqlEditor/codemirror/types.d.ts +8 -0
- package/esm/MaqlEditor/codemirror/types.d.ts.map +1 -0
- package/esm/MaqlEditor/codemirror/types.js +2 -0
- package/esm/MaqlEditor/hooks/useCodeTheme.d.ts +15 -2
- package/esm/MaqlEditor/hooks/useCodeTheme.d.ts.map +1 -1
- package/esm/MaqlEditor/hooks/useCodeTheme.js +36 -43
- package/esm/MaqlEditor/hooks/useCopyToClipboard.d.ts +7 -2
- package/esm/MaqlEditor/hooks/useCopyToClipboard.d.ts.map +1 -1
- package/esm/MaqlEditor/hooks/useCopyToClipboard.js +53 -10
- package/esm/MaqlEditor/maql/MaqlEditor.d.ts +25 -9
- package/esm/MaqlEditor/maql/MaqlEditor.d.ts.map +1 -1
- package/esm/MaqlEditor/maql/MaqlEditor.js +179 -30
- package/esm/MaqlEditor/maql/MaqlEditor.styles.d.ts.map +1 -1
- package/esm/MaqlEditor/maql/MaqlEditor.styles.js +13 -17
- package/esm/MaqlEditor/maql/MaqlEditor.tooltip.d.ts.map +1 -1
- package/esm/MaqlEditor/maql/MaqlEditor.tooltip.js +15 -20
- package/esm/MaqlEditor/maql/extensions/completion.d.ts +101 -0
- package/esm/MaqlEditor/maql/extensions/completion.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/extensions/completion.js +420 -0
- package/esm/MaqlEditor/maql/extensions/decorations.d.ts +19 -0
- package/esm/MaqlEditor/maql/extensions/decorations.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/extensions/decorations.js +137 -0
- package/esm/MaqlEditor/maql/extensions/formatting.d.ts +22 -0
- package/esm/MaqlEditor/maql/extensions/formatting.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/extensions/formatting.js +78 -0
- package/esm/MaqlEditor/maql/extensions/hover.d.ts +22 -0
- package/esm/MaqlEditor/maql/extensions/hover.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/extensions/hover.js +98 -0
- package/esm/MaqlEditor/maql/extensions/semanticTokens.d.ts +15 -0
- package/esm/MaqlEditor/maql/extensions/semanticTokens.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/extensions/semanticTokens.js +79 -0
- package/esm/MaqlEditor/maql/extensions/validation.d.ts +41 -0
- package/esm/MaqlEditor/maql/extensions/validation.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/extensions/validation.js +202 -0
- package/esm/MaqlEditor/maql/hooks/hover/doHover.d.ts +19 -4
- package/esm/MaqlEditor/maql/hooks/hover/doHover.d.ts.map +1 -1
- package/esm/MaqlEditor/maql/hooks/hover/doHover.js +71 -61
- package/esm/MaqlEditor/maql/maqlLanguage.d.ts +16 -0
- package/esm/MaqlEditor/maql/maqlLanguage.d.ts.map +1 -0
- package/esm/MaqlEditor/maql/maqlLanguage.js +72 -0
- package/esm/MaqlEditor/mock/editor-shim.d.ts +7 -0
- package/esm/MaqlEditor/mock/editor-shim.d.ts.map +1 -0
- package/esm/MaqlEditor/mock/{monaco-shim.js → editor-shim.js} +27 -1
- package/esm/MaqlEditor/sql/SqlEditor.d.ts +15 -7
- package/esm/MaqlEditor/sql/SqlEditor.d.ts.map +1 -1
- package/esm/MaqlEditor/sql/SqlEditor.js +55 -30
- package/esm/MaqlEditor/sql/formatter.d.ts +6 -5
- package/esm/MaqlEditor/sql/formatter.d.ts.map +1 -1
- package/esm/MaqlEditor/sql/formatter.js +14 -14
- package/esm/MaqlEditor/sql/sqlLanguage.d.ts +3 -0
- package/esm/MaqlEditor/sql/sqlLanguage.d.ts.map +1 -0
- package/esm/MaqlEditor/sql/sqlLanguage.js +19 -0
- package/esm/MaqlEditor/statusBar/SuggestionStatusBar.d.ts +5 -2
- package/esm/MaqlEditor/statusBar/SuggestionStatusBar.d.ts.map +1 -1
- package/esm/MaqlEditor/statusBar/SuggestionStatusBar.js +20 -8
- package/esm/MetricComponent/Form/MaqlEditorField/MaqlEditorEditor.d.ts.map +1 -1
- package/esm/MetricComponent/Form/MaqlEditorField/MaqlEditorEditor.js +28 -27
- package/esm/MetricComponent/Form/MaqlEditorField/suggestionDetailsFunctions.d.ts +0 -1
- package/esm/MetricComponent/Form/MaqlEditorField/suggestionDetailsFunctions.d.ts.map +1 -1
- package/esm/MetricComponent/Form/MaqlEditorField/suggestionDetailsFunctions.js +4 -29
- package/esm/MetricComponent/Form/MaqlResult/MaqlSql.d.ts.map +1 -1
- package/esm/MetricComponent/Form/MaqlResult/MaqlSql.js +4 -2
- package/esm/MetricComponent/Form/maqlFieldFunctions.d.ts +2 -5
- package/esm/MetricComponent/Form/maqlFieldFunctions.d.ts.map +1 -1
- package/esm/MetricComponent/Form/maqlFieldFunctions.js +1 -4
- package/esm/index.d.ts +3 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/sdk-ui-metric-component.d.ts +50 -39
- package/esm/shared/permissions.d.ts.map +1 -1
- package/esm/shared/permissions.js +1 -0
- package/esm/translations/en-US.json +36 -0
- package/package.json +36 -34
- package/esm/MaqlEditor/hooks/useAutoformat.d.ts +0 -3
- package/esm/MaqlEditor/hooks/useAutoformat.d.ts.map +0 -1
- package/esm/MaqlEditor/hooks/useAutoformat.js +0 -15
- package/esm/MaqlEditor/hooks/useCleanCallback.d.ts +0 -4
- package/esm/MaqlEditor/hooks/useCleanCallback.d.ts.map +0 -1
- package/esm/MaqlEditor/hooks/useCleanCallback.js +0 -12
- package/esm/MaqlEditor/hooks/useMountCallback.d.ts +0 -13
- package/esm/MaqlEditor/hooks/useMountCallback.d.ts.map +0 -1
- package/esm/MaqlEditor/hooks/useMountCallback.js +0 -26
- package/esm/MaqlEditor/hooks/useUpdateCallback.d.ts +0 -19
- package/esm/MaqlEditor/hooks/useUpdateCallback.d.ts.map +0 -1
- package/esm/MaqlEditor/hooks/useUpdateCallback.js +0 -63
- package/esm/MaqlEditor/hooks/useValueCallbacks.d.ts +0 -6
- package/esm/MaqlEditor/hooks/useValueCallbacks.d.ts.map +0 -1
- package/esm/MaqlEditor/hooks/useValueCallbacks.js +0 -14
- package/esm/MaqlEditor/maql/formatter.d.ts +0 -6
- package/esm/MaqlEditor/maql/formatter.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/formatter.js +0 -14
- package/esm/MaqlEditor/maql/hooks/hover/useHoverEvent.d.ts +0 -4
- package/esm/MaqlEditor/maql/hooks/hover/useHoverEvent.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/hover/useHoverEvent.js +0 -32
- package/esm/MaqlEditor/maql/hooks/useAutocomplete.d.ts +0 -4
- package/esm/MaqlEditor/maql/hooks/useAutocomplete.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useAutocomplete.js +0 -60
- package/esm/MaqlEditor/maql/hooks/useDecoration.d.ts +0 -4
- package/esm/MaqlEditor/maql/hooks/useDecoration.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useDecoration.js +0 -73
- package/esm/MaqlEditor/maql/hooks/useDocumentFormatting.d.ts +0 -3
- package/esm/MaqlEditor/maql/hooks/useDocumentFormatting.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useDocumentFormatting.js +0 -29
- package/esm/MaqlEditor/maql/hooks/useHover.d.ts +0 -6
- package/esm/MaqlEditor/maql/hooks/useHover.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useHover.js +0 -77
- package/esm/MaqlEditor/maql/hooks/useLanguageConfiguration.d.ts +0 -4
- package/esm/MaqlEditor/maql/hooks/useLanguageConfiguration.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useLanguageConfiguration.js +0 -21
- package/esm/MaqlEditor/maql/hooks/useMonaco.d.ts +0 -21
- package/esm/MaqlEditor/maql/hooks/useMonaco.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useMonaco.js +0 -75
- package/esm/MaqlEditor/maql/hooks/useSemanticHighlight.d.ts +0 -4
- package/esm/MaqlEditor/maql/hooks/useSemanticHighlight.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useSemanticHighlight.js +0 -33
- package/esm/MaqlEditor/maql/hooks/useSyntaxHighlight.d.ts +0 -2
- package/esm/MaqlEditor/maql/hooks/useSyntaxHighlight.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useSyntaxHighlight.js +0 -28
- package/esm/MaqlEditor/maql/hooks/useValidation.d.ts +0 -4
- package/esm/MaqlEditor/maql/hooks/useValidation.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/hooks/useValidation.js +0 -56
- package/esm/MaqlEditor/maql/monacoConverter.d.ts +0 -80
- package/esm/MaqlEditor/maql/monacoConverter.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/monacoConverter.js +0 -528
- package/esm/MaqlEditor/maql/utils.d.ts +0 -4
- package/esm/MaqlEditor/maql/utils.d.ts.map +0 -1
- package/esm/MaqlEditor/maql/utils.js +0 -6
- package/esm/MaqlEditor/mock/monaco-shim.d.ts +0 -5
- package/esm/MaqlEditor/mock/monaco-shim.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/MonacoEditor.d.ts +0 -64
- package/esm/MaqlEditor/monaco/MonacoEditor.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/MonacoEditor.js +0 -71
- package/esm/MaqlEditor/monaco/MonacoEditor.styles.d.ts +0 -53
- package/esm/MaqlEditor/monaco/MonacoEditor.styles.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/MonacoEditor.styles.js +0 -427
- package/esm/MaqlEditor/monaco/hooks/useAutofocus.d.ts +0 -3
- package/esm/MaqlEditor/monaco/hooks/useAutofocus.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/hooks/useDefaultValue.d.ts +0 -3
- package/esm/MaqlEditor/monaco/hooks/useDefaultValue.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/hooks/useDefaultValue.js +0 -14
- package/esm/MaqlEditor/monaco/hooks/useEditorInit.d.ts +0 -3
- package/esm/MaqlEditor/monaco/hooks/useEditorInit.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/hooks/useEditorInit.js +0 -84
- package/esm/MaqlEditor/monaco/hooks/useEditorOptions.d.ts +0 -3
- package/esm/MaqlEditor/monaco/hooks/useEditorOptions.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/hooks/useEditorOptions.js +0 -51
- package/esm/MaqlEditor/monaco/hooks/useMonaco.d.ts +0 -3
- package/esm/MaqlEditor/monaco/hooks/useMonaco.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/hooks/useMonaco.js +0 -24
- package/esm/MaqlEditor/monaco/monacoContributions.d.ts +0 -74
- package/esm/MaqlEditor/monaco/monacoContributions.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/monacoContributions.js +0 -88
- package/esm/MaqlEditor/monaco/monacoWorkers.d.ts +0 -53
- package/esm/MaqlEditor/monaco/monacoWorkers.d.ts.map +0 -1
- package/esm/MaqlEditor/monaco/monacoWorkers.js +0 -176
- package/esm/MaqlEditor/sql/hooks/useDocumentFormatting.d.ts +0 -2
- package/esm/MaqlEditor/sql/hooks/useDocumentFormatting.d.ts.map +0 -1
- package/esm/MaqlEditor/sql/hooks/useDocumentFormatting.js +0 -26
- package/esm/MaqlEditor/sql/hooks/useLanguageConfiguration.d.ts +0 -4
- package/esm/MaqlEditor/sql/hooks/useLanguageConfiguration.d.ts.map +0 -1
- package/esm/MaqlEditor/sql/hooks/useLanguageConfiguration.js +0 -29
- package/esm/MaqlEditor/sql/hooks/useMonaco.d.ts +0 -14
- package/esm/MaqlEditor/sql/hooks/useMonaco.d.ts.map +0 -1
- package/esm/MaqlEditor/sql/hooks/useMonaco.js +0 -26
- package/esm/MaqlEditor/sql/hooks/useSyntaxHighlight.d.ts +0 -2
- package/esm/MaqlEditor/sql/hooks/useSyntaxHighlight.d.ts.map +0 -1
- package/esm/MaqlEditor/sql/hooks/useSyntaxHighlight.js +0 -796
- package/esm/MaqlEditor/sql/utils.d.ts +0 -4
- package/esm/MaqlEditor/sql/utils.d.ts.map +0 -1
- package/esm/MaqlEditor/sql/utils.js +0 -6
- package/worker/monaco-editor-worker.js +0 -33
- package/worker/monaco-editor-worker.source.js +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { type Completion } from "@codemirror/autocomplete";
|
|
2
|
+
import { type Extension } from "@codemirror/state";
|
|
3
|
+
import { EditorView } from "@codemirror/view";
|
|
4
|
+
import { type CompletionItem, CompletionItemKind, type CompletionList } from "vscode-languageserver-types";
|
|
5
|
+
import { type MaqlLanguageService } from "@gooddata/sdk-maql-language-server";
|
|
6
|
+
export interface IMaqlCompletionOptions {
|
|
7
|
+
languageService: MaqlLanguageService;
|
|
8
|
+
/**
|
|
9
|
+
* Characters that open the suggestions on their own, from the language service capabilities.
|
|
10
|
+
*/
|
|
11
|
+
triggerCharacters: readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* Receives the raw list the language service answered with, so the editor can tell the user
|
|
14
|
+
* when it is incomplete. Null when the list closes.
|
|
15
|
+
*/
|
|
16
|
+
onList: (list: CompletionList | null) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Called when the user shows or hides the documentation of the suggestions.
|
|
19
|
+
*/
|
|
20
|
+
onDocsToggle?: (view: EditorView, visible: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The icon class of a completion, keyed the way the editor icons are.
|
|
24
|
+
*/
|
|
25
|
+
export declare function completionType(kind: CompletionItemKind | undefined): string;
|
|
26
|
+
/**
|
|
27
|
+
* The protocol writes tab stops as `$1` and the final cursor as `$0`; CodeMirror wants them in braces,
|
|
28
|
+
* with the final cursor as an unnamed field.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toCodeMirrorSnippet(text: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* The text a completion replaces. The language service computed its edit for the document it was
|
|
33
|
+
* asked about; the list stays open while the user types on, so the typed characters are taken in
|
|
34
|
+
* as well, or they would stay behind the inserted text.
|
|
35
|
+
*
|
|
36
|
+
* @param from - start of the word the editor is completing
|
|
37
|
+
* @param to - the cursor
|
|
38
|
+
*/
|
|
39
|
+
export declare function completionSpan(edit: {
|
|
40
|
+
from: number;
|
|
41
|
+
to: number;
|
|
42
|
+
} | undefined, from: number, to: number): {
|
|
43
|
+
from: number;
|
|
44
|
+
to: number;
|
|
45
|
+
};
|
|
46
|
+
export interface IFuzzyMatch {
|
|
47
|
+
/**
|
|
48
|
+
* Pairs of offsets into the text, one per matched run.
|
|
49
|
+
*/
|
|
50
|
+
positions: number[];
|
|
51
|
+
/**
|
|
52
|
+
* Higher is better: a run of the typed text at the start of a word, a run, then scattered characters.
|
|
53
|
+
*/
|
|
54
|
+
score: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Matches the typed text against the filter text of an item the way the Monaco editor did: the
|
|
58
|
+
* characters in order, ignoring case, and the first letter or digit of them at the start of a
|
|
59
|
+
* word. Typing `me` or `{me` finds `{ metric / ... }`, not `{ dataset / timeline }`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function fuzzyMatch(pattern: string, text: string): IFuzzyMatch | null;
|
|
62
|
+
/**
|
|
63
|
+
* Where the typed characters sit in the shown label, as pairs of offsets. The match is made on
|
|
64
|
+
* the filter text of an item, which carries the identifier besides the title; the highlight goes
|
|
65
|
+
* on the label the user sees. A run of the typed text wins over scattered characters.
|
|
66
|
+
*
|
|
67
|
+
* @param matched - the offsets matched in the filter text
|
|
68
|
+
*/
|
|
69
|
+
export declare function matchInDisplayLabel(label: string, displayLabel: string, matched: readonly number[]): number[];
|
|
70
|
+
/**
|
|
71
|
+
* A completion with the offsets to highlight in its label, computed by the editor's own filter.
|
|
72
|
+
*/
|
|
73
|
+
interface IMaqlCompletion extends Completion {
|
|
74
|
+
matched: number[];
|
|
75
|
+
/**
|
|
76
|
+
* The type of the object, such as the type of a parameter, shown dimmed after the label on
|
|
77
|
+
* every row, the way Monaco showed the label description.
|
|
78
|
+
*/
|
|
79
|
+
typeLabel?: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The translation of a label of the suggestions, from the phrases of the editor state.
|
|
83
|
+
*/
|
|
84
|
+
type Phrase = (text: string) => string;
|
|
85
|
+
/**
|
|
86
|
+
* The items that match the typed text, best matches first and the language service's order
|
|
87
|
+
* among equals.
|
|
88
|
+
*/
|
|
89
|
+
export declare function filterItems(items: readonly CompletionItem[], typed: string, languageService: MaqlLanguageService, phrase?: Phrase): IMaqlCompletion[];
|
|
90
|
+
/**
|
|
91
|
+
* Shows or hides the documentation of the suggestions. The choice sticks for the life of the editor,
|
|
92
|
+
* the way it does in Monaco.
|
|
93
|
+
*/
|
|
94
|
+
export declare const setDocsVisible: import("@codemirror/state").StateEffectType<boolean>;
|
|
95
|
+
/**
|
|
96
|
+
* Suggestions from the language service, filtered by the editor as the user types, with their
|
|
97
|
+
* documentation resolved when an item is selected and shown on demand.
|
|
98
|
+
*/
|
|
99
|
+
export declare function maqlCompletion({ languageService, triggerCharacters, onList, onDocsToggle, }: IMaqlCompletionOptions): Extension;
|
|
100
|
+
export {};
|
|
101
|
+
//# sourceMappingURL=completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../../src/MaqlEditor/maql/extensions/completion.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,UAAU,EAUlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAmB,KAAK,SAAS,EAAiC,MAAM,mBAAmB,CAAC;AACnG,OAAO,EAAE,UAAU,EAAU,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACH,KAAK,cAAc,EACnB,kBAAkB,EAClB,KAAK,cAAc,EAItB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAc9E,MAAM,WAAW,sBAAsB;IACnC,eAAe,EAAE,mBAAmB,CAAC;IACrC;;OAEG;IACH,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC/D;AAQD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,SAAS,GAAG,MAAM,CA0B3E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC1B,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EAC9C,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACX;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAK9B;AAED,MAAM,WAAW,WAAW;IACxB;;OAEG;IACH,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACjB;AAcD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAoC5E;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,SAAS,MAAM,EAAE,GAC3B,MAAM,EAAE,CA+BV;AA8CD;;GAEG;AACH,UAAU,eAAgB,SAAQ,UAAU;IACxC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAYD;;GAEG;AACH,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;AAuBvC;;;GAGG;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,mBAAmB,EACpC,MAAM,GAAE,MAAuB,GAChC,eAAe,EAAE,CAsCnB;AAMD;;;GAGG;AACH,eAAO,MAAM,cAAc,sDAAgC,CAAC;AAoG5D;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAC3B,eAAe,EACf,iBAAiB,EACjB,MAAM,EACN,YAAY,GACf,EAAE,sBAAsB,GAAG,SAAS,CAgGpC"}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
// (C) 2021-2026 GoodData Corporation
|
|
2
|
+
import { acceptCompletion, autocompletion, completionStatus, pickedCompletion, snippet, startCompletion, } from "@codemirror/autocomplete";
|
|
3
|
+
import { Prec, StateEffect, StateField } from "@codemirror/state";
|
|
4
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
5
|
+
import { CompletionItemKind, InsertTextFormat, TextEdit, } from "vscode-languageserver-types";
|
|
6
|
+
import { DOCS_CLASS, DOCS_OPEN_CLASS, DOCS_PANE_CLASS, DOCS_TOGGLE_CLASS, SUGGEST_CLASS, TYPE_LABEL_CLASS, } from "../../codemirror/CodeEditor.styles.js";
|
|
7
|
+
import { createDocument, offsetToPosition, rangeToSpan, textEditsToChanges } from "../../codemirror/lsp.js";
|
|
8
|
+
import { renderMarkdown } from "../../codemirror/markdown.js";
|
|
9
|
+
import { LANGUAGE } from "../constants.js";
|
|
10
|
+
/**
|
|
11
|
+
* The text before the cursor the suggestions are filtered by: everything since the last space or
|
|
12
|
+
* bracket, so an operator or an opening brace counts as well, the way the Monaco editor behaved.
|
|
13
|
+
*/
|
|
14
|
+
const WORD = /[^\s(),";]*$/;
|
|
15
|
+
/**
|
|
16
|
+
* The icon class of a completion, keyed the way the editor icons are.
|
|
17
|
+
*/
|
|
18
|
+
export function completionType(kind) {
|
|
19
|
+
switch (kind) {
|
|
20
|
+
case CompletionItemKind.Field:
|
|
21
|
+
return "fact";
|
|
22
|
+
case CompletionItemKind.Variable:
|
|
23
|
+
return "metric";
|
|
24
|
+
case CompletionItemKind.Constant:
|
|
25
|
+
return "dataset";
|
|
26
|
+
case CompletionItemKind.Text:
|
|
27
|
+
return "label";
|
|
28
|
+
case CompletionItemKind.Enum:
|
|
29
|
+
case CompletionItemKind.EnumMember:
|
|
30
|
+
return "attribute";
|
|
31
|
+
case CompletionItemKind.Keyword:
|
|
32
|
+
return "keyword";
|
|
33
|
+
case CompletionItemKind.Function:
|
|
34
|
+
return "function";
|
|
35
|
+
case CompletionItemKind.Operator:
|
|
36
|
+
return "operator";
|
|
37
|
+
case CompletionItemKind.Value:
|
|
38
|
+
return "value";
|
|
39
|
+
case CompletionItemKind.Snippet:
|
|
40
|
+
return "snippet";
|
|
41
|
+
default:
|
|
42
|
+
return "text";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The protocol writes tab stops as `$1` and the final cursor as `$0`; CodeMirror wants them in braces,
|
|
47
|
+
* with the final cursor as an unnamed field.
|
|
48
|
+
*/
|
|
49
|
+
export function toCodeMirrorSnippet(text) {
|
|
50
|
+
return text.replace(/\$(\d+)/g, (_match, index) => (index === "0" ? "${}" : `\${${index}}`));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The text a completion replaces. The language service computed its edit for the document it was
|
|
54
|
+
* asked about; the list stays open while the user types on, so the typed characters are taken in
|
|
55
|
+
* as well, or they would stay behind the inserted text.
|
|
56
|
+
*
|
|
57
|
+
* @param from - start of the word the editor is completing
|
|
58
|
+
* @param to - the cursor
|
|
59
|
+
*/
|
|
60
|
+
export function completionSpan(edit, from, to) {
|
|
61
|
+
if (!edit) {
|
|
62
|
+
return { from, to };
|
|
63
|
+
}
|
|
64
|
+
return { from: Math.min(edit.from, from), to: Math.max(edit.to, to) };
|
|
65
|
+
}
|
|
66
|
+
function isWordStart(text, index) {
|
|
67
|
+
if (index === 0) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
const previous = text[index - 1];
|
|
71
|
+
const current = text[index];
|
|
72
|
+
if (!/[A-Za-z0-9]/.test(previous)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return previous !== previous.toUpperCase() && current !== current.toLowerCase();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Matches the typed text against the filter text of an item the way the Monaco editor did: the
|
|
79
|
+
* characters in order, ignoring case, and the first letter or digit of them at the start of a
|
|
80
|
+
* word. Typing `me` or `{me` finds `{ metric / ... }`, not `{ dataset / timeline }`.
|
|
81
|
+
*/
|
|
82
|
+
export function fuzzyMatch(pattern, text) {
|
|
83
|
+
if (!pattern) {
|
|
84
|
+
return { positions: [], score: 0 };
|
|
85
|
+
}
|
|
86
|
+
const needle = pattern.toLowerCase();
|
|
87
|
+
const haystack = text.toLowerCase();
|
|
88
|
+
// Punctuation such as `{` or `+` may sit anywhere; the word-start rule is for what follows it.
|
|
89
|
+
const anchor = needle.search(/[a-z0-9]/);
|
|
90
|
+
let run = haystack.indexOf(needle);
|
|
91
|
+
while (run >= 0 && anchor >= 0 && !isWordStart(text, run + anchor)) {
|
|
92
|
+
run = haystack.indexOf(needle, run + 1);
|
|
93
|
+
}
|
|
94
|
+
if (run >= 0) {
|
|
95
|
+
return { positions: [run, run + needle.length], score: 3 };
|
|
96
|
+
}
|
|
97
|
+
const positions = [];
|
|
98
|
+
let from = 0;
|
|
99
|
+
for (let index = 0; index < needle.length; index += 1) {
|
|
100
|
+
let at = haystack.indexOf(needle[index], from);
|
|
101
|
+
while (at >= 0 && index === anchor && !isWordStart(text, at)) {
|
|
102
|
+
at = haystack.indexOf(needle[index], at + 1);
|
|
103
|
+
}
|
|
104
|
+
if (at < 0) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
if (positions.length && positions[positions.length - 1] === at) {
|
|
108
|
+
positions[positions.length - 1] = at + 1;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
positions.push(at, at + 1);
|
|
112
|
+
}
|
|
113
|
+
from = at + 1;
|
|
114
|
+
}
|
|
115
|
+
const firstRun = haystack.indexOf(needle);
|
|
116
|
+
return { positions, score: firstRun >= 0 ? 2 : 1 };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Where the typed characters sit in the shown label, as pairs of offsets. The match is made on
|
|
120
|
+
* the filter text of an item, which carries the identifier besides the title; the highlight goes
|
|
121
|
+
* on the label the user sees. A run of the typed text wins over scattered characters.
|
|
122
|
+
*
|
|
123
|
+
* @param matched - the offsets matched in the filter text
|
|
124
|
+
*/
|
|
125
|
+
export function matchInDisplayLabel(label, displayLabel, matched) {
|
|
126
|
+
let typed = "";
|
|
127
|
+
for (let i = 0; i + 1 < matched.length; i += 2) {
|
|
128
|
+
typed += label.slice(matched[i], matched[i + 1]);
|
|
129
|
+
}
|
|
130
|
+
const needle = typed.toLowerCase();
|
|
131
|
+
if (!needle) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const haystack = displayLabel.toLowerCase();
|
|
135
|
+
const run = haystack.indexOf(needle);
|
|
136
|
+
if (run >= 0) {
|
|
137
|
+
return [run, run + needle.length];
|
|
138
|
+
}
|
|
139
|
+
const result = [];
|
|
140
|
+
let from = 0;
|
|
141
|
+
for (const char of needle) {
|
|
142
|
+
const at = haystack.indexOf(char, from);
|
|
143
|
+
if (at < 0) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
if (result.length && result[result.length - 1] === at) {
|
|
147
|
+
result[result.length - 1] = at + 1;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
result.push(at, at + 1);
|
|
151
|
+
}
|
|
152
|
+
from = at + 1;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function applyCompletion(view, completion, item, from, to) {
|
|
157
|
+
// The read-only facet stops the user's edits, not a dispatched change.
|
|
158
|
+
if (view.state.readOnly) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const doc = view.state.doc;
|
|
162
|
+
const edit = TextEdit.is(item.textEdit) ? item.textEdit : undefined;
|
|
163
|
+
const span = completionSpan(edit ? rangeToSpan(doc, edit.range) : undefined, from, to);
|
|
164
|
+
const text = edit?.newText ?? item.insertText ?? item.label;
|
|
165
|
+
const additional = item.additionalTextEdits ? textEditsToChanges(doc, item.additionalTextEdits) : [];
|
|
166
|
+
if (item.insertTextFormat === InsertTextFormat.Snippet) {
|
|
167
|
+
// The snippet is placed after the additional edits moved the text, so its span is mapped
|
|
168
|
+
// through them.
|
|
169
|
+
let snippetFrom = span.from;
|
|
170
|
+
let snippetTo = span.to;
|
|
171
|
+
if (additional.length) {
|
|
172
|
+
const changes = view.state.changes(additional);
|
|
173
|
+
view.dispatch({ changes });
|
|
174
|
+
snippetFrom = changes.mapPos(span.from, 1);
|
|
175
|
+
snippetTo = Math.max(snippetFrom, changes.mapPos(span.to, -1));
|
|
176
|
+
}
|
|
177
|
+
snippet(toCodeMirrorSnippet(text))(view, completion, snippetFrom, snippetTo);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const specs = [{ from: span.from, to: span.to, insert: text }, ...additional];
|
|
181
|
+
const changes = view.state.changes(specs);
|
|
182
|
+
view.dispatch({
|
|
183
|
+
changes,
|
|
184
|
+
// The cursor goes after the inserted text, wherever the additional edits moved it.
|
|
185
|
+
selection: { anchor: changes.mapPos(span.to, 1) },
|
|
186
|
+
annotations: pickedCompletion.of(completion),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
// An accepted reference may open a longer one, so the suggestions reopen right away.
|
|
190
|
+
startCompletion(view);
|
|
191
|
+
}
|
|
192
|
+
function renderTypeLabel(completion) {
|
|
193
|
+
if (!completion.typeLabel) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const span = document.createElement("span");
|
|
197
|
+
span.className = TYPE_LABEL_CLASS;
|
|
198
|
+
span.textContent = completion.typeLabel;
|
|
199
|
+
return span;
|
|
200
|
+
}
|
|
201
|
+
function toCompletion(item, matched, languageService, phrase) {
|
|
202
|
+
return {
|
|
203
|
+
label: item.filterText ?? item.label,
|
|
204
|
+
displayLabel: item.label,
|
|
205
|
+
// Shown dimmed at the right of the row while the documentation is closed, the way Monaco
|
|
206
|
+
// shows it; the documentation pane repeats it in its header.
|
|
207
|
+
detail: item.detail,
|
|
208
|
+
sortText: item.sortText,
|
|
209
|
+
type: completionType(item.kind),
|
|
210
|
+
matched,
|
|
211
|
+
typeLabel: item.labelDetails?.description,
|
|
212
|
+
apply: (view, completion, from, to) => applyCompletion(view, completion, item, from, to),
|
|
213
|
+
info: () => resolveInfo(item, languageService, phrase),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The items that match the typed text, best matches first and the language service's order
|
|
218
|
+
* among equals.
|
|
219
|
+
*/
|
|
220
|
+
export function filterItems(items, typed, languageService, phrase = (text) => text) {
|
|
221
|
+
const scored = [];
|
|
222
|
+
for (const item of items) {
|
|
223
|
+
const text = item.filterText ?? item.label;
|
|
224
|
+
const match = fuzzyMatch(typed, text);
|
|
225
|
+
if (!match) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
scored.push({
|
|
229
|
+
completion: toCompletion(item, matchInDisplayLabel(text, item.label, match.positions), languageService, phrase),
|
|
230
|
+
score: match.score,
|
|
231
|
+
sortText: (item.sortText ?? item.label).toLowerCase(),
|
|
232
|
+
item,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// The order Monaco used among equal matches: the sort text, then the label, then the kind, so
|
|
236
|
+
// the overloads of a function, which share a sort text, come in the order of their signatures.
|
|
237
|
+
return scored
|
|
238
|
+
.sort((a, b) => b.score - a.score ||
|
|
239
|
+
compare(a.sortText, b.sortText) ||
|
|
240
|
+
compare(a.item.label, b.item.label) ||
|
|
241
|
+
(a.item.kind ?? 0) - (b.item.kind ?? 0))
|
|
242
|
+
.map((entry) => entry.completion);
|
|
243
|
+
}
|
|
244
|
+
function compare(a, b) {
|
|
245
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Shows or hides the documentation of the suggestions. The choice sticks for the life of the editor,
|
|
249
|
+
* the way it does in Monaco.
|
|
250
|
+
*/
|
|
251
|
+
export const setDocsVisible = StateEffect.define();
|
|
252
|
+
const docsVisible = StateField.define({
|
|
253
|
+
create: () => false,
|
|
254
|
+
update(value, transaction) {
|
|
255
|
+
for (const effect of transaction.effects) {
|
|
256
|
+
if (effect.is(setDocsVisible)) {
|
|
257
|
+
return effect.value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return value;
|
|
261
|
+
},
|
|
262
|
+
// The documentation pane is rendered whenever an item has one, so it is laid out and placed
|
|
263
|
+
// by the time the user asks for it; the class is what shows it.
|
|
264
|
+
provide: (field) => EditorView.editorAttributes.from(field, (visible) => ({ class: visible ? DOCS_OPEN_CLASS : "" })),
|
|
265
|
+
});
|
|
266
|
+
function toggleDocs(view) {
|
|
267
|
+
view.dispatch({ effects: setDocsVisible.of(!view.state.field(docsVisible)) });
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* The editor an element of a tooltip belongs to. Tooltips sit beside the content, outside what
|
|
271
|
+
* `EditorView.findFromDOM` searches, so the lookup starts from the editor element.
|
|
272
|
+
*/
|
|
273
|
+
function viewOf(element) {
|
|
274
|
+
const editor = element.closest(".cm-editor");
|
|
275
|
+
return editor ? EditorView.findFromDOM(editor) : null;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The `?` on the selected row: it opens and closes the documentation. The row itself accepts the
|
|
279
|
+
* completion on mousedown, so the event stops here.
|
|
280
|
+
*/
|
|
281
|
+
function renderDocsToggle(view) {
|
|
282
|
+
const button = document.createElement("button");
|
|
283
|
+
button.type = "button";
|
|
284
|
+
button.className = DOCS_TOGGLE_CLASS;
|
|
285
|
+
button.setAttribute("aria-label", view.state.phrase("Documentation"));
|
|
286
|
+
button.textContent = "?";
|
|
287
|
+
button.addEventListener("mousedown", (event) => {
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
event.stopPropagation();
|
|
290
|
+
toggleDocs(view);
|
|
291
|
+
});
|
|
292
|
+
return button;
|
|
293
|
+
}
|
|
294
|
+
function markdownOf(documentation) {
|
|
295
|
+
const markdown = typeof documentation === "string" ? documentation : documentation?.value;
|
|
296
|
+
return markdown ?? "";
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The documentation pane: the detail of the item (its identifier and description) in the header,
|
|
300
|
+
* with a close button, and the resolved documentation below.
|
|
301
|
+
*/
|
|
302
|
+
function renderDocsPane(detail, markdown, phrase) {
|
|
303
|
+
const pane = document.createElement("div");
|
|
304
|
+
pane.className = DOCS_PANE_CLASS;
|
|
305
|
+
// A click in the pane must not take the focus from the editor, which would close the list.
|
|
306
|
+
pane.addEventListener("mousedown", (event) => event.preventDefault());
|
|
307
|
+
const header = document.createElement("div");
|
|
308
|
+
header.className = "header";
|
|
309
|
+
const text = document.createElement("p");
|
|
310
|
+
text.textContent = detail ?? "";
|
|
311
|
+
header.appendChild(text);
|
|
312
|
+
const close = document.createElement("button");
|
|
313
|
+
close.type = "button";
|
|
314
|
+
close.className = "close";
|
|
315
|
+
close.textContent = "×";
|
|
316
|
+
close.addEventListener("click", () => {
|
|
317
|
+
viewOf(close)?.dispatch({ effects: setDocsVisible.of(false) });
|
|
318
|
+
});
|
|
319
|
+
close.setAttribute("aria-label", phrase("Close"));
|
|
320
|
+
header.appendChild(close);
|
|
321
|
+
pane.appendChild(header);
|
|
322
|
+
const rendered = markdown ? renderMarkdown(markdown, DOCS_CLASS) : null;
|
|
323
|
+
if (rendered) {
|
|
324
|
+
pane.appendChild(rendered.dom);
|
|
325
|
+
}
|
|
326
|
+
return { dom: pane, destroy: () => rendered?.destroy() };
|
|
327
|
+
}
|
|
328
|
+
async function resolveInfo(item, languageService, phrase) {
|
|
329
|
+
const resolved = await languageService.doCompletionResolve(item);
|
|
330
|
+
const markdown = markdownOf(resolved.documentation);
|
|
331
|
+
return item.detail || markdown ? renderDocsPane(item.detail, markdown, phrase) : null;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Suggestions from the language service, filtered by the editor as the user types, with their
|
|
335
|
+
* documentation resolved when an item is selected and shown on demand.
|
|
336
|
+
*/
|
|
337
|
+
export function maqlCompletion({ languageService, triggerCharacters, onList, onDocsToggle, }) {
|
|
338
|
+
let pendingRequests = 0;
|
|
339
|
+
const endsWithTrigger = (typed) => typed.length > 0 && triggerCharacters.includes(typed.slice(-1));
|
|
340
|
+
const source = async (context) => {
|
|
341
|
+
// Nothing to suggest where nothing can be written, the way Monaco behaved.
|
|
342
|
+
if (context.state.readOnly) {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
const word = context.matchBefore(WORD);
|
|
346
|
+
const charBefore = context.state.sliceDoc(Math.max(context.pos - 1, 0), context.pos);
|
|
347
|
+
const typing = word !== null && word.from < word.to;
|
|
348
|
+
if (!context.explicit && !typing && !triggerCharacters.includes(charBefore)) {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
const document = createDocument(context.state, LANGUAGE);
|
|
352
|
+
const position = offsetToPosition(context.state.doc, context.pos);
|
|
353
|
+
onList({ isIncomplete: false, items: [] });
|
|
354
|
+
pendingRequests += 1;
|
|
355
|
+
try {
|
|
356
|
+
const list = await languageService.doCompletion(document, position);
|
|
357
|
+
if (pendingRequests === 1) {
|
|
358
|
+
onList(list);
|
|
359
|
+
}
|
|
360
|
+
// The list is filtered here rather than by CodeMirror, whose matcher takes any
|
|
361
|
+
// character order and, for a single character, only the first one of the label.
|
|
362
|
+
const build = (typed, from) => ({
|
|
363
|
+
from,
|
|
364
|
+
options: filterItems(list.items, typed, languageService, (text) => context.state.phrase(text)),
|
|
365
|
+
filter: false,
|
|
366
|
+
getMatch: (completion) => completion.matched,
|
|
367
|
+
// Typing on refilters the same answer. A trigger character changes what the
|
|
368
|
+
// language service would offer, and a truncated list has to be asked for again,
|
|
369
|
+
// or the objects beyond the first page never show up.
|
|
370
|
+
update: (_current, nextFrom, _to, nextContext) => {
|
|
371
|
+
const nextTyped = nextContext.state.sliceDoc(nextFrom, nextContext.pos);
|
|
372
|
+
if (list.isIncomplete || endsWithTrigger(nextTyped)) {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
return build(nextTyped, nextFrom);
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
return build(word?.text ?? "", word?.from ?? context.pos);
|
|
379
|
+
}
|
|
380
|
+
finally {
|
|
381
|
+
pendingRequests -= 1;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const listener = EditorView.updateListener.of((update) => {
|
|
385
|
+
const was = completionStatus(update.startState);
|
|
386
|
+
const is = completionStatus(update.state);
|
|
387
|
+
if (was !== null && is === null) {
|
|
388
|
+
onList(null);
|
|
389
|
+
}
|
|
390
|
+
// The field is missing from the start state of the transaction that adds this extension.
|
|
391
|
+
const docsWere = update.startState.field(docsVisible, false) ?? false;
|
|
392
|
+
const docsAre = update.state.field(docsVisible);
|
|
393
|
+
if (docsWere !== docsAre) {
|
|
394
|
+
onDocsToggle?.(update.view, docsAre);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
return [
|
|
398
|
+
docsVisible,
|
|
399
|
+
autocompletion({
|
|
400
|
+
override: [source],
|
|
401
|
+
activateOnTyping: true,
|
|
402
|
+
// Monaco accepted a suggestion the moment the list opened; the editor would otherwise
|
|
403
|
+
// let Enter and Tab through for the first 75 ms.
|
|
404
|
+
interactionDelay: 0,
|
|
405
|
+
icons: true,
|
|
406
|
+
tooltipClass: () => SUGGEST_CLASS,
|
|
407
|
+
addToOptions: [
|
|
408
|
+
{ render: (completion) => renderTypeLabel(completion), position: 60 },
|
|
409
|
+
{ render: (_completion, _state, view) => renderDocsToggle(view), position: 90 },
|
|
410
|
+
],
|
|
411
|
+
}),
|
|
412
|
+
// Above the standard bindings: Mod-i selects the enclosing syntax there, and Tab indents.
|
|
413
|
+
// While an input method composes text, Tab is left to the base binding, which ignores it.
|
|
414
|
+
Prec.high(keymap.of([
|
|
415
|
+
{ key: "Mod-i", run: startCompletion },
|
|
416
|
+
{ key: "Tab", run: (view) => (view.compositionStarted ? false : acceptCompletion(view)) },
|
|
417
|
+
])),
|
|
418
|
+
listener,
|
|
419
|
+
];
|
|
420
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Extension, type Text } from "@codemirror/state";
|
|
2
|
+
import { type DecorationSet } from "@codemirror/view";
|
|
3
|
+
import { type IDecoration, type MaqlLanguageService } from "@gooddata/sdk-maql-language-server";
|
|
4
|
+
import { type ISpan } from "../../codemirror/lsp.js";
|
|
5
|
+
export declare function buildDecorations(doc: Text, decorations: readonly IDecoration[]): DecorationSet;
|
|
6
|
+
/**
|
|
7
|
+
* Highlights the reference the metric tooltip is open for.
|
|
8
|
+
*/
|
|
9
|
+
export declare const setHoveredSpan: import("@codemirror/state").StateEffectType<ISpan | null>;
|
|
10
|
+
/**
|
|
11
|
+
* The decoration state. Add {@link decorationsPlugin} to keep it filled.
|
|
12
|
+
*/
|
|
13
|
+
export declare function maqlDecorations(): Extension;
|
|
14
|
+
/**
|
|
15
|
+
* Asks the language service for the references in the code and decorates them, on every change.
|
|
16
|
+
* With `enabled` off the editor shows no badges.
|
|
17
|
+
*/
|
|
18
|
+
export declare function decorationsPlugin(languageService: MaqlLanguageService, enabled: boolean): Extension;
|
|
19
|
+
//# sourceMappingURL=decorations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorations.d.ts","sourceRoot":"","sources":["../../../../src/MaqlEditor/maql/extensions/decorations.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAA2B,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACvF,OAAO,EAEH,KAAK,aAAa,EAKrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAGhG,OAAO,EAAE,KAAK,KAAK,EAA+B,MAAM,yBAAyB,CAAC;AA+BlF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,WAAW,EAAE,GAAG,aAAa,CAkB9F;AAiBD;;GAEG;AACH,eAAO,MAAM,cAAc,2DAAqC,CAAC;AAoBjE;;GAEG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,GAAG,SAAS,CAkDnG"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// (C) 2026 GoodData Corporation
|
|
2
|
+
import { StateEffect, StateField } from "@codemirror/state";
|
|
3
|
+
import { Decoration, EditorView, ViewPlugin, WidgetType, } from "@codemirror/view";
|
|
4
|
+
import { DecoratorHovered, Decorators } from "../../codemirror/CodeEditor.styles.js";
|
|
5
|
+
import { createDocument, rangeToSpan } from "../../codemirror/lsp.js";
|
|
6
|
+
import { LANGUAGE } from "../constants.js";
|
|
7
|
+
/**
|
|
8
|
+
* The badge with the title of a referenced object, rendered before the reference.
|
|
9
|
+
*/
|
|
10
|
+
class LabelWidget extends WidgetType {
|
|
11
|
+
label;
|
|
12
|
+
className;
|
|
13
|
+
constructor(label, className) {
|
|
14
|
+
super();
|
|
15
|
+
this.label = label;
|
|
16
|
+
this.className = className;
|
|
17
|
+
}
|
|
18
|
+
eq(other) {
|
|
19
|
+
return other.label === this.label && other.className === this.className;
|
|
20
|
+
}
|
|
21
|
+
toDOM() {
|
|
22
|
+
const span = document.createElement("span");
|
|
23
|
+
span.className = this.className;
|
|
24
|
+
// The spaces stand in for padding, the way the Monaco decoration rendered the badge.
|
|
25
|
+
span.textContent = ` ${this.label} `;
|
|
26
|
+
return span;
|
|
27
|
+
}
|
|
28
|
+
ignoreEvent() {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function buildDecorations(doc, decorations) {
|
|
33
|
+
const ranges = decorations.flatMap((decoration) => {
|
|
34
|
+
const { from, to } = rangeToSpan(doc, decoration.range);
|
|
35
|
+
if (to <= from) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const def = Decorators[decoration.options.type] || Decorators["default"];
|
|
39
|
+
return [
|
|
40
|
+
Decoration.widget({
|
|
41
|
+
widget: new LabelWidget(decoration.options.label, def.decorator.join(" ")),
|
|
42
|
+
side: -1,
|
|
43
|
+
}).range(from),
|
|
44
|
+
Decoration.mark({ class: def.decoratorItem.join(" ") }).range(from, to),
|
|
45
|
+
];
|
|
46
|
+
});
|
|
47
|
+
return Decoration.set(ranges, true);
|
|
48
|
+
}
|
|
49
|
+
const setDecorations = StateEffect.define();
|
|
50
|
+
const decorationsField = StateField.define({
|
|
51
|
+
create: () => Decoration.none,
|
|
52
|
+
update(value, transaction) {
|
|
53
|
+
for (const effect of transaction.effects) {
|
|
54
|
+
if (effect.is(setDecorations)) {
|
|
55
|
+
return effect.value;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return transaction.docChanged ? value.map(transaction.changes) : value;
|
|
59
|
+
},
|
|
60
|
+
provide: (field) => EditorView.decorations.from(field),
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* Highlights the reference the metric tooltip is open for.
|
|
64
|
+
*/
|
|
65
|
+
export const setHoveredSpan = StateEffect.define();
|
|
66
|
+
const hoveredDecoration = Decoration.mark({ class: DecoratorHovered });
|
|
67
|
+
const hoveredField = StateField.define({
|
|
68
|
+
create: () => Decoration.none,
|
|
69
|
+
update(value, transaction) {
|
|
70
|
+
for (const effect of transaction.effects) {
|
|
71
|
+
if (effect.is(setHoveredSpan)) {
|
|
72
|
+
const span = effect.value;
|
|
73
|
+
return span && span.to > span.from
|
|
74
|
+
? Decoration.set([hoveredDecoration.range(span.from, span.to)])
|
|
75
|
+
: Decoration.none;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return transaction.docChanged ? value.map(transaction.changes) : value;
|
|
79
|
+
},
|
|
80
|
+
provide: (field) => EditorView.decorations.from(field),
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* The decoration state. Add {@link decorationsPlugin} to keep it filled.
|
|
84
|
+
*/
|
|
85
|
+
export function maqlDecorations() {
|
|
86
|
+
return [decorationsField, hoveredField];
|
|
87
|
+
}
|
|
88
|
+
const REQUEST_DELAY_MS = 150;
|
|
89
|
+
/**
|
|
90
|
+
* Asks the language service for the references in the code and decorates them, on every change.
|
|
91
|
+
* With `enabled` off the editor shows no badges.
|
|
92
|
+
*/
|
|
93
|
+
export function decorationsPlugin(languageService, enabled) {
|
|
94
|
+
if (!enabled) {
|
|
95
|
+
return ViewPlugin.define((view) => {
|
|
96
|
+
// Dispatching inside the constructor is not allowed; clear once the view settles.
|
|
97
|
+
setTimeout(() => view.dispatch({ effects: setDecorations.of(Decoration.none) }), 0);
|
|
98
|
+
return {};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return ViewPlugin.fromClass(class {
|
|
102
|
+
view;
|
|
103
|
+
timer;
|
|
104
|
+
destroyed = false;
|
|
105
|
+
constructor(view) {
|
|
106
|
+
this.view = view;
|
|
107
|
+
this.schedule(0);
|
|
108
|
+
}
|
|
109
|
+
update(update) {
|
|
110
|
+
if (update.docChanged) {
|
|
111
|
+
this.schedule(REQUEST_DELAY_MS);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
destroy() {
|
|
115
|
+
this.destroyed = true;
|
|
116
|
+
window.clearTimeout(this.timer);
|
|
117
|
+
}
|
|
118
|
+
schedule(delay) {
|
|
119
|
+
window.clearTimeout(this.timer);
|
|
120
|
+
this.timer = window.setTimeout(() => this.request(), delay);
|
|
121
|
+
}
|
|
122
|
+
request() {
|
|
123
|
+
const doc = this.view.state.doc;
|
|
124
|
+
languageService
|
|
125
|
+
.doDecoration(createDocument(this.view.state, LANGUAGE))
|
|
126
|
+
.then((decorations) => {
|
|
127
|
+
if (this.destroyed || this.view.state.doc !== doc) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.view.dispatch({
|
|
131
|
+
effects: setDecorations.of(buildDecorations(doc, decorations)),
|
|
132
|
+
});
|
|
133
|
+
})
|
|
134
|
+
.catch(() => undefined);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|