spacemacs/layers/+frameworks/react/funcs.el
Thanh Vuong ce30353b52 js, ts and react layers: linter option
this PR does two things for js-related layers:

(i) add option to disable lsp linter
javascript-lsp-linter for javascript and react layers
typescript-lsp-linter for typescript layer
when the value is t, lsp linter will be used in the layer
when nil, let flycheck pick up the best linters available such
as eslint

(ii) when syntax-checking(flycheck) layer is installed, then set
next-error-function value in react and javascript layers to nil, so that
spacemacs next-error, previous-error work A desciption of this issue can be
found at https://github.com/syl20bnr/spacemacs/issues/8078

Co-Authored-By: duianto <otnaiud@gmail.com>
2019-07-26 18:04:25 +02:00

84 lines
2.7 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; funcs.el --- react layer funcs file for Spacemacs. -*- lexical-binding: t -*-
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Muneeb Shaikh <muneeb@reversehack.in>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; Backend
(defun spacemacs//react-setup-backend ()
"Conditionally setup react backend."
(pcase javascript-backend
(`tern (spacemacs/tern-setup-tern))
(`lsp (spacemacs//react-setup-lsp))))
(defun spacemacs//react-setup-company ()
"Conditionally setup company based on backend."
(pcase javascript-backend
(`tern (spacemacs/tern-setup-tern-company 'rjsx-mode))
(`lsp (spacemacs//react-setup-lsp-company))))
(defun spacemacs//react-setup-next-error-fn ()
"If the `syntax-checking' layer is enabled, disable `rjsx-mode''s
`next-error-function', and let `flycheck' handle any errors."
(when (configuration-layer/layer-used-p 'syntax-checking)
(setq-local next-error-function nil)))
;; LSP
(defun spacemacs//react-setup-lsp ()
"Setup lsp backend."
(if (configuration-layer/layer-used-p 'lsp)
(progn
(when (not javascript-lsp-linter)
(setq-local lsp-prefer-flymake :none))
(lsp))
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
(defun spacemacs//react-setup-lsp-company ()
"Setup lsp auto-completion."
(if (configuration-layer/layer-used-p 'lsp)
(progn
(spacemacs|add-company-backends
:backends company-lsp
:modes rjsx-mode
:variables company-minimum-prefix-length 2
:append-hooks nil
:call-hooks t)
(company-mode))
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
;; Emmet
(defun spacemacs/react-emmet-mode ()
"Activate `emmet-mode' and configure it for local buffer."
(emmet-mode)
(setq-local emmet-expand-jsx-className? t))
;; Others
(defun spacemacs//react-inside-string-q ()
"Returns non-nil if inside string, else nil.
Result depends on syntax table's string quote character."
(let ((result (nth 3 (syntax-ppss))))
result))
(defun spacemacs//react-inside-comment-q ()
"Returns non-nil if inside comment, else nil.
Result depends on syntax table's comment character."
(let ((result (nth 4 (syntax-ppss))))
result))
(defun spacemacs//react-inside-string-or-comment-q ()
"Return non-nil if point is inside string, documentation string or a comment.
If optional argument P is present, test this instead of point."
(or (spacemacs//react-inside-string-q)
(spacemacs//react-inside-comment-q)))
(defun spacemacs//react-setup-yasnippet ()
(yas-activate-extra-mode 'js-mode))