import * as vscode from "vscode" ; import { debounce } from "lodash" ; import { LinterOffense } from "vscode-linter-api" ; import { CodeActionProvider } from "./CodeActionProvider" ; import { run , fix , fixInline , ignore } from "./linters/run" ; import { getEditor } from "./helpers/getEditor" ; export function activate ( context ) { const runLinters = debounce ( run , 200 ) ; const runFix = debounce ( fix , 200 ) ; const runIgnore = debounce ( ignore , 200 ) ; const { subscriptions } = context ; const offenses = [ ] ; const diagnostics = vscode . languages . createDiagnosticCollection ( "linter" ) ; const codeActionProvider = new CodeActionProvider ( diagnostics , offenses ) ; if ( vscode . window . activeTextEditor ) { runLinters ( vscode . window . activeTextEditor . document , diagnostics , offenses ) ; } subscriptions . push ( vscode . window . onDidChangeActiveTextEditor ( ( editor ) => { if ( editor ) { runLinters ( editor . document , diagnostics , offenses ) ; } } ) ) ; subscriptions . push ( vscode . workspace . onDidChangeTextDocument ( ( { document } ) => { runLinters ( document , diagnostics , offenses ) ; } ) ) ; subscriptions . push ( vscode . languages . registerCodeActionsProvider ( "*" , codeActionProvider ) ) ; subscriptions . push ( vscode . commands . registerCommand ( "linter.fix" , ( offense , type ) => { const editor = getEditor ( offense . uri ) ; if ( editor ) { runFix ( offense , editor , type ) ; } } ) ) ; subscriptions . push ( vscode . commands . registerCommand ( "linter.fixInline" , ( offense ) => { const editor = getEditor ( offense . uri ) ; if ( editor ) { fixInline ( offense , editor ) ; } } ) ) ; subscriptions . push ( vscode . commands . registerCommand ( "linter.openUrl" , ( url ) => { vscode . env . openExternal ( vscode . Uri . parse ( url ) ) ; } ) ) ; subscriptions . push ( vscode . commands . registerCommand ( "linter.ignoreOffense" , ( offense , type ) => { runIgnore ( offense , type ) ; } ) ) ; } export function deactivate ( ) { }