36
36
:group 'lsp-mode
37
37
:link '(url-link " https://github.com/Microsoft/vscode-eslint" ))
38
38
39
+ (defcustom lsp-eslint-unzipped-path (f-join lsp-server-install-dir " eslint/unzipped" )
40
+ " The path to the file in which `eslint' will be stored."
41
+ :type 'file
42
+ :group 'lsp-eslint
43
+ :package-version '(lsp-mode . " 7.1" ))
44
+
39
45
(defcustom lsp-eslint-server-command `(" node"
40
46
" ~/server/out/eslintServer.js"
41
47
" --stdio" )
67
73
:type '(repeat string)
68
74
:package-version '(lsp-mode . " 6.3" ))
69
75
76
+ (defcustom lsp-eslint-node " node"
77
+ " Path to nodejs."
78
+ :type 'file
79
+ :package-version '(lsp-mode . " 7.1" ))
80
+
70
81
(defcustom lsp-eslint-options nil
71
82
" The eslint options object to provide args normally passed to
72
83
eslint when executed from a command line (see
@@ -227,16 +238,32 @@ source.fixAll code action."
227
238
(when (called-interactively-p 'any )
228
239
(lsp--info " source.fixAll.eslint action not available" )))))
229
240
241
+ (defun lsp-eslint-server-command ()
242
+ (if (lsp-eslint-server-exists? lsp-eslint-server-command)
243
+ lsp-eslint-server-command
244
+ `(, lsp-eslint-node ,(f-join lsp-eslint-unzipped-path
245
+ " extension/server/out/eslintServer.js" )
246
+ " --stdio" )))
247
+
248
+ (defun lsp-eslint-server-exists? (eslint-server-command )
249
+ (let* ((command-name (f-base (f-filename (cl-first eslint-server-command))))
250
+ (first-argument (cl-second eslint-server-command))
251
+ (first-argument-exist (and first-argument (file-exists-p first-argument))))
252
+ (if (equal command-name lsp-eslint-node)
253
+ first-argument-exist
254
+ (executable-find (cl-first eslint-server-command)))))
255
+
256
+ (defun lsp-eslint--confirm-local (_workspace _params )
257
+ ; ; don't bother implementing since it will be dropped in next version of the
258
+ ; ; server
259
+ t )
260
+
230
261
(lsp-register-client
231
262
(make-lsp-client
232
263
:new-connection
233
264
(lsp-stdio-connection
234
- (lambda () lsp-eslint-server-command)
235
- (lambda ()
236
- (let* ((command-name (f-base (f-filename (cl-first lsp-eslint-server-command))))
237
- (first-argument (cl-second lsp-eslint-server-command))
238
- (first-argument-exist (and first-argument (file-exists-p first-argument))))
239
- (if (equal command-name " node" ) first-argument-exist (executable-find (cl-first lsp-eslint-server-command))))))
265
+ (lambda () (lsp-eslint-server-command))
266
+ (lambda () (lsp-eslint-server-exists? (lsp-eslint-server-command))))
240
267
:activation-fn (lambda (filename &optional _ )
241
268
(or (string-match-p (rx (one-or-more anything) " ."
242
269
(or " ts" " js" " jsx" " tsx" " html" " vue" ))
@@ -248,7 +275,8 @@ source.fixAll code action."
248
275
:multi-root t
249
276
:notification-handlers (ht (" eslint/status" #'lsp-eslint-status-handler ))
250
277
:request-handlers (ht (" workspace/configuration" #'lsp-eslint--configuration )
251
- (" eslint/openDoc" 'lsp-eslint--open-doc ))
278
+ (" eslint/openDoc" #'lsp-eslint--open-doc )
279
+ (" eslint/confirmLocalESLint" #'lsp-eslint--confirm-local ))
252
280
:server-id 'eslint
253
281
:initialized-fn (lambda (workspace )
254
282
(with-lsp-workspace workspace
@@ -263,7 +291,20 @@ source.fixAll code action."
263
291
,(lsp-make-file-system-watcher
264
292
:glob-pattern " **/.eslintignore" )
265
293
,(lsp-make-file-system-watcher
266
- :glob-pattern " **/package.json" )])))))))
294
+ :glob-pattern " **/package.json" )])))))
295
+ :download-server-fn (lambda (_client callback error-callback _update? )
296
+ (let ((tmp-zip (make-temp-file " ext" nil " .zip" )))
297
+ (delete-file tmp-zip)
298
+ (lsp-download-install
299
+ (lambda (&rest _ )
300
+ (condition-case err
301
+ (progn
302
+ (lsp-unzip tmp-zip lsp-eslint-unzipped-path)
303
+ (funcall callback))
304
+ (error (funcall error-callback err))))
305
+ error-callback
306
+ :url (lsp-vscode-extension-url " dbaeumer" " vscode-eslint" )
307
+ :store-path tmp-zip)))))
267
308
268
309
(provide 'lsp-eslint )
269
310
; ;; lsp-eslint.el ends here
0 commit comments