Closed NANASHI0X74 closed 4 years ago
I think the right thing to do would be to overwrite the standard lsp binding in the layer with a more specific one for the language. PR would be welcome.
so. I just had a look at the package.el and it seems that the typescript layer already binds its own keybinding: https://github.com/syl20bnr/spacemacs/blob/dad4406f70e8d84f6e0eb8dcc1398ddcb05bbaee/layers/%2Blang/typescript/packages.el#L125-L127 It works with tide backend, but when using lsp I assume it gets overwritten by the lsp layer later? Can I somehow ensure that the typescript layer binds its keys after lsp or prevent the lsp layer from binding its keys?
ok, after reading the documentation on spacemacs layers and keybinding functions, I first naively tried to fix it by binding "=" to typescript-format with the following patch:
++ b/layers/+lang/typescript/packages.el
@@ -22,6 +22,7 @@
web-mode
tide
yasnippet
+ lsp-mode
))
@@ -136,3 +138,9 @@
(when (eq (spacemacs//typescript-backend) 'tide)
(add-to-list 'tide-managed-modes 'typescript-mode)
(add-to-list 'tide-managed-modes 'typescript-tsx-mode)))
+
+(defun typescript/post-init-lsp-mode ()
+ (spacemacs/set-leader-keys-for-major-mode 'typescript-mode
+ "=" 'spacemacs/typescript-format
+ "p" 'spacemacs/typescript-open-region-in-playground))
But upon reloading emacs and opening a typescript file, I couldn't observe any different behavior...
what does instead work though is to bind it to "==" conditionally, if using lsp backend and to "=" otherwise . I'll submit a PR with this fix, but maybe it would be better to bind it to "=" to be consistent with the other backend? If the latter would be preferred, feel free to reject the PR.
Also, could someone educate me on why my first patch wouldn't work? I'm still quite new to emacs/elisp and spacemacs (and haven't done much FP up to now, so having trouble understanding the syntax of the language as well sometimes) and a lot of things about how they work under the hood are still quite opaque to me.
The first PR was against the master
branch.
The destination and source are described under the title.
The first PR says: Bind typescript-format to "==" or "=" depending on backend #14048 NANASHI0X74 wants to merge 4,148 commits into syl20bnr:master from NANASHI0X74:patch-ts-format-kbd
The second one PR says: Bind typescript-format to "==" or "=" depending on backend #14049 smile13241324 merged 3 commits into syl20bnr:develop from NANASHI0X74:patch-ts-format-kbd 8 days ago
The contributing pull request instructions say: https://github.com/syl20bnr/spacemacs/blob/develop/CONTRIBUTING.org#pull-request
Submit your contribution against the develop branch. You should not use your master branch to modify Spacemacs, this branch is considered to be read-only.
Description :octocat:
typescript-mode with lsp backend and prettier typescript-fmt-tool doesn't use prettier to format typescript files. It should be noted that the javascript layer handles this fine (actually what it does is expose keybindings to use either the lsp formatter or prettier).
Reproduction guide :beetle:
SPC-m-=-b
Observed behaviour: :eyes: :broken_heart: lsp-format-buffer is run which doesn't respect .prettierrc and produces conflicts. It does respect .editorconfig though.
Expected behaviour: :heart: :smile: format buffer command runs prettier-js instead of lsp-format-buffer or alternately the layer configures the lsp to respect my .prettierrc ^^
System Info :computer:
Additional info:
this is my .eslintrc.js:
this is my .prettierrc.js:
and this is my .editorconfig: