@@ -5,6 +5,7 @@ import { resolve } from 'dns';
55import { Diagnostic , Range , TextDocument } from 'vscode' ;
66import { cljParser } from './cljParser' ;
77import { CLOJURE_MODE } from './clojureMode' ;
8+ import { handleError } from './clojureEval' ;
89
910interface LinterWarningResult {
1011
@@ -59,23 +60,32 @@ const infoSeverity: string[] = ["no-ns-form-found",
5960
6061export 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 }
0 commit comments