dev-packages.el 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ;; Tree-sitter & LSP tweaks (Core transformative changes)
  2. (use-package treesit-fold
  3. :defer t
  4. :commands (treesit-fold-close
  5. treesit-fold-close-all
  6. treesit-fold-open
  7. treesit-fold-toggle
  8. treesit-fold-open-all
  9. treesit-fold-mode
  10. global-treesit-fold-mode
  11. treesit-fold-open-recursively
  12. treesit-fold-line-comment-mode)
  13. :custom
  14. (treesit-fold-line-count-show t)
  15. (treesit-fold-line-count-format "--▼--")
  16. :config
  17. (set-face-attribute 'treesit-fold-replacement-face nil
  18. :foreground "#808080"
  19. :box nil
  20. :weight 'bold)
  21. )
  22. ;; Tree-sitter hooks
  23. (dolist (hook '(c-ts-mode-hook c++-ts-mode-hook java-ts-mode-hook rust-ts-mode-hook go-ts-mode-hook ruby-ts-mode-hook js-ts-mode-hook typescript-ts-mode-hook tsx-ts-mode-hook css-ts-mode-hook html-ts-mode-hook bash-ts-mode-hook cmake-ts-mode-hook dockerfile-ts-mode-hook json-ts-mode-hook toml-ts-mode-hook yaml-ts-mode-hook))
  24. (add-hook hook #'treesit-fold-mode))
  25. (with-eval-after-load 'treesit
  26. (setq treesit-font-lock-level 4))
  27. (use-package mason
  28. :defer t
  29. :config
  30. (mason-setup))
  31. (use-package lsp-mode
  32. :defer t
  33. :commands (lsp lsp-deferred)
  34. :init
  35. (setq lsp-keymap-prefix "C-l")
  36. :hook
  37. ((c-mode-hook
  38. c++-mode-hook
  39. c-ts-mode-hook
  40. c++-ts-mode-hook
  41. arduino-mode-hook
  42. typescript-ts-mode-hook
  43. js-ts-mode-hook
  44. tsx-ts-mode-hook
  45. toml-ts-mode-hook
  46. json-ts-mode-hook
  47. python-ts-mode-hook) . lsp-deferred)
  48. :config
  49. ;; --- General LSP Settings ---
  50. (setq lsp-completion-provider :none
  51. lsp-completion-enable-filtering nil
  52. lsp-completion-sort-initial-results t
  53. lsp-enable-indentation t
  54. lsp-enable-on-type-formatting nil)
  55. (add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration)
  56. ;; --- C / C++ Configuration (clangd) ---
  57. (setq lsp-clients-clangd-executable "/usr/bin/clangd"
  58. lsp-clients--clangd-default-executable "/usr/bin/clangd"
  59. lsp-clients-clangd-args '("--header-insertion=iwyu"
  60. "--fallback-style=LLVM"
  61. "--query-driver=/usr/bin/c++,/usr/bin/g++,/home/*/.arduino15/packages/**/bin/*"
  62. "--header-insertion-decorators"))
  63. ;; Map major modes to LSP language IDs
  64. (add-to-list 'lsp-language-id-configuration '(c-ts-mode . "c"))
  65. (add-to-list 'lsp-language-id-configuration '(c++-ts-mode . "cpp"))
  66. (add-to-list 'lsp-language-id-configuration '(arduino-mode . "arduino"))
  67. ;; --- Arduino Language Server Registration ---
  68. (lsp-register-client
  69. (make-lsp-client
  70. :new-connection (lsp-stdio-connection
  71. (list "arduino-language-server"
  72. "-clangd" "/usr/bin/clangd"
  73. "-cli" "/usr/bin/arduino-cli"
  74. "-cli-config" (expand-file-name "~/.arduino15/arduino-cli.yaml")
  75. ))
  76. :activation-fn (lsp-activate-on "arduino")
  77. :major-modes '(arduino-mode)
  78. :server-id 'arduino-ls))
  79. ;; --- Keybindings ---
  80. (define-key lsp-command-map (kbd "a") #'lsp-execute-code-action)
  81. (define-key lsp-command-map (kbd "d") #'lsp-ui-doc-glance)
  82. (define-key lsp-command-map (kbd "r") #'lsp-rename)
  83. ;; Filter out unsupported inlineCompletion capability
  84. (advice-add 'lsp--client-capabilities :filter-return
  85. (lambda (caps)
  86. (cond
  87. ((hash-table-p caps)
  88. (when-let ((text-doc (gethash "textDocument" caps)))
  89. (if (hash-table-p text-doc)
  90. (remhash "inlineCompletion" text-doc)
  91. (setcdr (assoc "inlineCompletion" text-doc) nil))))
  92. ((listp caps)
  93. (when-let ((text-doc (cdr (assoc 'textDocument caps))))
  94. (setcdr (assoc 'textDocument caps)
  95. (assq-delete-all 'inlineCompletion text-doc)))))
  96. caps)))
  97. (use-package lsp-ui
  98. :defer t
  99. :after lsp-mode
  100. :commands lsp-ui-mode
  101. :init
  102. (setq lsp-ui-sideline-show-symbol t
  103. lsp-ui-side-show-code-actions t
  104. lsp-ui-sideline-show-hover t
  105. lsp-ui-doc-enable t
  106. lsp-ui-doc-delay 1
  107. lsp-ui-doc-position 'at-point
  108. lsp-ui-sideline-show-hover t
  109. lsp-ui-sideline-show-diagnostics t
  110. lsp-ui-side-show-code-actions t
  111. lsp-ui-sideline-delay 0.25
  112. )
  113. )
  114. (with-eval-after-load 'lsp-mode
  115. (add-to-list 'lsp-disabled-clients 'tailwindcss)
  116. )
  117. (provide 'dev-packages)