2021年8月29日日曜日

Emacs の lsp の設定、なう。

Emacs に LSP を入れてみて、そう、4ヶ月ほどになるだろうか。 まあ、私の使い方なら、それなりかと思えるようになったので、 一区切りという意味で、晒してみる。

  • 環境は、Debian(bullseye)+emacs(27.1)。ivy + company。
  • lsp は、 python と shell で使用。将来の希望で、rustも入れている。
  • lsp は lsp-mode で、python のクライアントは、lsp-pylsp。 shell は bash-language-server。
  • lsp-pyls から lsp-pylsp になる時期だったらしく、戸惑った記憶あり。
  • flymake ではなく、flycheck。設定は lsp まかせ。 この flycheck が、なんか馴染めない。 きっと使い方が分ってないのだと思うが放置状態。
  • 補完は、lsp ではなく、company を直接使ってる、はず。 cpmpany-ispell がうまく動かせなかったのが理由。そのうち、再挑戦しよう。
  • フォールディングは、origami。
  • indent、整形は、auto で動くやつは使わない。 python では使わないものだ、とか、どこかで見た記憶。
  • lsp-ui-peak は、一応設定してあるというレベル。
;; lsp-mode

(leaf lsp-mode :ensure t
  :url "https://github.com/emacs-lsp/lsp-mode"
  :hook (
         (python-mode-hook . lsp-deferred)
         (rust-mode-hook . lsp-deferred) ;; rust-analyzer(次に学ぶとしたら、)
         (sh-mode-hook . lsp-deferred)   ;; yarn global add bash-language-server
         ;; (haskell-mode . lsp-deferred)      ;;
         ;; To defer LSP server startup (and DidOpen notifications) until the buffer is visible
         ;; you can use lsp-deferred instead of lsp:
         (lsp-mode-hook . lsp-enable-which-key-integration) ;; Adds to `which-key-mode'
         (lsp-mode-hook . (lambda () (ggtags-mode -1))) ;; デフォでは使わないようにする [2021-06-12]
         )
  :custom (
           (add-to-list 'lsp-disabled-clients 'pyls)
           ;; debug
           (lsp-log-io             . nil)  ;; print all messages to and from the language server to ~*lsp-log*~.
           (lsp-print-performance  . nil)
           (lsp-server-trace       . nil)  ;; Request trace mode on the language server.
           ;; general
           (lsp-auto-guess-root . t)  ;; original nil
           ;;   Automatically guess the project root using projectile/project.
           ;;   Do *not* use this setting unless you are familiar with ‘lsp-mode’
           ;;   internals and you are sure that all of your projects are
           ;;   following ‘projectile’/‘project.el’ conventions.
           (lsp-message-project-root-warning . t)

           (lsp-auto-configure . t)  ;;
           ;;   "Auto configure `lsp-mode' main features.
           ;; When set to t `lsp-mode' will auto-configure
           ;;   completion, code-actions, breadcrumb, flycheck, flymake, imenu, symbol highlighting,
           ;;   lenses, links, and so on.

           (lsp-headerline-breadcrumb-enable . t)
           ;; (lsp-headerline-breadcrumb-segments . '(project file symbols))
           ;;
           ;; (lsp-document-sync-method . nil)  ;; original nil  'incremental
           ;; (lsp-document-sync-method . 'lsp-sync-incremental)  ;; original nil  'inclemental は変更された
           ;;
           (lsp-eldoc-render-all . nil)
           ;; ミニバッファでの関数情報
           ;;   nil: シグニチャだけ,   t: doc-string 本体を表示する
           ;;
           (lsp-idle-delay . 0.5)
           (lsp-response-timeout     . 5)
           ;; (lsp-enable-snippet       . t)     ;; original t
           (lsp-enable-folding       . t)     ;; original t
           (lsp-enable-indentation   . t)
           ;;
           (lsp-completion-enable . nil)  ;; original t
           (lsp-completion-provider . :none)
           ;; (lsp-completion-provider . :capf)  ;;
           ;; (lsp-prefer-capf . t)  ;;  use ‘lsp-completion-provider’ instead.
           ;; (lsp-completion-no-cache . t)  ;;
           ;; (lsp-completion-enable-additional-text-edit  . t)
           (lsp-completion-show-detail . nil)
           ;; (lsp-completion-show-kind . nil)

           ;; (lsp-diagnostics-provider . :auto) ;; default :auto
           (lsp-diagnostics-provider . :flycheck)
           ;;
           ;; (lsp-inhibit-message . t)
           ;; (create-lockfiles . nil)
           (lsp-file-watch-threshold . nil)
           ;;
           (lsp-enable-symbol-highlighting . t)
           (lsp-signature-render-documentation . nil)
           )
  :commands (lsp lsp-deferred)
  ;; :commands (lsp)
  :config
  ;; .venv, .mypy_cache を watch 対象から外す
  ;;    https://qiita.com/slotport/items/0e9cb2a875fe85bc1735
  (dolist (dir '(
                 "[/\\\\]\\.venv$"
                 "[/\\\\]\\.mypy_cache$"
                 "[/\\\\]__pycache__$"
                 "[/\\\\]_archives$"
                 "[/\\\\]_logs$"
                 ))
    (push dir lsp-file-watch-ignored))

  ;;
  (leaf lsp-ui :ensure t
    :custom
    ;; lsp-ui-doc
    (lsp-ui-doc-enable . t)            ;; original t
    (lsp-ui-doc-header . nil)          ;; original nil
    ;; (lsp-ui-doc-use-childframe . t)
    (lsp-ui-doc-delay  . 1.5)
    (lsp-ui-doc-include-signature . t)   ;; original nil
    (lsp-ui-doc-position . 'top)         ;; top bottom at-point
    (lsp-ui-doc-alignment . 'frame)
    ;;   "How to align the doc.
    ;;    only takes effect when `lsp-ui-doc-position' is 'top or 'bottom."
    ;; (lsp-ui-doc-border . "orange")
    ;; (lsp-ui-doc-border (face-foreground 'default))
    (lsp-ui-doc-use-childframe . t)      ;; require 26
    ;;(lsp-ui-doc-max-width . 70)
    ;;(lsp-ui-doc-max-height . 20)
    (lsp-ui-doc-use-webkit . nil)
    (lsp-eldoc-enable-hover . nil)  ;; mini-buffer への表示

    ;; disable cursor hover (keep mouse hover)
    (lsp-ui-doc-show-with-cursor . nil)
    ;; disable mouse hover (keep cursor hover)
    (lsp-ui-doc-show-with-mouse . nil)

    ;; lsp-ui-flycheck  ;; autoload ?
    (lsp-ui-flycheck-enable . t)

    (lsp-lens-enable . t)

    ;; lsp-ui-sideline
    ;;    Show informations of the symbols on the current line.
    ;;    It also show flycheck diagnostics and LSP code actions
    ;;
    (lsp-ui-sideline-update-mode . 'line)  ;; line or point
    (lsp-ui-sideline-enable . t)
    (lsp-ui-sideline-show-symbol . t)
    (lsp-ui-sideline-show-code-actions . t)
    (lsp-ui-sideline-show-hover . nil)
    (lsp-ui-sideline-show-diagnostics . t)
    (lsp-ui-sideline-ignore-duplicate . t)
    (lsp-ui-sideline-code-actions-prefix . "")
    (lsp-ui-sideline-delay . 0.5)
    ;;
    ;; lsp-ui-imenu
    (lsp-ui-imenu-enable . t)
    (lsp-ui-imenu-kind-position . 'top)
    ;;     (setq lsp-ui-imenu-colors `(,(face-foreground 'font-lock-keyword-face)
    ;;                                 ,(face-foreground 'font-lock-string-face)
    ;;                                 ,(face-foreground 'font-lock-constant-face)
    ;;                                 ,(face-foreground 'font-lock-variable-name-face)))
    ;;
    ;; lsp-ui-peek
    ;;   like Visual studio peak function.
    (lsp-ui-peek-enable . t)
    (lsp-ui-peek-show-directory . t)
    (lsp-ui-peek-always-show . t)
    ;; (lsp-ui-peek-list-width . 60)
    ;; (lsp-ui-peek-peek-height . 20)
    (lsp-ui-peek-fontify . 'on-demand) ;; never, on-demand, or always
    )

  (leaf lsp-ivy :ensure t :require t
    :url "https://github.com/emacs-lsp/lsp-ivy"
    :doc "interface to the workspace symbol functionality"
    :after ivy
    :commands lsp-ivy-workspace-symbol
    )

  (leaf lsp-origami :ensure t :require t
    :url "https://github.com/emacs-lsp/lsp-origami"
    :hook lsp-after-open-hook
    ;; :after origami-minor-mode
    :commands lsp-origami-try-enable
    )
  ;;
  )

lsp は使えていると思うのだが、快適になったかというと、はて?というのが本音。 それに、lsp は反応が遅いという感触がある。

本筋ではないだろうけど、 ファイルサイズを小さく分けることで、少し改善できてるように思う。 これまで、700-800行は気にしなかったのだが、 最近は300-500になるように変更したりしている。

たまに freeze 状態になる問題があるので、 これに比べれば、些細なことかも。

最近の garbage collection に関する設定。

(setq gc-cons-threshold (* 256 1024 1024))
(setq read-process-output-max (* 8 1024 1024))

0 件のコメント:

コメントを投稿

Emacs の lsp の設定、なう(202310)

前回さらしてから、さらに1年。そう、3年めになる。 が、今回は一段と自信がない。 環境は、 Debian GNU/Linux 12 (bookworm) + emacs(29.1)。consult + company。 embark は未だに使ってない。 用途は、メモ と ...