|
@@ -1,71 +1,73 @@
|
|
1
|
+
|
1
|
2
|
declare var monaco: any;
|
2
|
3
|
|
3
|
|
-async function onMonacoEditorLoad(range: Range, languages=['java','csharp','python','html']) {
|
4
|
|
- const allLangs = await (<any>window).monaco.languages.getLanguages();
|
|
4
|
+async function onMonacoEditorLoad(languages: Array<string> = ['java', 'csharp', 'python', 'html', 'json', 'css'], id: any) {
|
|
5
|
+ const allLangs = await monaco.languages.getLanguages();
|
5
|
6
|
console.log('all supported languages:', allLangs);
|
6
|
7
|
console.log(monaco);
|
7
|
|
- monaco.languages.register({id: languages[3]});
|
8
|
|
- monaco.languages.registerCompletionItemProvider(languages[3],{
|
9
|
|
- triggerCharacters : ['.'],
|
10
|
|
- provideCompletionItems: function(model:any, position: any){
|
|
8
|
+ monaco.languages.register({ id: languages[0] });
|
|
9
|
+ monaco.languages.registerCompletionItemProvider(languages[0], {
|
|
10
|
+ triggerCharacters: ['.'],
|
|
11
|
+ provideCompletionItems: function (model: any, position: any) {
|
11
|
12
|
var textUntilPosition = model.getValueInRange(
|
12
|
|
- {startLineNumber: 1, startColumn: 1,
|
13
|
|
- endLineNumber: position.lineNumber,
|
|
13
|
+ {
|
|
14
|
+ startLineNumber: 1, startColumn: 1,
|
|
15
|
+ endLineNumber: position.lineNumber,
|
14
|
16
|
endColumn: position.column
|
15
|
17
|
}
|
16
|
18
|
);
|
17
|
|
- console.log(textUntilPosition);
|
18
|
|
- var match = textUntilPosition.match(/"dependencies"\s*:\s*\{\s*("[^"]*"\s*:\s*"[^"]*"\s*,\s*)*([^"]*)?$/);
|
19
|
|
- if (!match) {
|
20
|
|
- return { suggestions: [] };
|
21
|
|
- }
|
22
|
|
- var word = model.getWordUntilPosition(position);
|
23
|
|
- var range = {
|
24
|
|
- startLineNumber: position.lineNumber,
|
25
|
|
- endLineNumber: position.lineNumber,
|
26
|
|
- startColumn: word.startColumn,
|
27
|
|
- endColumn: word.endColumn
|
|
19
|
+ console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!', textUntilPosition);
|
|
20
|
+ var match = textUntilPosition.match(/"dependencies"\s*:\s*\{\s*("[^"]*"\s*:\s*"[^"]*"\s*,\s*)*([^"]*)?$/);
|
|
21
|
+ if (!match) {
|
|
22
|
+ return { suggestions: [] };
|
|
23
|
+ }
|
|
24
|
+ var word = model.getWordUntilPosition(position);
|
|
25
|
+ var range = {
|
|
26
|
+ startLineNumber: position.lineNumber,
|
|
27
|
+ endLineNumber: position.lineNumber,
|
|
28
|
+ startColumn: word.startColumn,
|
|
29
|
+ endColumn: word.endColumn
|
28
|
30
|
};
|
29
|
31
|
|
30
|
32
|
var suggestions = [
|
31
|
33
|
{
|
32
|
|
- label: '"lodash"',
|
33
|
|
- kind: monaco.languages.CompletionItemKind.Function,
|
34
|
|
- documentation: "The Lodash library exported as Node.js modules.",
|
35
|
|
- insertText: '"lodash": "*"',
|
36
|
|
- range: range
|
|
34
|
+ label: '"lodash"',
|
|
35
|
+ kind: monaco.languages.CompletionItemKind.Function,
|
|
36
|
+ documentation: "The Lodash library exported as Node.js modules.",
|
|
37
|
+ insertText: '"lodash": "*"',
|
|
38
|
+ range: range
|
37
|
39
|
},
|
38
|
40
|
{
|
39
|
|
- label: '"express"',
|
40
|
|
- kind: monaco.languages.CompletionItemKind.Function,
|
41
|
|
- documentation: "Fast, unopinionated, minimalist web framework",
|
42
|
|
- insertText: '"express": "*"',
|
43
|
|
- range: range
|
|
41
|
+ label: '"express"',
|
|
42
|
+ kind: monaco.languages.CompletionItemKind.Function,
|
|
43
|
+ documentation: "Fast, unopinionated, minimalist web framework",
|
|
44
|
+ insertText: '"express": "*"',
|
|
45
|
+ range: range
|
44
|
46
|
},
|
45
|
47
|
{
|
46
|
|
- label: '"mkdirp"',
|
47
|
|
- kind: monaco.languages.CompletionItemKind.Function,
|
48
|
|
- documentation: "Recursively mkdir, like <code>mkdir -p</code>",
|
49
|
|
- insertText: '"mkdirp": "*"',
|
50
|
|
- range: range
|
|
48
|
+ label: '"mkdirp"',
|
|
49
|
+ kind: monaco.languages.CompletionItemKind.Function,
|
|
50
|
+ documentation: "Recursively mkdir, like <code>mkdir -p</code>",
|
|
51
|
+ insertText: '"mkdirp": "*"',
|
|
52
|
+ range: range
|
51
|
53
|
},
|
52
|
54
|
{
|
53
|
|
- label: '"my-third-party-library"',
|
54
|
|
- kind: monaco.languages.CompletionItemKind.Function,
|
55
|
|
- documentation: "Describe your library here",
|
56
|
|
- insertText: '"${1:my-third-party-library}": "${2:1.2.3}"',
|
57
|
|
- insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
58
|
|
- range: range
|
|
55
|
+ label: '"my-third-party-library"',
|
|
56
|
+ kind: monaco.languages.CompletionItemKind.Function,
|
|
57
|
+ documentation: "Describe your library here",
|
|
58
|
+ insertText: '"${1:my-third-party-library}": "${2:1.2.3}"',
|
|
59
|
+ insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
60
|
+ range: range
|
59
|
61
|
}
|
60
|
|
- ];
|
61
|
|
- return{suggestions:suggestions};
|
|
62
|
+ ];
|
|
63
|
+ return { suggestions: suggestions };
|
62
|
64
|
}
|
63
|
65
|
|
64
|
66
|
});
|
65
|
67
|
}
|
66
|
68
|
|
67
|
69
|
export const monacoConfig = {
|
68
|
|
- baseUrl:'./assets',
|
|
70
|
+ baseUrl: './assets',
|
69
|
71
|
defaultOptions: { scrollBeyondLastLine: false },
|
70
|
72
|
onMonacoLoad: onMonacoEditorLoad
|
71
|
73
|
};
|