spacemacs/layers/+tools/tide
thanhvg e3b6464649
[core][tide][lsp] improve spacemacs/set-leader-keys-for-minor-mode and apply it to tide and lsp layers (#14141)
* [core][keybinng] improve minor mode binding

This commit added add a new function defun spacemacs/declare-prefix-for-minor-mode
and improved spacemacs/set-leader-keys-for-minor-mode.

`which-key` package recently introduced a new api
which-key-add-keymap-based-replacements which improves perfomance and allows
prefix and namings to be stored directly in keymap. This is a great improvement.

With this new api we now make change to spacemacs/declare-prefix-for-minor-mode
to manage prefix also. For example:

  (spacemacs/set-leader-keys-for-minor-mode 'lsp-mode
    "=" "format"
    "=b" #'lsp-format-buffer)

Before we had to use another api to bind prefix
spacemacs/declare-prefix-for-mode which only works on major-mode. As lsp-mode is
a minor mode this api causes a lot of problems to which-key performance. An
example is https://github.com/syl20bnr/spacemacs/issues/12455 which led to my
hack in https://github.com/syl20bnr/spacemacs/pull/12474.

The improved spacemacs/set-leader-keys-for-minor-mode will take care of both
prefix and key naming for the minor mode. This will allows us to have a better
set up for dynamic minor modes such as lsp-mode, tide-mode etc.

Also another api is created to make prefix for minor mode:
spacemacs/declare-prefix-for-minor-mode.

Usage:
(spacemacs/declare-prefix-for-minor-mode 'tide-mode "E" "errors")"

* [tide] improve prefix

* [lsp] improve prefix
2020-11-21 07:34:55 +01:00
..
config.el [core][tide][lsp] improve spacemacs/set-leader-keys-for-minor-mode and apply it to tide and lsp layers (#14141) 2020-11-21 07:34:55 +01:00
funcs.el [core][tide][lsp] improve spacemacs/set-leader-keys-for-minor-mode and apply it to tide and lsp layers (#14141) 2020-11-21 07:34:55 +01:00
packages.el [core][tide][lsp] improve spacemacs/set-leader-keys-for-minor-mode and apply it to tide and lsp layers (#14141) 2020-11-21 07:34:55 +01:00
README.org documentation formatting: Fri Mar 13 07:13:20 UTC 2020 2020-03-13 08:19:39 +01:00

Tide Layer

Description

This layer installs tide package which allows communication with standalone typescript server tsserver for JavaScript/TypeScript development.

Features:

  • First class support from tsserver just like vscode: speed and accuracy
  • Linter
  • Refactor
  • Go to definition
  • Find references

Install

See tide for details. First you must have `tsserver` installed in your project or globally:

  npm install -g typescript

Next enable this layer in your ~/.spacemacs. You will need to add tide to the existing dotspacemacs-configuration-layers list in this file. Then set the backend variables for JavaScript layer, React layer and TypeScript layer to tide in dotspacemacs-configuration-layers

  (javascript :variables
               javascript-backend 'tide)

  (typescript :variables
              typescript-backend 'tide)

Both javascript-backend and typescript-backend can be set per project.

When using this layer, make sure tsconfig.json or jsconfig.json is present in the root folder of the project.

Example from emacs tide package: For JavaScript projects you may want to create jsconfig.json in the root folder of your project. jsconfig.json is tsconfig.json with allowjs attribute set to true.

  {
    "compilerOptions": {
      "target": "es2017",
      "allowSyntheticDefaultImports": true,
      "noEmit": true,
      "checkJs": true,
      "jsx": "react",
      "lib": [ "dom", "es2017" ]
    }
  }

Without this file tsserver will pick up current folder as project root.

Key bindings

Major Mode

Key binding Description
SPC m E d add tslint:disable-next-line at point
SPC m E e fix thing at point
SPC m g b jump back
SPC m g g jump to entity's definition
SPC m g t jump to entity's type definition
SPC m g r references
SPC m h h documentation at point
SPC m r i organize imports
SPC m r r rename symbol
SPC m r f rename file
SPC m S r restart server
SPC m S j create a barebone jsconfig.json at project root

Reference Major Mode

Key binding Description
C-j find previous reference
C-k find next reference
C-l goto reference