Skip to content

Commit

Permalink
Fix indentation offset when using Eglot with LSP indentation.
Browse files Browse the repository at this point in the history
This fix correctly sets `tab-width`, which Eglot uses to specify the
indentation offset to the Language Server.  `tab-width` needs to be
set to `ada-ts-mode-indent-offset` before calling `eglot-format`.  It
was incorrectly using the default value of `tab-width` instead.
  • Loading branch information
brownts committed Sep 15, 2024
1 parent 1e7ea28 commit 99bfa64
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 1 addition & 4 deletions ada-ts-mode-lspclient-eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@

(cl-defmethod ada-ts-mode-lspclient-format-region ((_client (eql eglot)) beg end)
"Format region BEG to END of using Language Server."
(let ((tab-width ; eglot uses `tab-width' to specify indentation
(cond ((local-variable-p 'standard-indent) standard-indent)
(t tab-width))))
(eglot-format beg end)))
(eglot-format beg end))

(cl-defmethod ada-ts-mode-lspclient-workspace-configuration ((_client (eql eglot)) scope)
"Retrieve workspace configuration for SCOPE."
Expand Down
3 changes: 2 additions & 1 deletion ada-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

;; Author: Troy Brown <[email protected]>
;; Created: February 2023
;; Version: 0.7.0
;; Version: 0.7.1
;; Keywords: ada languages tree-sitter
;; URL: https://github.com/brownts/ada-ts-mode
;; Package-Requires: ((emacs "29.1"))
Expand Down Expand Up @@ -690,6 +690,7 @@ formatting function fails."
When CLIENT is not nil, use it as the active LSP client."
(if-let* ((client (or client (ada-ts-mode-lspclient-current))))
(let ((inhibit-message t)
(tab-width ada-ts-mode-indent-offset)
(standard-indent ada-ts-mode-indent-offset))
(ada-ts-mode-lspclient-format-region client beg end))
;; fallback on default indentation
Expand Down

0 comments on commit 99bfa64

Please sign in to comment.