Skip to content

Commit 759c35a

Browse files
committed
run the linter on each change
1 parent ff52cd2 commit 759c35a

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

src/clojureEval.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ import { cljConnection } from './cljConnection';
44
import { cljParser } from './cljParser';
55
import { nreplClient } from './nreplClient';
66
import {readBooleanConfiguration} from './utils';
7-
import { ClojureLintingProvider } from './clojureLintingProvider';
87

98
function getAlertOnEvalResult() {
109
return readBooleanConfiguration('aletOnEval');
1110
}
1211

13-
export function clojureEval(outputChannel: vscode.OutputChannel, linter: ClojureLintingProvider): void {
14-
evaluate(outputChannel, linter, false);
12+
export function clojureEval(outputChannel: vscode.OutputChannel): void {
13+
evaluate(outputChannel, false);
1514
}
1615

17-
export function clojureEvalAndShowResult(outputChannel: vscode.OutputChannel, linter: ClojureLintingProvider): void {
18-
evaluate(outputChannel, linter, true);
16+
export function clojureEvalAndShowResult(outputChannel: vscode.OutputChannel): void {
17+
evaluate(outputChannel, true);
1918
}
2019

2120
export function evaluateText(outputChannel: vscode.OutputChannel,
@@ -37,14 +36,13 @@ export function evaluateText(outputChannel: vscode.OutputChannel,
3736
});
3837
}
3938

40-
function evaluate(outputChannel: vscode.OutputChannel, linter: ClojureLintingProvider, showResults: boolean): void {
39+
function evaluate(outputChannel: vscode.OutputChannel, showResults: boolean): void {
4140
if (!cljConnection.isConnected()) {
4241
vscode.window.showWarningMessage('You should connect to nREPL first to evaluate code.');
4342
return;
4443
}
4544

46-
const editor = vscode.window.activeTextEditor;
47-
linter.runLinter(editor.document);
45+
const editor = vscode.window.activeTextEditor;
4846

4947
const selection = editor.selection;
5048
let text = editor.document.getText();

src/clojureLintingProvider.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,21 @@ export class ClojureLintingProvider {
170170
});
171171
}
172172

173-
public runLinter(textDocument: TextDocument) {
174-
this.diagnosticCollection.delete(textDocument.uri);
175-
this.lint(textDocument);
176-
}
177-
178173
public activate(subscriptions: vscode.Disposable[]) {
179174
subscriptions.push(this);
180175
this.diagnosticCollection = vscode.languages.createDiagnosticCollection();
181176

182177
vscode.workspace.onDidOpenTextDocument(this.lint, this, subscriptions);
178+
179+
vscode.workspace.onDidChangeTextDocument(e=> {
180+
181+
this.diagnosticCollection.delete(e.document.uri);
182+
this.lint(e.document);
183+
});
184+
183185
vscode.workspace.onDidCloseTextDocument((textDocument)=> {
184186
this.diagnosticCollection.delete(textDocument.uri);
185187
}, null, subscriptions);
186-
187-
vscode.workspace.onDidSaveTextDocument(this.runLinter, this);
188188
}
189189

190190
public dispose(): void {

src/clojureMain.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export function activate(context: vscode.ExtensionContext) {
3131
vscode.commands.registerCommand('clojureVSCode.startNRepl', cljConnection.startNRepl);
3232

3333
const evaluationResultChannel = vscode.window.createOutputChannel('Evaluation results');
34-
let linter = new ClojureLintingProvider(evaluationResultChannel);
34+
3535

36-
vscode.commands.registerCommand('clojureVSCode.eval', () => clojureEval(evaluationResultChannel, linter));
37-
vscode.commands.registerCommand('clojureVSCode.evalAndShowResult', () => clojureEvalAndShowResult(evaluationResultChannel, linter));
36+
vscode.commands.registerCommand('clojureVSCode.eval', () => clojureEval(evaluationResultChannel));
37+
vscode.commands.registerCommand('clojureVSCode.evalAndShowResult', () => clojureEvalAndShowResult(evaluationResultChannel));
3838
vscode.commands.registerTextEditorCommand('clojureVSCode.formatFile', formatFile);
39-
vscode.commands.registerTextEditorCommand('clojureVSCode.reloadNamespace', ()=> { reloadNamespaceCommand(evaluationResultChannel, linter); });
39+
vscode.commands.registerTextEditorCommand('clojureVSCode.reloadNamespace', ()=> { reloadNamespaceCommand(evaluationResultChannel); });
4040
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(CLOJURE_MODE, new ClojureCompletionItemProvider(), '.', '/'));
4141
context.subscriptions.push(vscode.languages.registerDefinitionProvider(CLOJURE_MODE, new ClojureDefinitionProvider()));
4242
context.subscriptions.push(vscode.languages.registerHoverProvider(CLOJURE_MODE, new ClojureHoverProvider()));
@@ -48,11 +48,11 @@ export function activate(context: vscode.ExtensionContext) {
4848
if(getReloadOnFileSave()) {
4949
vscode.workspace.onDidSaveTextDocument(
5050
function (textDocument: vscode.TextDocument) {
51-
reloadNamespaceCommand(evaluationResultChannel, linter);
51+
reloadNamespaceCommand(evaluationResultChannel);
5252
}, this);
5353
}
5454

55-
55+
let linter = new ClojureLintingProvider(evaluationResultChannel);
5656
linter.activate(context.subscriptions);
5757
}
5858

src/clojureReloadNamespace.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ import { cljConnection } from './cljConnection';
33
import { cljParser } from './cljParser';
44
import { handleError, evaluateText } from './clojureEval';
55
import {readBooleanConfiguration} from './utils';
6-
import { ClojureLintingProvider } from './clojureLintingProvider';
76

87
export function getReloadOnFileSave() :boolean {
98
return readBooleanConfiguration('autoReloadNamespaceOnSave')
109
}
1110

1211
export function reloadNamespaceCommand(
13-
outputChannel: vscode.OutputChannel,
14-
linter: ClojureLintingProvider) {
12+
outputChannel: vscode.OutputChannel) {
1513

1614
if (!cljConnection.isConnected()) {
1715
return;
1816
}
1917

20-
const textDocument = vscode.window.activeTextEditor.document;
21-
linter.runLinter(textDocument);
18+
const textDocument = vscode.window.activeTextEditor.document;
2219

2320
const fileName = textDocument.fileName;
2421
if(!fileName.endsWith(".clj")) {

0 commit comments

Comments
 (0)