@mhjuma/traverse 0.1.0 → 0.3.0

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.
Files changed (29) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/package.json +7 -4
  3. package/src/components/Explorer/Explorer.spec.tsx +122 -3
  4. package/src/components/Explorer/Explorer.tsx +82 -6
  5. package/src/components/ExplorerWorkspace/ExplorerWorkspace.logic.ts +26 -0
  6. package/src/components/ExplorerWorkspace/ExplorerWorkspace.spec.tsx +53 -17
  7. package/src/components/ExplorerWorkspace/ExplorerWorkspace.tsx +78 -74
  8. package/src/components/ExplorerWorkspace/bootstrapKustoLanguage.spec.ts +150 -0
  9. package/src/components/ExplorerWorkspace/bootstrapKustoLanguage.ts +95 -0
  10. package/src/components/ExplorerWorkspace/kustoSchemaQueue.spec.ts +322 -0
  11. package/src/components/ExplorerWorkspace/kustoSchemaQueue.ts +188 -0
  12. package/src/components/ExplorerWorkspace/monacoLoader.spec.ts +82 -0
  13. package/src/components/ExplorerWorkspace/monacoLoader.ts +57 -0
  14. package/src/components/ExplorerWorkspace/monacoWorkers.spec.ts +81 -0
  15. package/src/components/ExplorerWorkspace/monacoWorkers.ts +90 -0
  16. package/src/index.ts +4 -0
  17. package/src/services/schema.spec.ts +107 -28
  18. package/src/services/schema.ts +66 -25
  19. package/src/services/state-service.spec.ts +16 -0
  20. package/src/services/state-service.ts +12 -5
  21. package/src/state/persistence.spec.ts +239 -0
  22. package/src/state/persistence.ts +140 -0
  23. package/src/state/reducer.spec.ts +134 -3
  24. package/src/state/reducer.ts +39 -14
  25. package/src/state/types.ts +6 -0
  26. package/src/test-setup.ts +3 -0
  27. package/vitest.config.ts +7 -0
  28. package/src/components/ExplorerWorkspace/kqlLanguage.spec.ts +0 -321
  29. package/src/components/ExplorerWorkspace/kqlLanguage.ts +0 -155
@@ -3,11 +3,10 @@ import type { Monaco } from '@monaco-editor/react';
3
3
  import type { editor } from 'monaco-editor';
4
4
  import React, { useState, useCallback, useRef, useEffect, useMemo } from 'react';
5
5
 
6
- import { useExplorerColors } from '../../context/ExplorerColorContext';
7
6
  import type { KustoTarget } from '../../services/kusto';
8
7
  import { normalizeQuery, getHistory, saveHistoryEntry, recallResult } from '../../services/queryHistory';
9
8
  import type { QueryHistoryEntry } from '../../services/queryHistory';
10
- import { getSchema, loadSchema } from '../../services/schema';
9
+ import { getSchema, loadSchema, getRawShowSchema } from '../../services/schema';
11
10
  import { EditorToolbar } from '../EditorToolbar/EditorToolbar';
12
11
  import { ResultsPanel } from '../ResultsPanel/ResultsPanel';
13
12
  import { SchemaSidebar } from '../SchemaSidebar/SchemaSidebar';
@@ -26,7 +25,8 @@ import {
26
25
  import { useExplorerStyles } from './ExplorerWorkspace.styles';
27
26
  import type { ExplorerProps } from '../Explorer/Explorer';
28
27
  import { useKustoClient } from '../../context/KustoClientContext';
29
- import { registerKqlLanguage, setKqlSchemaResolver } from './kqlLanguage';
28
+ import { bootstrapKustoLanguage } from './bootstrapKustoLanguage';
29
+ import { applyKustoSchema } from './kustoSchemaQueue';
30
30
 
31
31
 
32
32
  const positionRelativeStyle = { position: 'relative' as const } as const;
@@ -38,12 +38,15 @@ const editorOptions = {
38
38
  overviewRulerBorder: false, padding: { top: 4, bottom: 4 }, lineDecorationsWidth: 8,
39
39
  glyphMargin: false, folding: false,
40
40
  dropIntoEditor: { enabled: false },
41
+ // monaco-kusto exposes semantic-token-based highlighting (columns,
42
+ // functions, tables distinguished by AST role). Enable it explicitly —
43
+ // Monaco's default for standalone editors is false.
44
+ 'semanticHighlighting.enabled': true,
41
45
  } as const;
42
46
 
43
47
  export function ExplorerWorkspace(props: ExplorerProps) {
44
48
  const styles = useExplorerStyles();
45
49
  const { isDark = false } = props;
46
- const explorerColors = useExplorerColors();
47
50
  const client = useKustoClient();
48
51
  const state = useExplorerState();
49
52
  const dispatch = useExplorerDispatch();
@@ -115,9 +118,8 @@ export function ExplorerWorkspace(props: ExplorerProps) {
115
118
  );
116
119
 
117
120
  useEffect(() => {
118
- setKqlSchemaResolver(() => getSchema(focusedTarget));
119
121
  saveActiveConnectionId(focusedConn.id);
120
- }, [focusedConn.id, focusedTarget]);
122
+ }, [focusedConn.id]);
121
123
 
122
124
  // Setter shims — dispatch to reducer, keep same call signatures for existing callbacks
123
125
  const setHasSelection = useCallback((v: boolean) => dispatch({ type: 'SET_HAS_SELECTION', hasSelection: v }), [dispatch]);
@@ -133,8 +135,17 @@ export function ExplorerWorkspace(props: ExplorerProps) {
133
135
  // --- Editor refs (primary + secondary for split) ---
134
136
  const primaryEditorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
135
137
  const secondaryEditorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
136
- const primaryDecorationsRef = useRef<editor.IEditorDecorationsCollection | null>(null);
137
- const secondaryDecorationsRef = useRef<editor.IEditorDecorationsCollection | null>(null);
138
+ // Monaco instance is captured at first editor mount. Stored in state (not
139
+ // a ref) so the schema-push effect re-runs when it becomes available.
140
+ const [monacoInstance, setMonacoInstance] = useState<Monaco | null>(null);
141
+ // Track when monaco-kusto's themed token colors (`kusto-light` /
142
+ // `kusto-dark`) have been registered. Before bootstrap resolves, those
143
+ // theme names don't exist yet — passing them as the Editor's `theme`
144
+ // prop on first mount makes Monaco silently fall back to the default
145
+ // `vs` (light) theme, which causes a brief white flash for dark-mode
146
+ // users on first paint. We render with the built-in `vs-dark` / `vs`
147
+ // theme until bootstrap completes, then swap to the kusto themes.
148
+ const [kustoThemeReady, setKustoThemeReady] = useState(false);
138
149
  const runQueryRef = useRef<() => void>(() => {});
139
150
  const recallQueryRef = useRef<() => void>(() => {});
140
151
  const containerRef = useRef<HTMLDivElement | null>(null);
@@ -142,6 +153,49 @@ export function ExplorerWorkspace(props: ExplorerProps) {
142
153
  const historyKeysRef = useRef<Set<string>>(new Set());
143
154
  const abortRef = useRef<AbortController | null>(null);
144
155
 
156
+ // Push the latest schema to the Kusto language worker whenever connection
157
+ // or schema changes. Debounce + identity-skip live in the queue.
158
+ useEffect(() => {
159
+ const monaco = monacoInstance;
160
+ if (!monaco) {
161
+ return;
162
+ }
163
+ const raw = getRawShowSchema(focusedTarget);
164
+ if (!raw) {
165
+ return;
166
+ }
167
+ applyKustoSchema({
168
+ monaco,
169
+ raw,
170
+ clusterUri: focusedTarget.clusterUrl,
171
+ dbName: focusedTarget.database,
172
+ });
173
+ }, [monacoInstance, focusedTarget, schema]);
174
+
175
+ // Apply monaco-kusto's themed token colors once the language plugin has
176
+ // registered its themes (`kusto-light` / `kusto-dark`). Until bootstrap
177
+ // resolves we render with the built-in `vs` / `vs-dark` theme via the
178
+ // `effectiveTheme` prop below to avoid the white-flash described where
179
+ // `kustoThemeReady` is declared.
180
+ useEffect(() => {
181
+ const monaco = monacoInstance;
182
+ if (!monaco) {
183
+ return;
184
+ }
185
+ let cancelled = false;
186
+ void bootstrapKustoLanguage(monaco).then(() => {
187
+ if (cancelled) {
188
+ return;
189
+ }
190
+ setKustoThemeReady(true);
191
+ }).catch(() => { /* bootstrap errors surface elsewhere */ });
192
+ return () => { cancelled = true; };
193
+ }, [monacoInstance]);
194
+
195
+ const effectiveTheme = kustoThemeReady
196
+ ? (isDark ? 'kusto-dark' : 'kusto-light')
197
+ : (isDark ? 'vs-dark' : 'vs');
198
+
145
199
  // Convenience: the focused editor
146
200
  const getFocusedEditor = useCallback(() => {
147
201
  return focusedPane === 'primary' ? primaryEditorRef.current : secondaryEditorRef.current;
@@ -168,49 +222,6 @@ export function ExplorerWorkspace(props: ExplorerProps) {
168
222
  setCanRecall(historyKeysRef.current.has(normalizeQuery(toRun.query)));
169
223
  }, [setCanRecall]);
170
224
 
171
- const updateStatementHighlight = useCallback((ed: editor.IStandaloneCodeEditor) => {
172
- const decRef = ed === primaryEditorRef.current ? primaryDecorationsRef : secondaryDecorationsRef;
173
- if (!decRef.current) {
174
- return;
175
- }
176
- const selection = ed.getSelection();
177
- // When the user has an explicit selection, don't show the block highlight
178
- if (selection && !selection.isEmpty()) {
179
- decRef.current.set([]);
180
- checkCanRecall(ed);
181
- return;
182
- }
183
- const model = ed.getModel();
184
- if (!model) {
185
- return;
186
- }
187
- const cursorLine = ed.getPosition()?.lineNumber ?? 1;
188
- const totalLines = model.getLineCount();
189
-
190
- let startLine = cursorLine;
191
- while (startLine > 1 && model.getLineContent(startLine - 1).trim() !== '') {
192
- startLine--;
193
- }
194
- let endLine = cursorLine;
195
- while (endLine < totalLines && model.getLineContent(endLine + 1).trim() !== '') {
196
- endLine++;
197
- }
198
-
199
- decRef.current.set([{
200
- range: {
201
- startLineNumber: startLine,
202
- startColumn: 1,
203
- endLineNumber: endLine,
204
- endColumn: model.getLineMaxColumn(endLine),
205
- },
206
- options: {
207
- isWholeLine: true,
208
- className: 'traverse-run-highlight',
209
- },
210
- }]);
211
- checkCanRecall(ed);
212
- }, [checkCanRecall]);
213
-
214
225
  const cancelQuery = useCallback(() => {
215
226
  abortRef.current?.abort();
216
227
  }, []);
@@ -317,10 +328,14 @@ export function ExplorerWorkspace(props: ExplorerProps) {
317
328
  const createEditorMountHandler = useCallback((pane: 'primary' | 'secondary') => {
318
329
  return (ed: editor.IStandaloneCodeEditor, monaco: Monaco) => {
319
330
  const edRef = pane === 'primary' ? primaryEditorRef : secondaryEditorRef;
320
- const decRef = pane === 'primary' ? primaryDecorationsRef : secondaryDecorationsRef;
321
331
  edRef.current = ed;
322
- decRef.current = ed.createDecorationsCollection([]);
323
- registerKqlLanguage(monaco);
332
+ setMonacoInstance(monaco);
333
+ // Kick off the @kusto/monaco-kusto bootstrap; fire-and-forget — the
334
+ // schema queue awaits this internally before applying schema.
335
+ // monaco-kusto also installs its own KustoCommandHighlighter, which
336
+ // visually marks the current command (delimited by blank lines) —
337
+ // that replaces our previous custom decoration.
338
+ void bootstrapKustoLanguage(monaco);
324
339
  ed.addAction({
325
340
  id: 'run-query',
326
341
  label: 'Run Query',
@@ -340,35 +355,24 @@ export function ExplorerWorkspace(props: ExplorerProps) {
340
355
  run: () => { formatQueryRef.current(); },
341
356
  });
342
357
 
343
- ed.onDidChangeCursorPosition(() => updateStatementHighlight(ed));
358
+ ed.onDidChangeCursorPosition(() => checkCanRecall(ed));
344
359
  ed.onDidChangeCursorSelection((e) => {
345
360
  setHasSelection(!e.selection.isEmpty());
346
- updateStatementHighlight(ed);
361
+ checkCanRecall(ed);
347
362
  });
348
- ed.onDidChangeModelContent(() => updateStatementHighlight(ed));
363
+ ed.onDidChangeModelContent(() => checkCanRecall(ed));
349
364
  ed.onDidFocusEditorWidget(() => setFocusedPane(pane));
350
365
 
351
- updateStatementHighlight(ed);
366
+ checkCanRecall(ed);
352
367
  if (pane === 'primary') {
353
368
  ed.focus();
354
369
  }
355
370
  };
356
- }, [updateStatementHighlight, setHasSelection, setFocusedPane]);
371
+ }, [checkCanRecall, setHasSelection, setFocusedPane]);
357
372
 
358
373
  useEffect(() => { runQueryRef.current = runQuery; }, [runQuery]);
359
374
  useEffect(() => { recallQueryRef.current = doRecall; }, [doRecall]);
360
375
 
361
- // Inject global CSS for the run-highlight decoration (Monaco needs a real class)
362
- useEffect(() => {
363
- const id = 'traverse-run-highlight-style';
364
- if (!document.getElementById(id)) {
365
- const style = document.createElement('style');
366
- style.id = id;
367
- style.textContent = `.traverse-run-highlight { background-color: ${explorerColors.semantic.selectionBg}; transition: background-color 0.3s ease; }`;
368
- document.head.appendChild(style);
369
- }
370
- }, [explorerColors.semantic.selectionBg]);
371
-
372
376
  const insertText = useCallback((text: string) => {
373
377
  const ed = getFocusedEditor();
374
378
  if (!ed) {
@@ -595,8 +599,8 @@ export function ExplorerWorkspace(props: ExplorerProps) {
595
599
  )}
596
600
  <Editor
597
601
  height="100%"
598
- language="kql"
599
- theme={isDark ? 'vs-dark' : 'vs'}
602
+ language="kusto"
603
+ theme={effectiveTheme}
600
604
  value={activeTab.kql}
601
605
  onChange={handlePrimaryEditorChange}
602
606
  onMount={handlePrimaryMount}
@@ -615,8 +619,8 @@ export function ExplorerWorkspace(props: ExplorerProps) {
615
619
  onKeyDown={focusSecondaryPaneKeyDown}>
616
620
  <Editor
617
621
  height="100%"
618
- language="kql"
619
- theme={isDark ? 'vs-dark' : 'vs'}
622
+ language="kusto"
623
+ theme={effectiveTheme}
620
624
  value={splitTab.kql}
621
625
  onChange={handleSecondaryEditorChange}
622
626
  onMount={handleSecondaryMount}
@@ -0,0 +1,150 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import type * as Monaco from 'monaco-editor';
3
+
4
+ import {
5
+ bootstrapKustoLanguage,
6
+ __resetBootstrapForTests,
7
+ } from './bootstrapKustoLanguage';
8
+
9
+ const setLanguageSettings = vi.fn();
10
+ const setMaximumWorkerIdleTime = vi.fn();
11
+ const kustoDefaults = { setLanguageSettings, setMaximumWorkerIdleTime };
12
+
13
+ vi.mock('@kusto/monaco-kusto', () => ({
14
+ get kustoDefaults() {
15
+ return kustoDefaults;
16
+ },
17
+ }));
18
+
19
+ function makeMonaco(languages: { id: string }[] = [{ id: 'kusto' }]): typeof Monaco {
20
+ return {
21
+ languages: {
22
+ getLanguages: vi.fn(() => languages),
23
+ },
24
+ } as unknown as typeof Monaco;
25
+ }
26
+
27
+ beforeEach(() => {
28
+ __resetBootstrapForTests();
29
+ setLanguageSettings.mockReset();
30
+ setMaximumWorkerIdleTime.mockReset();
31
+ vi.spyOn(console, 'error').mockImplementation(() => {});
32
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
33
+ });
34
+
35
+ afterEach(() => {
36
+ vi.restoreAllMocks();
37
+ });
38
+
39
+ describe('bootstrapKustoLanguage', () => {
40
+ it('imports @kusto/monaco-kusto and applies default settings on first call', async () => {
41
+ const monaco = makeMonaco();
42
+
43
+ await bootstrapKustoLanguage(monaco);
44
+
45
+ expect(setLanguageSettings).toHaveBeenCalledTimes(1);
46
+ const settings = setLanguageSettings.mock.calls[0][0];
47
+ expect(settings.enableHover).toBe(true);
48
+ expect(settings.enableQueryWarnings).toBe(true);
49
+ expect(settings.enableQuerySuggestions).toBe(true);
50
+ expect(settings.includeControlCommands).toBe(true);
51
+ expect(settings.completionOptions).toEqual({ includeExtendedSyntax: false });
52
+ });
53
+
54
+ it('is idempotent — repeated calls return the same promise without re-applying settings', async () => {
55
+ const monaco = makeMonaco();
56
+
57
+ const p1 = bootstrapKustoLanguage(monaco);
58
+ const p2 = bootstrapKustoLanguage(monaco);
59
+
60
+ expect(p1).toBe(p2);
61
+ await p1;
62
+ await p2;
63
+ expect(setLanguageSettings).toHaveBeenCalledTimes(1);
64
+ });
65
+
66
+ it('merges caller-provided settings over defaults', async () => {
67
+ const monaco = makeMonaco();
68
+
69
+ await bootstrapKustoLanguage(monaco, {
70
+ languageSettings: {
71
+ enableHover: false,
72
+ disabledDiagnosticCodes: ['KS107'],
73
+ },
74
+ });
75
+
76
+ const settings = setLanguageSettings.mock.calls[0][0];
77
+ expect(settings.enableHover).toBe(false);
78
+ expect(settings.enableQueryWarnings).toBe(true);
79
+ expect(settings.disabledDiagnosticCodes).toEqual(['KS107']);
80
+ expect(settings.completionOptions).toEqual({ includeExtendedSyntax: false });
81
+ });
82
+
83
+ it('falls back to default completionOptions when caller passes undefined', async () => {
84
+ const monaco = makeMonaco();
85
+
86
+ await bootstrapKustoLanguage(monaco, {
87
+ languageSettings: { completionOptions: undefined as never },
88
+ });
89
+
90
+ const settings = setLanguageSettings.mock.calls[0][0];
91
+ expect(settings.completionOptions).toEqual({ includeExtendedSyntax: false });
92
+ });
93
+
94
+ it('uses caller-provided completionOptions when present', async () => {
95
+ const monaco = makeMonaco();
96
+
97
+ await bootstrapKustoLanguage(monaco, {
98
+ languageSettings: { completionOptions: { includeExtendedSyntax: true } },
99
+ });
100
+
101
+ const settings = setLanguageSettings.mock.calls[0][0];
102
+ expect(settings.completionOptions).toEqual({ includeExtendedSyntax: true });
103
+ });
104
+
105
+ it('applies workerMaxIdleTimeMs when provided', async () => {
106
+ const monaco = makeMonaco();
107
+
108
+ await bootstrapKustoLanguage(monaco, { workerMaxIdleTimeMs: 5 * 60_000 });
109
+
110
+ expect(setMaximumWorkerIdleTime).toHaveBeenCalledWith(5 * 60_000);
111
+ });
112
+
113
+ it('does not call setMaximumWorkerIdleTime when not provided', async () => {
114
+ const monaco = makeMonaco();
115
+
116
+ await bootstrapKustoLanguage(monaco);
117
+
118
+ expect(setMaximumWorkerIdleTime).not.toHaveBeenCalled();
119
+ });
120
+
121
+ it('throws when the Monaco instance has no kusto language after import (two-Monaco)', async () => {
122
+ const monaco = makeMonaco([{ id: 'javascript' }]);
123
+
124
+ await expect(bootstrapKustoLanguage(monaco)).rejects.toThrow(/different Monaco instance/);
125
+ });
126
+
127
+ it('clears the cached promise on failure so a subsequent call can retry', async () => {
128
+ const monaco = makeMonaco([{ id: 'javascript' }]);
129
+
130
+ await expect(bootstrapKustoLanguage(monaco)).rejects.toThrow();
131
+
132
+ // After failure, the next call should re-attempt (and re-invoke setLanguageSettings).
133
+ const monaco2 = makeMonaco();
134
+ await bootstrapKustoLanguage(monaco2);
135
+
136
+ expect(setLanguageSettings).toHaveBeenCalledTimes(2);
137
+ });
138
+
139
+ it('throws a helpful error when @kusto/monaco-kusto did not expose kustoDefaults', async () => {
140
+ const monaco = makeMonaco();
141
+ const broken = kustoDefaults.setLanguageSettings;
142
+ kustoDefaults.setLanguageSettings = undefined as never;
143
+
144
+ try {
145
+ await expect(bootstrapKustoLanguage(monaco)).rejects.toThrow(/did not expose kustoDefaults/);
146
+ } finally {
147
+ kustoDefaults.setLanguageSettings = broken;
148
+ }
149
+ });
150
+ });
@@ -0,0 +1,95 @@
1
+ import type { LanguageSettings } from '@kusto/monaco-kusto';
2
+ import type * as Monaco from 'monaco-editor';
3
+
4
+ /**
5
+ * Default language settings applied on the first bootstrap call.
6
+ *
7
+ * Notes:
8
+ * - `completionOptions` is required by `@kusto/monaco-kusto@14.x`.
9
+ * - Several legacy flags (`useIntellisenseV2`, `useSemanticColorization`,
10
+ * `useTokenColorization`) were removed in v12+ and must not be set.
11
+ * - Semantic highlighting is gated by the Monaco editor option
12
+ * `'semanticHighlighting.enabled'`, not by language settings.
13
+ */
14
+ const DEFAULT_LANGUAGE_SETTINGS: LanguageSettings = {
15
+ enableHover: true,
16
+ enableQueryWarnings: true,
17
+ enableQuerySuggestions: true,
18
+ includeControlCommands: true,
19
+ completionOptions: { includeExtendedSyntax: false },
20
+ };
21
+
22
+ export interface BootstrapKustoLanguageOptions {
23
+ /**
24
+ * Override or extend the default language settings. The merge is shallow —
25
+ * fields supplied here replace the defaults entirely.
26
+ */
27
+ languageSettings?: Partial<LanguageSettings>;
28
+ /**
29
+ * Worker idle timeout in milliseconds. Defaults to the engine's built-in
30
+ * value (effectively never idles out so the schema stays resident).
31
+ */
32
+ workerMaxIdleTimeMs?: number;
33
+ }
34
+
35
+ let bootstrapPromise: Promise<void> | null = null;
36
+
37
+ /**
38
+ * Lazily loads `@kusto/monaco-kusto` and registers the `kusto` language against
39
+ * the provided Monaco instance. Idempotent — repeated calls return the same
40
+ * promise. The dynamic import is performed exactly once per process; if the
41
+ * import fails, the cached promise is cleared so a later call can retry.
42
+ */
43
+ export function bootstrapKustoLanguage(
44
+ monaco: typeof Monaco,
45
+ options: BootstrapKustoLanguageOptions = {},
46
+ ): Promise<void> {
47
+ if (bootstrapPromise) {
48
+ return bootstrapPromise;
49
+ }
50
+ bootstrapPromise = doBootstrap(monaco, options).catch((err) => {
51
+ bootstrapPromise = null;
52
+ throw err;
53
+ });
54
+ return bootstrapPromise;
55
+ }
56
+
57
+ async function doBootstrap(
58
+ monaco: typeof Monaco,
59
+ options: BootstrapKustoLanguageOptions,
60
+ ): Promise<void> {
61
+ const mod = await import('@kusto/monaco-kusto');
62
+ const defaults = mod.kustoDefaults;
63
+ if (!defaults || typeof defaults.setLanguageSettings !== 'function') {
64
+ throw new Error(
65
+ 'Traverse: @kusto/monaco-kusto did not expose kustoDefaults.setLanguageSettings. ' +
66
+ 'This usually means a duplicate monaco-editor was loaded — verify configureMonacoLoader ran.',
67
+ );
68
+ }
69
+ const settings: LanguageSettings = {
70
+ ...DEFAULT_LANGUAGE_SETTINGS,
71
+ ...options.languageSettings,
72
+ completionOptions:
73
+ options.languageSettings?.completionOptions ??
74
+ DEFAULT_LANGUAGE_SETTINGS.completionOptions,
75
+ };
76
+ defaults.setLanguageSettings(settings);
77
+ if (typeof options.workerMaxIdleTimeMs === 'number') {
78
+ defaults.setMaximumWorkerIdleTime(options.workerMaxIdleTimeMs);
79
+ }
80
+ // Sanity check: confirm the plugin registered against this Monaco instance.
81
+ // If `loader.config({ monaco })` was missed, the plugin will have decorated a
82
+ // different Monaco copy and the `kusto` language id won't be present here.
83
+ const registered = monaco.languages.getLanguages().some((l) => l.id === 'kusto');
84
+ if (!registered) {
85
+ throw new Error(
86
+ 'Traverse: @kusto/monaco-kusto registered against a different Monaco instance ' +
87
+ 'than the editor host. Ensure `configureMonacoLoader` runs before any editor mounts.',
88
+ );
89
+ }
90
+ }
91
+
92
+ /** Test-only: reset the cached bootstrap promise. */
93
+ export function __resetBootstrapForTests(): void {
94
+ bootstrapPromise = null;
95
+ }