| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
6c426860c2 | Formatting | 3 years ago |
|
|
4181f2937b | Refine git settings | 3 years ago |
|
|
b995505100 | Improve LSP settings | 3 years ago |
| @ -0,0 +1,75 @@ | |||||
| #+TITLE: Language - JavaScript - LSP | |||||
| #+AUTHOR: Juan Placencia | |||||
| * Package | |||||
| Define JavaScript language LSP Integration package. | |||||
| #+BEGIN_SRC emacs-lisp | |||||
| (use-package emacs | |||||
| :after (uno-lang-js uno-dev-lsp projectile) | |||||
| :config | |||||
| (provide 'uno-lang-js-lsp)) | |||||
| #+END_SRC | |||||
| * LSP Integration | |||||
| #+BEGIN_SRC emacs-lisp | |||||
| (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"))) | |||||
| #+END_SRC | |||||
| ** ESLint Integration | |||||
| #+BEGIN_SRC emacs-lisp | |||||
| (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::.*\\*")) | |||||
| #+END_SRC | |||||
| @ -1,65 +0,0 @@ | |||||
| #+TITLE: Language - JavaScript - Yarn | |||||
| #+AUTHOR: Juan Placencia | |||||
| * Package | |||||
| Define JavaScript language package. | |||||
| #+BEGIN_SRC emacs-lisp | |||||
| (use-package emacs | |||||
| :after (uno-lang-js uno-dev-lsp projectile) | |||||
| :config | |||||
| (provide 'uno-lang-js-yarn)) | |||||
| #+END_SRC | |||||
| * LSP Integration | |||||
| #+BEGIN_SRC emacs-lisp | |||||
| (use-package emacs | |||||
| :after uno-lang-js-yarn | |||||
| :init | |||||
| (defun uno/lang/js/yarn/add-to-local-lsp (name file) | |||||
| "Add NAME dependency from FILE to local yarn instance." | |||||
| (when (uno/lang/js/yarn/local-p file) | |||||
| (lsp-dependency name `(:yarn-local ,file)) | |||||
| t)) | |||||
| (defun uno/lang/js/yarn/check () | |||||
| "Set up support with local Yarn instance." | |||||
| (when (uno/lang/js/yarn/local-p) | |||||
| (require 'lsp-javascript) | |||||
| (make-local-variable 'lsp-enabled-clients) | |||||
| (plist-put lsp-deps-providers | |||||
| :yarn-local '(:path uno/lang/js/yarn/local-provider)) | |||||
| (setq-local lsp-auto-guess-root t) | |||||
| (run-hooks 'uno-lang-js-yarn-hook))) | |||||
| (defun uno/lang/js/yarn/local-p (&optional file) | |||||
| "Check if Yarn SDK is available locally." | |||||
| (if file | |||||
| (file-exists-p (uno/lang/js/yarn/local-provider file)) | |||||
| (file-directory-p (uno/lang/js/yarn/local-provider)))) | |||||
| (defun uno/lang/js/yarn/local-provider (&optional path) | |||||
| "Provide path for local yarn instance relative to PATH." | |||||
| (concat (projectile-project-root) ".yarn/sdks/" path))) | |||||
| #+END_SRC | |||||
| ** ESLint Integration | |||||
| #+BEGIN_SRC emacs-lisp | |||||
| (use-package emacs | |||||
| :after (uno-lang-js-yarn flycheck) | |||||
| :hook | |||||
| (uno-lang-js-yarn . uno/lang/js/eslint/add) | |||||
| :init | |||||
| (defun uno/lang/js/eslint/add () | |||||
| "Add support for ESLint." | |||||
| (when (uno/lang/js/yarn/local-p "eslint/bin/eslint.js") | |||||
| (let ((-eslint-full (uno/lang/js/yarn/local-provider "eslint/bin/eslint.js")) | |||||
| (-node-path (uno/lang/js/yarn/local-provider))) | |||||
| (setq-local | |||||
| flycheck-javascript-eslint-executable -eslint-full | |||||
| lsp-eslint-node-path -node-path | |||||
| lsp-eslint-package-manager "yarn")) | |||||
| (push 'eslint lsp-enabled-clients))) | |||||
| (uno/add-useless-buffer "\\*eslint\\*") | |||||
| (uno/add-useless-buffer "\\*eslint::.*\\*")) | |||||
| #+END_SRC | |||||