Skip to content

Commit 18eee9c

Browse files
committed
Add package @mongodb-js/mongodb-constants
1 parent c6b58a5 commit 18eee9c

File tree

6 files changed

+59
-269
lines changed

6 files changed

+59
-269
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@
6868
"@grafana/runtime": "^11.2.0",
6969
"@grafana/schema": "^10.4.0",
7070
"@grafana/ui": "^11.2.0",
71+
"@mongodb-js/mongodb-constants": "^0.11.1",
7172
"react": "18.2.0",
7273
"react-dom": "18.2.0",
7374
"shadowrealm-api": "^0.8.3",
7475
"tslib": "2.5.3",
7576
"validator": "^13.15.0"
7677
},
7778
"packageManager": "[email protected]"
78-
}
79+
}

src/editor/autocomplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRef, useEffect } from 'react';
22
import { type Monaco, type monacoTypes, type MonacoEditor } from '@grafana/ui';
33
import { languages } from 'monaco-editor';
4-
import stages from './stages.json';
4+
import { STAGE_OPERATORS } from '@mongodb-js/mongodb-constants'
55

66
interface CompletionState {
77
name: string;
@@ -46,7 +46,7 @@ class CompletionProvider implements monacoTypes.languages.CompletionItemProvider
4646
endColumn: word.endColumn,
4747
};
4848

49-
const suggestions: languages.CompletionItem[] = stages.map((stage) => ({
49+
const suggestions: languages.CompletionItem[] = STAGE_OPERATORS.map((stage) => ({
5050
label: `"${stage.name}"`,
5151
kind: languages.CompletionItemKind.Function,
5252
insertText: `"\\${stage.name}": ${stage.snippet}`,

src/editor/hover.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { useEffect, useRef } from 'react';
22
import { monacoTypes, type Monaco, type MonacoEditor } from '@grafana/ui';
3-
import stages from './stages.json';
3+
import { STAGE_OPERATORS } from '@mongodb-js/mongodb-constants'
44

5-
const stageObj = Object.fromEntries(stages.map((stage) => [stage.name, [stage.description, stage.comment]]))
5+
6+
const stages = Object.fromEntries(STAGE_OPERATORS.map((stage) => [stage.name, [stage.description, stage.comment]]))
67

78
class HoverProvider implements monacoTypes.languages.HoverProvider {
89
constructor(private readonly editor: MonacoEditor) { }
@@ -12,8 +13,8 @@ class HoverProvider implements monacoTypes.languages.HoverProvider {
1213
}
1314

1415
const word = model.getWordAtPosition(position);
15-
if (word && Object.keys(stageObj).includes(word.word)) {
16-
const [description, comment] = stageObj[word.word];
16+
if (word && word.word in stages) {
17+
const [description, comment] = stages[word.word];
1718
return {
1819
range: {
1920
startLineNumber: position.lineNumber,
@@ -24,7 +25,13 @@ class HoverProvider implements monacoTypes.languages.HoverProvider {
2425
contents: [
2526
{ value: `[${word.word}](https://www.mongodb.com/docs/manual/reference/operator/aggregation/${word.word.substring(1)})` },
2627
{ value: description },
27-
{ value: comment },
28+
{
29+
value: comment
30+
.trim()
31+
.replace(/^\/\*\*/g, '')
32+
.replace(/\*\/$/g, '')
33+
.trim()
34+
},
2835
]
2936
};
3037
}

0 commit comments

Comments
 (0)