Language - JavaScript - LSP
Define JavaScript language LSP Integration package.
(use-package emacs
:after (uno-lang-js uno-dev-lsp projectile)
:config
(provide 'uno-lang-js-lsp))
(use-package emacs
:after uno-lang-js-lsp
:init
(require 'seq)
(defun uno/lang/js/lsp/add-to-local (name file)
"Add NAME dependency from FILE to local instance."
(when (uno/lang/js/lsp/local-provider file)
(lsp-dependency name `(:local ,file))
t))
(defun uno/lang/js/lsp/check ()
"Set up support with local SDK instance."
(when (uno/lang/js/lsp/local-provider)
(require 'lsp-javascript)
(make-local-variable 'lsp-enabled-clients)
(plist-put lsp-deps-providers
:local '(:path uno/lang/js/lsp/local-provider))
(setq-local lsp-auto-guess-root t)
(run-hooks 'uno-lang-js-lsp-hook)))
(defun uno/lang/js/lsp/local-provider (&optional path)
"Provide path for local SDK instance relative to PATH."
(seq-reduce
(lambda (current sdk)
(if current
current
(let ((-path (concat (projectile-project-root) sdk path)))
(if (file-exists-p -path) -path nil))))
'(".yarn/sdks/" "node_modules/")
nil))
(defun uno/lang/js/lsp/local-provider-type (&optional path)
"Check SDK instance type relative to PATH."
(let ((-path (uno/lang/js/lsp/local-provider path)))
(cond
(string-match-p ".yarn/sdks/" -path) "yarn")
(string-match-p "node_modules/" -path) "npm")))
(use-package emacs
:after (uno-lang-js-lsp flycheck)
:hook
(uno-lang-js-lsp . uno/lang/js/eslint/add)
:init
(defun uno/lang/js/eslint/add ()
"Add support for ESLint."
(when (uno/lang/js/lsp/local-provider "eslint/bin/eslint.js")
(let ((-eslint-full
(uno/lang/js/lsp/local-provider "eslint/bin/eslint.js"))
(-node-path (uno/lang/js/lsp/local-provider)))
(setq-local
flycheck-javascript-eslint-executable -eslint-full
lsp-eslint-node-path -node-path
lsp-eslint-package-manager (uno/lang/js/lsp/local-provider-type)))
(push 'eslint lsp-enabled-clients)))
(uno/add-useless-buffer "\\*eslint\\*")
(uno/add-useless-buffer "\\*eslint::.*\\*"))