Skip to content

Commit 750c383

Browse files
committed
Create a TSDoc lang conf for playground
1 parent cc10697 commit 750c383

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

playground/src/CodeEditor.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import * as monacoEditor from 'monaco-editor';
3+
import * as tsdoc from '@microsoft/tsdoc';
34
import { FlexColDiv } from './FlexDivs';
45

56
export interface ITextRange {
@@ -58,6 +59,10 @@ interface IMonacoWindow extends Window {
5859
};
5960
}
6061

62+
interface IMonarchLanguageConfiguration extends monacoEditor.languages.IMonarchLanguage {
63+
keywords: string[];
64+
}
65+
6166
declare const MONACO_URL: string;
6267
const MONACO_BASE_URL: string = MONACO_URL;
6368

@@ -309,6 +314,30 @@ export class CodeEditor extends React.Component<ICodeEditorProps, ICodeEditorSta
309314
CodeEditor._initializeMonaco()
310315
.then((monaco) => {
311316
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+
312341
this._editor = monaco.editor.create(this._hostDivRef, {
313342
value: this.props.value || '',
314343
language: this.props.language,

playground/src/PlaygroundView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class PlaygroundView extends React.Component<IPlaygroundViewProps, IPlayg
150150
style={editorStyle}
151151
value={this.state.inputText}
152152
onChange={this._inputTextArea_onChange}
153-
language="typescript"
153+
language="tsdocLanguage"
154154
markers={markers}
155155
syntaxStyles={syntaxStyles}
156156
theme={this.state.selectedTheme}

0 commit comments

Comments
 (0)