import { Disposable , TextDocumentContentChangeEvent , TextEditor , window , workspace , WorkspaceConfiguration } from 'vscode' ; import { IDocommentDomain } from '../Domain/IDocommentDomain' ; import { CommentSyntax , Configuration } from '../Entity/Config/Contributes/Configuration' ; import { IDocommentController } from './IDocommentController' ; export class DocommentController implements IDocommentController { public _languageId : string ; public _disposable : Disposable ; public constructor ( docommentDomain ) { const config = this . loadConfig ( ) ; const subscriptions = [ ] ; workspace . onDidChangeTextDocument ( event => { const activeEditor = window . activeTextEditor ; if ( activeEditor && event . document === activeEditor . document ) { this . _onEvent ( activeEditor , event . contentChanges [ 0 ] , config , docommentDomain ) ; } } , this , subscriptions ) ; workspace . onDidChangeConfiguration ( ( ) => { this . loadConfig ( ) ; } , this , subscriptions ) ; this . _disposable = Disposable . from ( ... subscriptions ) ; } public dispose ( ) { this . _disposable . dispose ( ) ; } private loadConfig ( ) { const confDocomment = workspace . getConfiguration ( Configuration . KEY_DOCOMMENT ) ; const confFiles = workspace . getConfiguration ( Configuration . KEY_FILES ) ; const confEditor = workspace . getConfiguration ( Configuration . KEY_EDITOR ) ; const config = new Configuration ( ) ; config . syntax = CommentSyntax [ confDocomment . get < string > ( Configuration . SYNTAX , CommentSyntax . single ) ] ; config . activateOnEnter = confDocomment . get < boolean > ( Configuration . ACTIVATE_ON_ENTER , false ) ; config . advanced = confDocomment . get < Object > ( Configuration . ADVANCED ) ; config . eol = confFiles . get < string > ( Configuration . EOL , '\n' ) ; config . insertSpaces = confEditor . get < boolean > ( Configuration . INSERT_SPACES , false ) ; config . detectIdentation = confEditor . get < boolean > ( Configuration . DETECT_IDENTATION , true ) ; return config ; } private _onEvent ( activeEditor , event , config , domain ) { domain . Execute ( activeEditor , event , this . _languageId , config ) ; } }