12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
-
-
- async function onMonacoEditorLoad(languages: Array<string> = ['java', 'csharp', 'python', 'html', 'json', 'css']) {
- const allLangs = (<any>window).monaco.languages.getLanguages();
- console.log('all supported languages:', allLangs);
- console.log( (<any>window).monaco);
- (<any>window).monaco.languages.register({ id: languages[0] });
- (<any>window).monaco.languages.registerCompletionItemProvider(languages[0], {
- triggerCharacters: ['.'],
- provideCompletionItems: function (model: any, position: any) {
- const textUntilPosition = model.getValueInRange(
- {
- startLineNumber: position.lineNumber,
- startColumn: 1,
- endLineNumber: position.lineNumber,
- endColumn: position.column
- }
- );
- console.log(textUntilPosition);
- const match = textUntilPosition.match(/"dependencies"\s*:\s*\{\s*("[^"]*"\s*:\s*"[^"]*"\s*,\s*)*([^"]*)?$/);
- if (!match) {
- return { suggestions: [] };
- }
- var word = model.getWordUntilPosition(position);
- var range = {
- startLineNumber: position.lineNumber,
- endLineNumber: position.lineNumber,
- startColumn: word.startColumn,
- endColumn: word.endColumn
- };
-
- const suggestions = [
- {
- label: '"lodash"',
- kind: (<any>window).monaco.languages.CompletionItemKind.Function,
- documentation: "The Lodash library exported as Node.js modules.",
- insertText: '"lodash": "*"',
- range: range
- },
- {
- label: '"express"',
- kind: (<any>window).monaco.languages.CompletionItemKind.Function,
- documentation: "Fast, unopinionated, minimalist web framework",
- insertText: '"express": "*"',
- range: range
- },
- {
- label: '"mkdirp"',
- kind: (<any>window).monaco.languages.CompletionItemKind.Function,
- documentation: "Recursively mkdir, like <code>mkdir -p</code>",
- insertText: '"mkdirp": "*"',
- range: range
- },
- {
- label: '"my-third-party-library"',
- kind: (<any>window).monaco.languages.CompletionItemKind.Function,
- documentation: "Describe your library here",
- insertText: '"${1:my-third-party-library}": "${2:1.2.3}"',
- insertTextRules: (<any>window).monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
- range: range
- }
- ];
- return { suggestions: suggestions };
- }
-
- });
- }
-
- export const monacoConfig = {
- baseUrl: './assets',
- defaultOptions: { scrollBeyondLastLine: false },
- onMonacoLoad: onMonacoEditorLoad
- };
|