22// See LICENSE in the project root for license information.
33
44import * as ts from 'typescript' ;
5- import * as path from 'path' ;
65import * as tsdoc from '@microsoft/tsdoc' ;
76import {
87 PackageJsonLookup ,
@@ -17,7 +16,7 @@ import {
1716 IExtractorValidationRulesConfig ,
1817 ExtractorValidationRulePolicy
1918} from '../api/IExtractorConfig' ;
20- import { TypeScriptMessageFormatter } from '../analyzer/TypeScriptMessageFormatter' ;
19+
2120import { CollectorEntity } from './CollectorEntity' ;
2221import { AstSymbolTable , AstEntity } from '../analyzer/AstSymbolTable' ;
2322import { AstModule , AstModuleExportInfo } from '../analyzer/AstModule' ;
@@ -30,6 +29,8 @@ import { PackageDocComment } from '../aedoc/PackageDocComment';
3029import { DeclarationMetadata } from './DeclarationMetadata' ;
3130import { SymbolMetadata } from './SymbolMetadata' ;
3231import { TypeScriptInternals } from '../analyzer/TypeScriptInternals' ;
32+ import { MessageRouter } from './MessageRouter' ;
33+ import { ExtractorMessageId } from './ExtractorMessageId' ;
3334
3435/**
3536 * Options for Collector constructor.
@@ -71,6 +72,7 @@ export class Collector {
7172 public readonly astSymbolTable : AstSymbolTable ;
7273
7374 public readonly packageJsonLookup : PackageJsonLookup ;
75+ public readonly messageRouter : MessageRouter ;
7476
7577 public readonly policies : IExtractorPoliciesConfig ;
7678 public readonly validationRules : IExtractorValidationRulesConfig ;
@@ -95,11 +97,11 @@ export class Collector {
9597
9698 constructor ( options : ICollectorOptions ) {
9799 this . packageJsonLookup = new PackageJsonLookup ( ) ;
100+ this . messageRouter = new MessageRouter ( ) ;
98101
99102 this . policies = options . policies ;
100103 this . validationRules = options . validationRules ;
101104
102- this . logger = options . logger ;
103105 this . _program = options . program ;
104106
105107 const packageFolder : string | undefined = this . packageJsonLookup . tryGetPackageFolderFor ( options . entryPointFile ) ;
@@ -173,8 +175,7 @@ export class Collector {
173175 // with semantic information (i.e. symbols). The "diagnostics" are a subset of the everyday
174176 // compile errors that would result from a full compilation.
175177 for ( const diagnostic of this . _program . getSemanticDiagnostics ( ) ) {
176- const errorText : string = TypeScriptMessageFormatter . format ( diagnostic . messageText ) ;
177- this . reportError ( `TypeScript: ${ errorText } ` , diagnostic . file , diagnostic . start ) ;
178+ this . messageRouter . addCompilerDiagnostic ( diagnostic ) ;
178179 }
179180
180181 // Build the entry point
@@ -443,26 +444,6 @@ export class Collector {
443444 }
444445 }
445446
446- /**
447- * Reports an error message to the registered ApiErrorHandler.
448- */
449- public reportError ( message : string , sourceFile : ts . SourceFile | undefined , start : number | undefined ) : void {
450- if ( sourceFile && start ) {
451- const lineAndCharacter : ts . LineAndCharacter = sourceFile . getLineAndCharacterOfPosition ( start ) ;
452-
453- // If the file is under the packageFolder, then show a relative path
454- const relativePath : string = path . relative ( this . workingPackage . packageFolder , sourceFile . fileName ) ;
455- const shownPath : string = relativePath . substr ( 0 , 2 ) === '..' ? sourceFile . fileName : relativePath ;
456-
457- // Format the error so that VS Code can follow it. For example:
458- // "src\MyClass.ts(15,1): The JSDoc tag "@blah" is not supported by AEDoc"
459- this . logger . logError ( `${ shownPath } (${ lineAndCharacter . line + 1 } ,${ lineAndCharacter . character + 1 } ): `
460- + message ) ;
461- } else {
462- this . logger . logError ( message ) ;
463- }
464- }
465-
466447 private _fetchSymbolMetadata ( astSymbol : AstSymbol ) : void {
467448 if ( astSymbol . metadata ) {
468449 return ;
@@ -495,8 +476,11 @@ export class Collector {
495476 if ( declaredReleaseTag !== ReleaseTag . None ) {
496477 if ( effectiveReleaseTag !== ReleaseTag . None && effectiveReleaseTag !== declaredReleaseTag ) {
497478 if ( ! astSymbol . isExternal ) { // for now, don't report errors for external code
498- // TODO: Report error message
499- this . reportError ( 'Inconsistent release tags between declarations' , undefined , undefined ) ;
479+ this . messageRouter . addAnalyzerIssue (
480+ ExtractorMessageId . InconsistentReleaseTags ,
481+ 'This symbol has another declaration with a different release tag' ,
482+ astDeclaration
483+ ) ;
500484 }
501485 } else {
502486 effectiveReleaseTag = declaredReleaseTag ;
@@ -514,16 +498,18 @@ export class Collector {
514498 if ( effectiveReleaseTag === ReleaseTag . None ) {
515499 if ( this . validationRules . missingReleaseTags !== ExtractorValidationRulePolicy . allow ) {
516500 if ( ! astSymbol . isExternal ) { // for now, don't report errors for external code
517- // For now, don 't report errors for forgotten exports
501+ // Don 't report missing release tags for forgotten exports
518502 const entity : CollectorEntity | undefined = this . _entitiesByAstEntity . get ( astSymbol . rootAstSymbol ) ;
519503 if ( entity && entity . exported ) {
520504 // We also don't report errors for the default export of an entry point, since its doc comment
521505 // isn't easy to obtain from the .d.ts file
522506 if ( astSymbol . rootAstSymbol . localName !== '_default' ) {
523- // TODO: Report error message
524- const loc : string = astSymbol . rootAstSymbol . localName + ' in '
525- + astSymbol . rootAstSymbol . astDeclarations [ 0 ] . declaration . getSourceFile ( ) . fileName ;
526- this . reportError ( 'Missing release tag for ' + loc , undefined , undefined ) ;
507+
508+ this . messageRouter . addAnalyzerIssue (
509+ ExtractorMessageId . MissingReleaseTag ,
510+ 'Missing release tag' ,
511+ astSymbol
512+ ) ;
527513 }
528514 }
529515 }
@@ -580,8 +566,10 @@ export class Collector {
580566
581567 if ( inconsistentReleaseTags ) {
582568 if ( ! astDeclaration . astSymbol . isExternal ) { // for now, don't report errors for external code
583- // TODO: Report error message
584- this . reportError ( 'Inconsistent release tags in doc comment' , undefined , undefined ) ;
569+ this . messageRouter . addAnalyzerIssue (
570+ ExtractorMessageId . ExtraReleaseTag ,
571+ 'The doc comment should not contain more than one release tag' ,
572+ astDeclaration ) ;
585573 }
586574 }
587575
0 commit comments