Integration of monaco-editor into angular application: monaco-editor@0.36.1, ngx-monaco-editor-v2@15.0.1

monaco-editor-config.ts 2.6KB

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

Powered by TurnKey Linux.