LSP shouldn't be turned on by default

At least, not until i can tame this beast.
This commit is contained in:
Howard Abrams 2022-05-10 11:25:10 -07:00
parent 0b64f4ab26
commit 6aa3efdf54

View file

@ -46,7 +46,7 @@ While Emacs supplies a Python editing environment, well still use =use-packag
(setq python-indent-guess-indent-offset-verbose nil) (setq python-indent-guess-indent-offset-verbose nil)
:config :config
(when (and (executable-find "python3") (when (and (executable-find "python3")
(string= python-shell-interpreter "python")) (string= python-shell-interpreter "python"))
(setq python-shell-interpreter "python3")) (setq python-shell-interpreter "python3"))
;; While `setup.py' and `requirements.txt' are already added, I often ;; While `setup.py' and `requirements.txt' are already added, I often
@ -162,106 +162,102 @@ The [[https://github.com/emacs-lsp/lsp-pyright][pyright package]] works with LSP
(setq lsp-pyright-python-executable-cmd "python3"))) (setq lsp-pyright-python-executable-cmd "python3")))
#+END_SRC #+END_SRC
* LSP Integration of Python * LSP Integration of Python
Now that the [[file:ha-programming.org::*Language Server Protocol (LSP) Integration][LSP Integration]] is complete, we can stitch the two projects together: Now that the [[file:ha-programming.org::*Language Server Protocol (LSP) Integration][LSP Integration]] is complete, we can stitch the two projects together, by calling =lsp=. I oscillate between automatically turning on LSP mode with every Python file, but I sometimes run into issues when starting, so I turn it on with ~SPC m w s~.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package lsp-mode (use-package lsp-mode
:hook ((python-mode . lsp))) ;; :hook ((python-mode . lsp)))
#+END_SRC :config
(ha-python-leader
"0" '("treemacs" . lsp-treemacs-symbols)
And we're done. Except that I would like a select collection of LSP keybindings for Python. "/" '("complete" . completion-at-point)
"k" '("check code" . python-check)
"]" '("shift left" . python-indent-shift-left)
"[" '("shift right" . python-indent-shift-right)
#+BEGIN_SRC emacs-lisp ;; actions
(ha-python-leader "a" '(:ignore t :which-key "code actions")
"0" '("treemacs" . lsp-treemacs-symbols) "aa" '("code actions" . lsp-execute-code-action)
"ah" '("highlight symbol" . lsp-document-highlight)
"al" '("lens" . lsp-avy-lens)
"/" '("complete" . completion-at-point) ;; formatting
"k" '("check code" . python-check) "=" '(:ignore t :which-key "formatting")
"]" '("shift left" . python-indent-shift-left) "==" '("format buffer" . lsp-format-buffer)
"[" '("shift right" . python-indent-shift-right) "=r" '("format region" . lsp-format-region)
;; actions "e" '(:ignore t :which-key "eval")
"a" '(:ignore t :which-key "code actions") "e P" '("run python" . run-python)
"aa" '("code actions" . lsp-execute-code-action) "e e" '("send statement" . python-shell-send-statement)
"ah" '("highlight symbol" . lsp-document-highlight) "e b" '("send buffer" . python-shell-send-buffer)
"al" '("lens" . lsp-avy-lens) "e f" '("send defun" . python-shell-send-defun)
"e F" '("send file" . python-shell-send-file)
"e r" '("send region" . python-shell-send-region)
"e ;" '("expression" . python-shell-send-string)
"e p" '("switch-to-shell" . python-shell-switch-to-shell)
;; formatting ;; folders
"=" '(:ignore t :which-key "formatting") "F" '(:ignore t :which-key "folders")
"==" '("format buffer" . lsp-format-buffer) "Fa" '("add folder" . lsp-workspace-folders-add)
"=r" '("format region" . lsp-format-region) "Fb" '("un-blacklist folder" . lsp-workspace-blacklist-remove)
"Fr" '("remove folder" . lsp-workspace-folders-remove)
"e" '(:ignore t :which-key "eval") ;; goto
"e P" '("run python" . run-python) "g" '(:ignore t :which-key "goto")
"e e" '("send statement" . python-shell-send-statement) "ga" '("find symbol in workspace" . xref-find-apropos)
"e b" '("send buffer" . python-shell-send-buffer) "gd" '("find declarations" . lsp-find-declaration)
"e f" '("send defun" . python-shell-send-defun) "ge" '("show errors" . lsp-treemacs-errors-list)
"e F" '("send file" . python-shell-send-file) "gg" '("find definitions" . lsp-find-definition)
"e r" '("send region" . python-shell-send-region) "gh" '("call hierarchy" . lsp-treemacs-call-hierarchy)
"e ;" '("expression" . python-shell-send-string) "gi" '("find implementations" . lsp-find-implementation)
"e p" '("switch-to-shell" . python-shell-switch-to-shell) "gm" '("imenu" . lsp-ui-imenu)
"gr" '("find references" . lsp-find-references)
"gt" '("find type definition" . lsp-find-type-definition)
;; folders ;; peeks
"F" '(:ignore t :which-key "folders") "G" '(:ignore t :which-key "peek")
"Fa" '("add folder" . lsp-workspace-folders-add) "Gg" '("peek definitions" . lsp-ui-peek-find-definitions)
"Fb" '("un-blacklist folder" . lsp-workspace-blacklist-remove) "Gi" '("peek implementations" . lsp-ui-peek-find-implementation)
"Fr" '("remove folder" . lsp-workspace-folders-remove) "Gr" '("peek references" . lsp-ui-peek-find-references)
"Gs" '("peek workspace symbol" . lsp-ui-peek-find-workspace-symbol)
;; goto ;; help
"g" '(:ignore t :which-key "goto") "h" '(:ignore t :which-key "help")
"ga" '("find symbol in workspace" . xref-find-apropos) "he" '("eldoc" . python-eldoc-at-point)
"gd" '("find declarations" . lsp-find-declaration) "hg" '("glance symbol" . lsp-ui-doc-glance)
"ge" '("show errors" . lsp-treemacs-errors-list) "hh" '("describe symbol at point" . lsp-describe-thing-at-point)
"gg" '("find definitions" . lsp-find-definition) "gH" '("describe python symbol" . python-describe-at-point)
"gh" '("call hierarchy" . lsp-treemacs-call-hierarchy) "hs" '("signature help" . lsp-signature-activate)
"gi" '("find implementations" . lsp-find-implementation)
"gm" '("imenu" . lsp-ui-imenu)
"gr" '("find references" . lsp-find-references)
"gt" '("find type definition" . lsp-find-type-definition)
;; peeks "i" 'imenu
"G" '(:ignore t :which-key "peek")
"Gg" '("peek definitions" . lsp-ui-peek-find-definitions)
"Gi" '("peek implementations" . lsp-ui-peek-find-implementation)
"Gr" '("peek references" . lsp-ui-peek-find-references)
"Gs" '("peek workspace symbol" . lsp-ui-peek-find-workspace-symbol)
;; help ;; refactoring
"h" '(:ignore t :which-key "help") "r" '(:ignore t :which-key "refactor")
"he" '("eldoc" . python-eldoc-at-point) "ro" '("organize imports" . lsp-organize-imports)
"hg" '("glance symbol" . lsp-ui-doc-glance) "rr" '("rename" . lsp-rename)
"hh" '("describe symbol at point" . lsp-describe-thing-at-point)
"gH" '("describe python symbol" . python-describe-at-point)
"hs" '("signature help" . lsp-signature-activate)
"i" 'imenu ;; toggles
"t" '(:ignore t :which-key "toggle")
"tD" '("toggle modeline diagnostics" . lsp-modeline-diagnostics-mode)
"tL" '("toggle log io" . lsp-toggle-trace-io)
"tS" '("toggle sideline" . lsp-ui-sideline-mode)
"tT" '("toggle treemacs integration" . lsp-treemacs-sync-mode)
"ta" '("toggle modeline code actions" . lsp-modeline-code-actions-mode)
"tb" '("toggle breadcrumb" . lsp-headerline-breadcrumb-mode)
"td" '("toggle documentation popup" . lsp-ui-doc-mode)
"tf" '("toggle on type formatting" . lsp-toggle-on-type-formatting)
"th" '("toggle highlighting" . lsp-toggle-symbol-highlight)
"tl" '("toggle lenses" . lsp-lens-mode)
"ts" '("toggle signature" . lsp-toggle-signature-auto-activate)
;; refactoring ;; workspaces
"r" '(:ignore t :which-key "refactor") "w" '(:ignore t :which-key "workspaces")
"ro" '("organize imports" . lsp-organize-imports) "wD" '("disconnect" . lsp-disconnect)
"rr" '("rename" . lsp-rename) "wd" '("describe session" . lsp-describe-session)
"wq" '("shutdown server" . lsp-workspace-shutdown)
;; toggles "wr" '("restart server" . lsp-workspace-restart)
"t" '(:ignore t :which-key "toggle") "ws" '("start server" . lsp)))
"tD" '("toggle modeline diagnostics" . lsp-modeline-diagnostics-mode)
"tL" '("toggle log io" . lsp-toggle-trace-io)
"tS" '("toggle sideline" . lsp-ui-sideline-mode)
"tT" '("toggle treemacs integration" . lsp-treemacs-sync-mode)
"ta" '("toggle modeline code actions" . lsp-modeline-code-actions-mode)
"tb" '("toggle breadcrumb" . lsp-headerline-breadcrumb-mode)
"td" '("toggle documentation popup" . lsp-ui-doc-mode)
"tf" '("toggle on type formatting" . lsp-toggle-on-type-formatting)
"th" '("toggle highlighting" . lsp-toggle-symbol-highlight)
"tl" '("toggle lenses" . lsp-lens-mode)
"ts" '("toggle signature" . lsp-toggle-signature-auto-activate)
;; workspaces
"w" '(:ignore t :which-key "workspaces")
"wD" '("disconnect" . lsp-disconnect)
"wd" '("describe session" . lsp-describe-session)
"wq" '("shutdown server" . lsp-workspace-shutdown)
"wr" '("restart server" . lsp-workspace-restart)
"ws" '("start server" . lsp))
#+END_SRC #+END_SRC
* Project Configuration * Project Configuration
I work with a lot of projects with my team where I need to /configure/ the project such that LSP and my Emacs setup works. Let's suppose I could point a function at a project directory, and have it /set it up/: I work with a lot of projects with my team where I need to /configure/ the project such that LSP and my Emacs setup works. Let's suppose I could point a function at a project directory, and have it /set it up/: