|
1 | 1 | import * as React from 'react';
|
2 | 2 | import * as monacoEditor from 'monaco-editor';
|
| 3 | +import * as tsdoc from '@microsoft/tsdoc'; |
3 | 4 | import { FlexColDiv } from './FlexDivs';
|
4 | 5 |
|
5 | 6 | export interface ITextRange {
|
@@ -58,6 +59,10 @@ interface IMonacoWindow extends Window {
|
58 | 59 | };
|
59 | 60 | }
|
60 | 61 |
|
| 62 | +interface IMonarchLanguageConfiguration extends monacoEditor.languages.IMonarchLanguage { |
| 63 | + keywords: string[]; |
| 64 | +} |
| 65 | + |
61 | 66 | declare const MONACO_URL: string;
|
62 | 67 | const MONACO_BASE_URL: string = MONACO_URL;
|
63 | 68 |
|
@@ -309,6 +314,30 @@ export class CodeEditor extends React.Component<ICodeEditorProps, ICodeEditorSta
|
309 | 314 | CodeEditor._initializeMonaco()
|
310 | 315 | .then((monaco) => {
|
311 | 316 | if (!this._editor && this._hostDivRef) {
|
| 317 | + const tsdocLanguage: IMonarchLanguageConfiguration = { |
| 318 | + keywords: tsdoc.StandardTags.allDefinitions.map((tag: tsdoc.TSDocTagDefinition) => tag.tagName), |
| 319 | + tokenizer: { |
| 320 | + common: [[/\/\*\*/, 'comment', '@comment']], |
| 321 | + comment: [ |
| 322 | + [/\*/, 'comment'], |
| 323 | + [/\\* [^\n@*]*/, 'comment'], |
| 324 | + [/(?:\/)[\n|*]*/, 'comment', '@pop'], |
| 325 | + [ |
| 326 | + /@[^ \n]*/, |
| 327 | + { |
| 328 | + cases: { |
| 329 | + '@keywords': 'keyword', |
| 330 | + '@default': 'annotation' |
| 331 | + } |
| 332 | + } |
| 333 | + ] |
| 334 | + ] |
| 335 | + } |
| 336 | + }; |
| 337 | + |
| 338 | + monaco.languages.register({ id: 'tsdocLanguage' }); |
| 339 | + monaco.languages.setMonarchTokensProvider('tsdocLanguage', tsdocLanguage); |
| 340 | + |
312 | 341 | this._editor = monaco.editor.create(this._hostDivRef, {
|
313 | 342 | value: this.props.value || '',
|
314 | 343 | language: this.props.language,
|
|
0 commit comments