@@ -4,16 +4,14 @@ import * as vscode from 'vscode';
44import { Location , ExtensionContext , Position } from 'vscode' ;
55import * as Locate from './locate/locate' ;
66import * as path from 'path' ;
7- import { LintCollection } from './lint/lintCollection' ;
87import * as utils from './utils' ;
98import { registerTaskProvider } from './task/rake' ;
10- import { Config as LintConfig } from './lint/lintConfig' ;
11- import * as debounce from 'lodash/debounce' ;
129
1310import { registerCompletionProvider } from './providers/completion' ;
1411import { registerFormatter } from './providers/formatter' ;
1512import { registerHighlightProvider } from './providers/highlight' ;
1613import { registerIntellisenseProvider } from './providers/intellisense' ;
14+ import { registerLinters } from './providers/linters' ;
1715
1816export function activate ( context : ExtensionContext ) {
1917 const subs = context . subscriptions ;
@@ -34,51 +32,3 @@ export function activate(context: ExtensionContext) {
3432 registerTaskProvider ( context ) ;
3533 utils . loadEnv ( ) ;
3634}
37-
38- function getGlobalLintConfig ( ) : LintConfig {
39- let globalConfig = new LintConfig ( ) ;
40-
41- let pathToRuby = vscode . workspace . getConfiguration ( "ruby.interpreter" ) . commandPath ;
42- if ( pathToRuby ) {
43- globalConfig . pathToRuby = pathToRuby ;
44- }
45-
46- let useBundler = vscode . workspace . getConfiguration ( "ruby" ) . get < boolean | null > ( "useBundler" ) ;
47- if ( useBundler !== null ) {
48- globalConfig . useBundler = useBundler ;
49- }
50-
51- let pathToBundler = vscode . workspace . getConfiguration ( "ruby" ) . pathToBundler ;
52- if ( pathToBundler ) {
53- globalConfig . pathToBundler = pathToBundler ;
54- }
55- return globalConfig ;
56- }
57-
58- function registerLinters ( ctx : ExtensionContext ) {
59- const globalConfig = getGlobalLintConfig ( ) ;
60- const linters = new LintCollection ( globalConfig , vscode . workspace . getConfiguration ( "ruby" ) . lint , vscode . workspace . rootPath ) ;
61- ctx . subscriptions . push ( linters ) ;
62-
63- function executeLinting ( e : vscode . TextEditor | vscode . TextDocumentChangeEvent ) {
64- if ( ! e ) return ;
65- linters . run ( e . document ) ;
66- }
67-
68- // Debounce linting to prevent running on every keypress, only run when typing has stopped
69- const lintDebounceTime = vscode . workspace . getConfiguration ( 'ruby' ) . lintDebounceTime ;
70- const executeDebouncedLinting = debounce ( executeLinting , lintDebounceTime ) ;
71-
72- ctx . subscriptions . push ( vscode . window . onDidChangeActiveTextEditor ( executeLinting ) ) ;
73- ctx . subscriptions . push ( vscode . workspace . onDidChangeTextDocument ( executeDebouncedLinting ) ) ;
74- ctx . subscriptions . push ( vscode . workspace . onDidChangeConfiguration ( ( ) => {
75- const docs = vscode . window . visibleTextEditors . map ( editor => editor . document ) ;
76- console . log ( "Config changed. Should lint:" , docs . length ) ;
77- const globalConfig = getGlobalLintConfig ( ) ;
78- linters . cfg ( vscode . workspace . getConfiguration ( "ruby" ) . lint , globalConfig ) ;
79- docs . forEach ( doc => linters . run ( doc ) ) ;
80- } ) ) ;
81-
82- // run against all of the current open files
83- vscode . window . visibleTextEditors . forEach ( executeLinting ) ;
84- }
0 commit comments