Skip to content

Instantly share code, notes, and snippets.

@matfournier
Created January 14, 2020 18:44
Show Gist options
  • Save matfournier/997107bfa8ee37d093e7c2ff1a9f0279 to your computer and use it in GitHub Desktop.
Save matfournier/997107bfa8ee37d093e7c2ff1a9f0279 to your computer and use it in GitHub Desktop.
emacs scala lsp
(map! :map scala-mode-map
"C-c C-t" #'lsp-ui-doc-show ;; shows type under cursor as a hover
"C-c t" #'lsp-describe-thing-at-point ;; shows type under cursor in temp buffer below
"C-c H" #'lsp-ui-doc-mode ;; toggle auto-showing type under cursor asa hover
"C-c F" #'lsp-format-buffer ;; run scalafmt on the entire buffer
"C-c f" #'lsp-format-region ;; run scalafmt on the selected region
"C-c C-f" #'lsp-find-references ;; find references symbol under cursor
"C-c i" #'lsp-execute-code-action ;; import missing type/class
"C-c r" #'lsp-rename ;; rename symbol
"C-c e" #'lsp-ui-flycheck-list ;; list all errors
"C-c g" #'lsp-goto-implementation ;; list all implementations for trait
)
@noelwelsh
Copy link

FWIW here's my Doom Scala mode keymap, updated with the above bindings:

    (map! :map scala-mode-map
          :localleader
          :desc "Compile" :n "c" (λ! (sbt-command "compile"))
          :desc "Reload" :n "d" (λ! (sbt-command "reload"))
          :desc "Hydra" :n "h" (λ! (sbt-hydra))
          :desc "Console" :n "o" #'run-scala
          :desc ":paste region" :n "p" #'sbt-paste-region
          :desc "Run" :n "r" (λ! (sbt-command "run"))
          :desc "sbt command" :n "s" #'sbt-command
          :desc "Clear" :n "x" #'sbt-clear
          (:prefix ("m". "metals")
            :desc "List errors" :n "e" #'lsp-ui-flycheck-list
            :desc "Fix missing import" :n "i" #'lsp-execute-code-action
            :desc "Describe thing at point" :n "t" #'lsp-describe-thing-at-point
            :desc "Toggle type hints" :n "H" #'lsp-ui-doc-mode
            :desc "Format buffer" :n "F" #'lsp-format-buffer
            :desc "Format region" :n "f" #'lsp-format-region
            :desc "Find references" :n "C-f" #'lsp-find-references
            :desc "Rename" :n "r" #'lsp-rename
            :desc "Goto implementation" :n "g" #'lsp-goto-implementation))

@matfournier
Copy link
Author

Oh I didn't know you can put in descriptions! thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment