@@ -133,15 +133,19 @@ source.fixAll code action."
133133 :package-version '(lsp-mode . " 6.3" ))
134134
135135(defcustom lsp-eslint-working-directories []
136- " A vector of working directory names to use. Can be a pattern, an absolute path
137- or a path relative to the workspace. Examples:
136+ " A vector of working directory names to use.
137+ Can be a pattern, an absolute path, a path relative to the workspace,
138+ or a supported mode such as \" auto\" or \" location\" .
139+ Examples:
138140 - \" /home/user/abc/\"
139141 - \" abc/\"
140142 - (directory \" abc\" ) which is equivalent to \" abc\" above
141143 - (pattern \" abc/*\" )
144+ - (mode \" auto\" )
145+ - (mode \" location\" )
142146Note that the home directory reference ~/ is not currently supported, use
143147/home/[user]/ instead."
144- :type 'lsp-string -vector
148+ :type '( lsp-repeatable -vector (choice string (plist mode string)))
145149 :package-version '(lsp-mode . " 6.3" ))
146150
147151(defcustom lsp-eslint-validate '(" svelte" )
@@ -280,52 +284,57 @@ stored."
280284 (buffer (find-buffer-visiting file))
281285 (workspace-folder (lsp-find-session-folder (lsp-session) file)))
282286 (with-current-buffer buffer
283- (let ((working-directory (lsp-eslint--working-directory workspace-folder file)))
284- (list :validate (if (member (lsp-buffer-language) lsp-eslint-validate) " on" " probe" )
285- :packageManager lsp-eslint-package-manager
286- :codeAction (list
287- :disableRuleComment (list
288- :enable (lsp-json-bool lsp-eslint-code-action-disable-rule-comment)
289- :location lsp-eslint-code-action-disable-rule-comment-location)
290- :showDocumentation (list
291- :enable (lsp-json-bool lsp-eslint-code-action-show-documentation)))
292- :codeActionOnSave (list :enable (lsp-json-bool lsp-eslint-auto-fix-on-save)
293- :mode lsp-eslint-fix-all-problem-type)
294- :format (lsp-json-bool lsp-eslint-format)
295- :quiet (lsp-json-bool lsp-eslint-quiet)
296- :onIgnoredFiles (if lsp-eslint-warn-on-ignored-files " warn" " off" )
297- :options (or lsp-eslint-options (ht))
298- :experimental (or lsp-eslint-experimental (ht))
299- :problems (or lsp-eslint-config-problems (ht))
300- :timeBudget (or lsp-eslint-time-budget (ht))
301- :rulesCustomizations lsp-eslint-rules-customizations
302- :run lsp-eslint-run
303- :nodePath lsp-eslint-node-path
304- :workingDirectory (when working-directory
305- (list
306- :directory working-directory
307- :!cwd :json-false ))
308- :workspaceFolder (list :uri (lsp--path-to-uri workspace-folder)
309- :name (f-filename workspace-folder))))))))
287+ (list :validate (if (member (lsp-buffer-language) lsp-eslint-validate) " on" " probe" )
288+ :packageManager lsp-eslint-package-manager
289+ :codeAction (list
290+ :disableRuleComment (list
291+ :enable (lsp-json-bool lsp-eslint-code-action-disable-rule-comment)
292+ :location lsp-eslint-code-action-disable-rule-comment-location)
293+ :showDocumentation (list
294+ :enable (lsp-json-bool lsp-eslint-code-action-show-documentation)))
295+ :codeActionOnSave (list :enable (lsp-json-bool lsp-eslint-auto-fix-on-save)
296+ :mode lsp-eslint-fix-all-problem-type)
297+ :format (lsp-json-bool lsp-eslint-format)
298+ :quiet (lsp-json-bool lsp-eslint-quiet)
299+ :onIgnoredFiles (if lsp-eslint-warn-on-ignored-files " warn" " off" )
300+ :options (or lsp-eslint-options (ht))
301+ :experimental (or lsp-eslint-experimental (ht))
302+ :problems (or lsp-eslint-config-problems (ht))
303+ :timeBudget (or lsp-eslint-time-budget (ht))
304+ :rulesCustomizations lsp-eslint-rules-customizations
305+ :run lsp-eslint-run
306+ :nodePath lsp-eslint-node-path
307+ :workingDirectory (lsp-eslint--working-directory workspace-folder file)
308+ :workspaceFolder (list :uri (lsp--path-to-uri workspace-folder)
309+ :name (f-filename workspace-folder)))))))
310310 (apply #'vector )))
311311
312312(defun lsp-eslint--working-directory (workspace current-file )
313313 " Find the first directory in the parameter config.workingDirectories which
314314contains the current file"
315- (let ((directories (-map (lambda (dir )
316- (when (and (listp dir) (plist-member dir 'directory ))
317- (setq dir (plist-get dir 'directory )))
318- (if (and (listp dir) (plist-member dir 'pattern ))
319- (progn
320- (setq dir (plist-get dir 'pattern ))
321- (when (not (f-absolute? dir))
322- (setq dir (f-join workspace dir)))
323- (f-glob dir))
324- (if (f-absolute? dir)
325- dir
326- (f-join workspace dir))))
327- (append lsp-eslint-working-directories nil ))))
328- (-first (lambda (dir ) (f-ancestor-of-p dir current-file)) (-flatten directories))))
315+ (let* ((directories (-map (lambda (dir )
316+ (when (and (listp dir) (plist-member dir 'directory ))
317+ (setq dir (plist-get dir 'directory )))
318+ (cond
319+ ((not (listp dir))
320+ (if (f-absolute? dir) dir (f-join workspace dir)))
321+ ((plist-member dir 'pattern )
322+ (setq dir (plist-get dir 'pattern ))
323+ (when (not (f-absolute? dir))
324+ (setq dir (f-join workspace dir)))
325+ (f-glob dir))
326+ ((plist-member dir 'mode )
327+ ; ; we don't want this setting to get flattened by -flatten
328+ `(mode . ,(plist-get dir 'mode )))))
329+ (append lsp-eslint-working-directories nil )))
330+ (working-directory (-first (lambda (dir )
331+ (if (stringp dir)
332+ (f-ancestor-of-p dir current-file)
333+ dir))
334+ (-flatten directories))))
335+ (cond
336+ ((consp working-directory) `(:mode ,(cdr working-directory)))
337+ ((stringp working-directory) (list :directory working-directory :!cwd :json-false )))))
329338
330339(lsp-defun lsp-eslint--open-doc (_workspace (&eslint:OpenESLintDocParams :url ))
331340 " Open documentation."
0 commit comments