Hi all,
Has anyone found a way to get treesitter + eglot + corfu to work well with nim. I never fully managed to get it to work properly, and nimsuggest is super slow:
The relevant bits:
(defun nimble-build-if-project ()
"Check if the current project is a Nimble project and run 'nimble build' from the project root."
(interactive)
(let ((project-root (locate-dominating-file
default-directory
(lambda (dir)
(directory-files dir nil "\\.nimble\\'")))))
(if project-root
(progn
(message "Project root found: %s" project-root)
(let ((default-directory project-root))
(message "Running 'nimble build' in directory: %s" default-directory)
(compile "nimble build")))
(message "Not a Nimble project: No '*.nimble' file found in the project root."))))
(with-eval-after-load 'nim-mode
(define-key nim-mode-map (kbd "C-c C-c") 'nimble-build-if-project))
;; --- Tree-sitter for Nim ---------------------------------------------
;; Install the Nim grammar first:
;; M-x treesit-install-language-grammar RET nim RET
;; Then use community nim-ts-mode:
(use-package nim-ts-mode
:vc (:url "https://github.com/niontrix/nim-ts-mode" :rev :newest)
:mode ("\\.nim\\'" . nim-ts-mode)
:init
(add-to-list 'treesit-language-source-alist
'(nim "https://github.com/alaviss/tree-sitter-nim")))
(defun nimble-build-if-project ()
"Check if the current project is a Nimble project and run 'nimble build' from the project root."
(interactive)
(let ((project-root (locate-dominating-file
default-directory
(lambda (dir)
(directory-files dir nil "\\.nimble\\'")))))
(if project-root
(progn
(message "Project root found: %s" project-root)
(let ((default-directory project-root))
(message "Running 'nimble build' in directory: %s" default-directory)
(compile "nimble build")))
(message "Not a Nimble project: No '*.nimble' file found in the project root."))))
(with-eval-after-load 'nim-mode
(define-key nim-mode-map (kbd "C-c C-c") 'nimble-build-if-project))
(use-package eglot
;; no :ensure t here because it's built-in
:defer t
;; Configure hooks to automatically turn-on eglot for selected modes
:custom
(eglot-send-changes-idle-time 0.4)
(eglot-report-progress nil) ; suppress nimlangserver progress spam
(jsonrpc-inhibit-debug-logs t)
(eglot-extend-to-xref t) ; activate Eglot in referenced non-project files
:hook
((ess-r-mode-inferior . eglot-ensure)
(nim-ts-mode . eglot-ensure))
:config
(fset #'jsonrpc--log-event #'ignore) ; massive perf boost---don't log every event
(setq eldoc-echo-area-use-multiline-p nil) ; Disable multiline echo area messages
;; Sometimes you need to tell Eglot where to find the language server
(add-to-list 'eglot-server-programs
'(nim-ts-mode . ("/home/luis/.nimble/bin/nimlangserver" "--autobind")))
;; Point nimlangserver at the correct nimsuggest (matches active nim 2.3.1 compiler)
;; Without this, it falls back to /usr/bin/nimsuggest (2.2.0) → 0 completions
(setq-default eglot-workspace-configuration
'((:nim . (:nimsuggestPath "/home/luis/.nimble/bin/nimsuggest"))))
)