tide只对打开的第一个js文件有效,关闭这个buffer或者打开其他js文件都无效


#1
(use-package tide
    :ensure t
    :after (typescript-mode company flycheck)
    ;;:hook ((typescript-mode . tide-setup)
      ;;     (typescript-mode . tide-hl-identifier-mode)
        ;;   (before-save . tide-format-before-save))
    )
  ;;typescript
  (require 'flycheck)
  (defun setup-tide-mode ()
  (interactive)
  (tide-setup)
  (flycheck-mode +1)
  (setq flycheck-check-syntax-automatically '(save mode-enabled))
  (eldoc-mode +1)
  (tide-hl-identifier-mode +1)
  ;; company is an optional dependency. You have to
  ;; install it separately via package-install
  ;; `M-x package-install [ret] company`
  (company-mode +1))

  ;; aligns annotation to the right hand side
  (setq company-tooltip-align-annotations t)

  ;; formats the buffer before saving
  (add-hook 'before-save-hook 'tide-format-before-save)

  (add-hook 'typescript-mode-hook #'setup-tide-mode)
  (add-hook 'js2-mode-hook #'setup-tide-mode)
  ;;tsx
  (require 'web-mode)
  (add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
  (add-hook 'web-mode-hook
            (lambda ()
              (when (string-equal "tsx" (file-name-extension buffer-file-name))
                (setup-tide-mode))))
  ;; enable typescript-tslint checker
  (flycheck-add-mode 'typescript-tslint 'web-mode)
  ;;javascript
  (setq tide-format-options '(:insertSpaceAfterFunctionKeywordForAnonymousFunctions t :placeOpenBraceOnNewLineForFunctions nil))
  ;; configure javascript-tide checker to run after your default javascript checker
  ;;(flycheck-add-next-checker 'javascript-eslint 'javascript-tide 'append)
  ;;jsx
  (require 'web-mode)
  (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
  (add-hook 'web-mode-hook
            (lambda ()
              (when (string-equal "jsx" (file-name-extension buffer-file-name))
                (setup-tide-mode))))
  ;; configure jsx-tide checker to run after your default jsx checker
  (flycheck-add-mode 'javascript-eslint 'web-mode)
  ;;(flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)

我用的spacemacs,上面的配置是按tide的readme写在~/.spacemacs.d/init.el的dotspacemacs/user-config里的。 只有打开的第一个js文件有效,关闭这个文件的buffer再打开或者打开其他文件都没有补全效果,message里面也没有报错。