我一直用 lsp-mode 写代码,最近想改 rust-analyzer 服务端的配置,一直没找到最方便的办法。
比如我想改 rust-analyzer.workspace.symbol.search.limit 的值为 1024,rust-analyzer.workspace.symbol.search.kind 的值为 all_symbols
这样我就能用 lsp-ui-find-workspace-symbols 搜索到更多的 symbols ,而不是 rust-analyzer 默认的 128 个。
我试了试,可以这样做:
  (defun merge-plists (origin patch)
	"Recursively merge PATCH plist onto ORIGIN plist."
	(if (null patch)
		origin
      (let ((key (car patch))
			(value (cadr patch)))
		(setq origin
              (plist-put origin key
						 (if (and (listp value) (plist-member origin key) (listp (plist-get origin key)))
							 (merge-plists (plist-get origin key) value)
                           value)))
		(merge-plists origin (cddr patch)))))
  (setq exec/lsp-rust-analyzer-patch-options
		'(:workspace
		  (:symbol
		   (:search
			(:limit 1024 :kind "all_symbols")))))
  (defun exec/lsp-rust-analyzer-add-extra-key (orig-fun &rest args)
	"Add :extraKey to the init options for rust-analyzer."
	(let ((init-options (apply orig-fun args))
		  (patch-options exec/lsp-rust-analyzer-patch-options))
	  (merge-plists init-options patch-options)))
  (advice-add 'lsp-rust-analyzer--make-init-options :around #'exec/lsp-rust-analyzer-add-extra-key)
效果:
