import * as vscode from 'vscode' ; import { Rubocop , RubocopAutocorrectProvider } from './rubocop' ; import { onDidChangeConfiguration } from './configuration' ; export function activate ( context ) { 'use strict' ; const diag = vscode . languages . createDiagnosticCollection ( 'ruby' ) ; context . subscriptions . push ( diag ) ; const rubocop = new Rubocop ( diag ) ; const disposable = vscode . commands . registerCommand ( 'ruby.rubocop' , ( ) => { const document = vscode . window . activeTextEditor . document ; rubocop . execute ( document ) ; } ) ; context . subscriptions . push ( disposable ) ; const ws = vscode . workspace ; ws . onDidChangeConfiguration ( onDidChangeConfiguration ( rubocop ) ) ; ws . textDocuments . forEach ( ( e ) => { rubocop . execute ( e ) ; } ) ; ws . onDidOpenTextDocument ( ( e ) => { rubocop . execute ( e ) ; } ) ; ws . onDidSaveTextDocument ( ( e ) => { if ( rubocop . isOnSave ) { rubocop . execute ( e ) ; } } ) ; ws . onDidCloseTextDocument ( ( e ) => { rubocop . clear ( e ) ; } ) ; const formattingProvider = new RubocopAutocorrectProvider ( ) ; vscode . languages . registerDocumentFormattingEditProvider ( 'ruby' , formattingProvider ) ; vscode . languages . registerDocumentFormattingEditProvider ( 'gemfile' , formattingProvider ) ; }