22// See LICENSE in the project root for license information.
33
44import * as ts from 'typescript' ;
5+ import * as tsdoc from '@microsoft/tsdoc' ;
56
67import { TypeScriptMessageFormatter } from '../analyzer/TypeScriptMessageFormatter' ;
78import { AstDeclaration } from '../analyzer/AstDeclaration' ;
@@ -24,6 +25,9 @@ export class MessageRouter {
2425 return this . _messages ;
2526 }
2627
28+ /**
29+ * Add a diagnostic message reported by the TypeScript compiler
30+ */
2731 public addCompilerDiagnostic ( diagnostic : ts . Diagnostic ) : void {
2832 switch ( diagnostic . category ) {
2933 case ts . DiagnosticCategory . Suggestion :
@@ -51,6 +55,9 @@ export class MessageRouter {
5155 this . _messages . push ( new ExtractorMessage ( options ) ) ;
5256 }
5357
58+ /**
59+ * Add a message from the API Extractor analysis
60+ */
5461 public addAnalyzerIssue ( messageId : ExtractorMessageId , messageText : string ,
5562 astDeclarationOrSymbol : AstDeclaration | AstSymbol ) : void {
5663
@@ -64,6 +71,31 @@ export class MessageRouter {
6471 this . addAnalyzerIssueForPosition ( messageId , messageText , declaration . getSourceFile ( ) , declaration . pos ) ;
6572 }
6673
74+ /**
75+ * Add all messages produced from an invocation of the TSDoc parser, assuming they refer to
76+ * code in the specified source file.
77+ */
78+ public addTsdocMessages ( parserContext : tsdoc . ParserContext , sourceFile : ts . SourceFile ) : void {
79+ for ( const message of parserContext . log . messages ) {
80+ const lineAndCharacter : ts . LineAndCharacter = sourceFile . getLineAndCharacterOfPosition (
81+ message . textRange . pos ) ;
82+
83+ this . _messages . push (
84+ new ExtractorMessage ( {
85+ category : ExtractorMessageCategory . TSDoc ,
86+ messageId : message . messageId ,
87+ text : message . text ,
88+ sourceFilePath : sourceFile . fileName ,
89+ sourceFileLine : lineAndCharacter . line ,
90+ sourceFileColumn : lineAndCharacter . character
91+ } )
92+ ) ;
93+ }
94+ }
95+
96+ /**
97+ * Add a message for a location in an arbitrary source file.
98+ */
6799 public addAnalyzerIssueForPosition ( messageId : ExtractorMessageId , messageText : string ,
68100 sourceFile : ts . SourceFile , pos : number ) : void {
69101
@@ -81,5 +113,4 @@ export class MessageRouter {
81113
82114 this . _messages . push ( new ExtractorMessage ( options ) ) ;
83115 }
84-
85116}
0 commit comments