import * as vscode from 'vscode' ; import { parsers , problemMatcher , uuid } from 'vscode-common' ; export interface CommandCodeLensProvider { param document param token param lineNum param colNum param command param args return provideCommandCodeLenses ( document , token , lineNum , colNum , command , args ) : Promise < vscode . CodeLens [ ] | undefined > ; /**
     * An optional event to signal that the code lenses from this provider have changed.
     */ onDidChangeCommandCodeLenses ? : vscode . Event < void > ; } export interface ICommandCodeLensProviderRegistry { getCommandCodeLensProvider ( name ) : CommandCodeLensProvider | undefined ; registerCommandCodeLensProvider ( name , provider ) : vscode . Disposable ; /**
     * An optional event to signal that the code lenses from the named provider have changed.
     */ onDidChangeCommandCodeLenses : vscode . Event < string > ; } export class API implements problemMatcher . IProblemMatcherRegistry , ICommandCodeLensProviderRegistry , vscode . Disposable { private registries : Set < DisposableProblemMatcherRegistry > = new Set ( ) ; private onDidDisposeProblemMatcherRegistry : vscode . EventEmitter < DisposableProblemMatcherRegistry > = new vscode . EventEmitter ( ) ; private onDidDisposeCommandCodeLens : vscode . EventEmitter < DisposableCommandCodeLensProvider > = new vscode . EventEmitter ( ) ; private _onMatcherChanged : vscode . EventEmitter < void > = new vscode . EventEmitter ( ) ; private _onDidChangeCommandCodeLenses : vscode . EventEmitter < string > = new vscode . EventEmitter ( ) ; private commandCodeLenses : Map < string , DisposableCommandCodeLensProvider > = new Map ( ) ; private disposables : vscode . Disposable [ ] = [ ] ; private uuid = uuid . generateUuid ( ) ; public onDidChangeCommandCodeLenses = this . _onDidChangeCommandCodeLenses . event ; constructor ( ) { this . onDidDisposeProblemMatcherRegistry . event ( this . handleDisposed , this , this . disposables ) ; this . disposables . push ( this . onDidDisposeProblemMatcherRegistry ) ; this . disposables . push ( this . onDidDisposeCommandCodeLens ) ; this . disposables . push ( this . _onMatcherChanged ) ; this . disposables . push ( this . _onDidChangeCommandCodeLenses ) ; } handleDisposed ( registry ) { this . registries . delete ( registry ) ; } registerCommandCodeLensProvider ( name , provider ) { const disposable = new DisposableCommandCodeLensProvider ( this . onDidDisposeCommandCodeLens , name , provider ) ; this . commandCodeLenses . set ( name , disposable ) ; if ( provider . onDidChangeCommandCodeLenses ) { this . disposables . push ( provider . onDidChangeCommandCodeLenses ( ( ) => this . _onDidChangeCommandCodeLenses . fire ( name ) ) ) ; } return disposable ; } getCommandCodeLensProvider ( name ) { return this . commandCodeLenses . get ( name ) ; } registerProblemMatchers ( configs ) { const registry = new problemMatcher . ProblemMatcherRegistryImpl ( ) ; const disposable = new DisposableProblemMatcherRegistry ( registry , this . onDidDisposeProblemMatcherRegistry ) ; this . disposables . push ( disposable ) ; const logger = new VSCodeWindowProblemReporter ( ) ; const parser = new problemMatcher . ProblemMatcherParser ( registry , logger ) ; for ( const config of configs ) { const matcher = parser . parse ( config ) ; if ( problemMatcher . isNamedProblemMatcher ( matcher ) ) { const name = matcher . name ; const aliases = name . split ( /\s*,\s*/ ) ; for ( const alias of aliases ) { matcher . name = alias ; matcher . owner = alias ; registry . add ( matcher ) ; console . log ( `Registered problem matcher "${ alias }"` ) ; } } } this . registries . add ( disposable ) ; this . _onMatcherChanged . fire ( ) ; return disposable ; } async onReady ( ) { } get ( name ) { for ( const registry of this . registries . values ( ) ) { const matcher = registry . get ( name ) ; if ( matcher ) { return matcher ; } } return undefined ; } keys ( ) { const all = new Set < string > ( ) ; for ( const registry of this . registries . values ( ) ) { for ( const key of registry . keys ( ) ) { all . add ( key ) ; } } return Array . from ( all . values ( ) ) ; } get onMatcherChanged ( ) { return this . _onMatcherChanged . event ; } dispose ( ) { this . disposables . forEach ( d => d . dispose ( ) ) ; this . disposables . length = 0 ; this . commandCodeLenses . forEach ( d => d . dispose ( ) ) ; this . registries . forEach ( d => d . dispose ( ) ) ; this . registries . clear ( ) ; } } class DisposableCommandCodeLensProvider implements CommandCodeLensProvider , vscode . Disposable { public onDidChangeCommandCodeLenses : vscode . Event < void > | undefined ; constructor ( private onDidDispose , private name , private proxy ) { this . onDidChangeCommandCodeLenses = proxy . onDidChangeCommandCodeLenses ; } provideCommandCodeLenses ( document , token , lineNum , colNum , command , args ) { return this . proxy . provideCommandCodeLenses ( document , token , lineNum , colNum , command , args ) ; } dispose ( ) { this . onDidDispose . fire ( this ) ; } } class DisposableProblemMatcherRegistry implements problemMatcher . IProblemMatcherRegistry , vscode . Disposable { constructor ( private proxy , private onDidDispose ) { } onReady ( ) { return this . proxy . onReady ( ) ; } get ( name ) { return this . proxy . get ( name ) ; } keys ( ) { return this . proxy . keys ( ) ; } get onMatcherChanged ( ) { return this . proxy . onMatcherChanged ; } dispose ( ) { this . onDidDispose . fire ( this ) ; } } export class VSCodeWindowProblemReporter implements parsers . IProblemReporter { private _validationStatus : parsers . ValidationStatus ; constructor ( ) { this . _validationStatus = new parsers . ValidationStatus ( ) ; } public info ( message ) { this . _validationStatus . state = parsers . ValidationState . Info ; vscode . window . showInformationMessage ( message ) ; } public warn ( message ) { this . _validationStatus . state = parsers . ValidationState . Warning ; vscode . window . showWarningMessage ( message ) ; } public error ( message ) { this . _validationStatus . state = parsers . ValidationState . Error ; vscode . window . showErrorMessage ( message ) ; } public fatal ( message ) { this . _validationStatus . state = parsers . ValidationState . Fatal ; vscode . window . showErrorMessage ( message ) ; throw new TypeError ( message ) ; } public get status ( ) : parsers . ValidationStatus { return this . _validationStatus ; } }