Skip to content

Commit c315956

Browse files
committed
fix bug in linter
1 parent 96bba74 commit c315956

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/clojureLintingProvider.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { resolve } from 'dns';
55
import { Diagnostic, Range, TextDocument } from 'vscode';
66
import { cljParser } from './cljParser';
77
import { CLOJURE_MODE } from './clojureMode';
8+
import { handleError } from './clojureEval';
89

910
interface LinterWarningResult {
1011

@@ -59,23 +60,32 @@ const infoSeverity: string[] = ["no-ns-form-found",
5960

6061
export class ClojureLintingProvider {
6162

63+
private outputChannel: vscode.OutputChannel;
64+
65+
constructor(channel: vscode.OutputChannel) {
66+
this.outputChannel = channel;
67+
}
68+
6269
private getLintCommand(ns): string {
70+
console.log(ns);
6371
return `(do (require '[eastwood.lint])
6472
(require '[clojure.data.json])
65-
(-> ;(eastwood.lint/lint {:namespaces ['${ns}]})
66-
(eastwood.lint/lint {:namespaces ['madlan.server.sms-api]})
73+
(-> (eastwood.lint/lint {:namespaces ['${ns}]})
6774
(select-keys [:warnings :err :err-data])
68-
(update :warnings (fn [x] (map #(select-keys % [:msg :line :column :linter]) x)))
75+
(update :warnings (fn [x] (map #(select-keys % [:msg :line :column :linter]) x)))
6976
(update :err-data :exception)
70-
(update :err-data Throwable->map)
71-
(update :err-data #(select-keys % [:cause :data]))
77+
((fn [data]
78+
(if-let [err-data (:err-data data)]
79+
(-> data
80+
(update :err-data Throwable->map)
81+
(update :err-data #(select-keys % [:cause :data])))
82+
data)))
7283
(clojure.data.json/write-str)))`;
7384
}
7485

7586
private diagnosticCollection: vscode.DiagnosticCollection;
7687

77-
private parseLintSuccessResponse(response: string): LinterResult {
78-
88+
private parseLintSuccessResponse(response: string): LinterResult {
7989
const parsedToString = JSON.parse(response);
8090
return JSON.parse(parsedToString);
8191
}
@@ -130,9 +140,16 @@ export class ClojureLintingProvider {
130140
nreplClient.evaluate(command)
131141
.then(result => {
132142
try {
133-
let lintResult: LinterResult = this.parseLintSuccessResponse(result[0].value);
134-
const diagnostics = this.createDiagnosticCollectionFromLintResult(textDocument, lintResult);
135-
this.diagnosticCollection.set(textDocument.uri, diagnostics);
143+
if(!!result[0].ex) {
144+
handleError(this.outputChannel,
145+
new vscode.Selection(0,0,0,0),
146+
false,
147+
result[0].session);
148+
} else {
149+
let lintResult: LinterResult = this.parseLintSuccessResponse(result[0].value);
150+
const diagnostics = this.createDiagnosticCollectionFromLintResult(textDocument, lintResult);
151+
this.diagnosticCollection.set(textDocument.uri, diagnostics);
152+
}
136153
} catch(e) {
137154
console.error(e);
138155
}

src/clojureMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function activate(context: vscode.ExtensionContext) {
5050
}, this);
5151
}
5252

53-
let linter = new ClojureLintingProvider;
53+
let linter = new ClojureLintingProvider(evaluationResultChannel);
5454
linter.activate(context.subscriptions);
5555
}
5656

0 commit comments

Comments
 (0)