lang/javascript: conform to naming conventions; refactor tide config

This commit is contained in:
Henrik Lissner 2018-04-18 18:04:49 -04:00
parent 8af94e8731
commit cc5bfc6dc0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 25 additions and 25 deletions

View file

@ -75,30 +75,18 @@ Run this for any buffer you want to skewer."
(if skewer-html-mode (skewer-html-mode -1))))) (if skewer-html-mode (skewer-html-mode -1)))))
;;;###autoload ;;;###autoload
(defun add-node-modules-path () (defun +javascript|add-node-modules-path ()
"Search the current buffer's parent directories for `node_modules/.bin`. "Search the current buffer's parent directories for `node_modules/.bin`.
If it's found, then add it to the `exec-path'." If it's found, then add it to the `exec-path'."
(defvar add-node-modules-path-debug nil)
(interactive) (interactive)
(let* ((root (locate-dominating-file (if-let* ((root (locate-dominating-file
(or (buffer-file-name) default-directory) (or (buffer-file-name) default-directory)
"node_modules")) "node_modules"))
(path (and root (path (expand-file-name "node_modules/.bin/" root)))
(expand-file-name "node_modules/.bin/" root))))
(if root
(progn (progn
(make-local-variable 'exec-path) (make-local-variable 'exec-path)
(add-to-list 'exec-path path) (cl-pushnew path exec-path :test #'string=)
(when add-node-modules-path-debug (when doom-debug-mode
(message (concat "added " path " to exec-path")))) (message "Added %s to exec-path" path)))
(when add-node-modules-path-debug (when doom-debug-mode
(message (concat "node_modules not found in " root)))))) (message "node_modules not found in %s" root))))
;;;###autoload
(defun set-up-tide-mode ()
(interactive)
(tide-setup)
(if company-mode (push 'company-tide company-backends))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
)

View file

@ -11,7 +11,8 @@
js2-mode-show-parse-errors nil js2-mode-show-parse-errors nil
js2-mode-show-strict-warnings nil) js2-mode-show-strict-warnings nil)
(add-hook! 'js2-mode-hook #'(flycheck-mode set-up-tide-mode add-node-modules-path rainbow-delimiters-mode)) (add-hook! 'js2-mode-hook
#'(flycheck-mode rainbow-delimiters-mode +javascript|add-node-modules-path))
(set! :repl 'js2-mode #'+javascript/repl) (set! :repl 'js2-mode #'+javascript/repl)
(set! :electric 'js2-mode :chars '(?\} ?\) ?.)) (set! :electric 'js2-mode :chars '(?\} ?\) ?.))
@ -45,6 +46,17 @@
:n "S" #'+javascript/skewer-this-buffer)) :n "S" #'+javascript/skewer-this-buffer))
(def-package! tide
:hook (js2-mode . tide-setup)
:config
(set! :company 'js2-mode 'company-tide)
(set! :lookup 'js2-mode
:definition #'tide-jump-to-definition
:references #'tide-references
:documentation #'tide-documentation-at-point)
(add-hook! 'tide-mode-hook #'(eldoc-mode tide-hl-identifier-mode)))
;; A find-{definition,references} backend for js2-mode. NOTE The xref API is ;; A find-{definition,references} backend for js2-mode. NOTE The xref API is
;; unstable and may break with an Emacs update. ;; unstable and may break with an Emacs update.
(def-package! xref-js2 (def-package! xref-js2