copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.71k stars 122 forks source link

Copilot in typescript-ts-mode ignores copilot-indentation-alist #320

Open aguynamedben opened 1 week ago

aguynamedben commented 1 week ago

I use typescript-ts-mode for TypeScript (the tree-sitter version, built in to Emacs) and I can't get copilot-indentation-alist working correctly.

Here's what I see:

image

On the left, you can see indentation is not 2 spaces, even though on the right typescript-ts-mode-indent-offset is 2.

I noticed copilot-indentation-alist has these entries by default:

 (typescript-mode typescript-indent-level)
 (typescript-ts-base-mode typescript-ts-mode-indent-offset)

So I tried a few things in my config:

(add-to-list 'copilot-indentation-alist '(typescript-ts-mode typescript-ts-mode-indent-offset))
(add-to-list 'copilot-indentation-alist '(typescript-ts-mode typescript-ts-mode-indent-offset))
(add-to-list 'copilot-indentation-alist '(typescript-ts-mode 2))

but none of those worked. I still go too much indentation.

js-ts-mode seems to respect indentation correctly. Is there some kind of hook or variable that might not be right to support typescript-ts-mode? I noticed

Is there some kind of hook I'd need to use? The current stock alist tries setting typescript-ts-base-mode, but it seems to not be working.

🙏 Thank you for providing this package to the community. It's really helping me avoid VS Code :D

Relevant Config

;;;;;;;;;;;;;
;; Copilot ;;
;;;;;;;;;;;;;

(use-package copilot
  :straight (:host github :repo "copilot-emacs/copilot.el" :files ("*.el"))
  :hook
  (typescript-ts-mode . copilot-mode)
  :bind
  (:map copilot-completion-map
        ("M-<return>" . 'copilot-accept-completion)
        ("M-]" . 'copilot-next-completion)
    ("M-[" . 'copilot-previous-completion))
  :config
  (add-to-list 'copilot-indentation-alist '(typescript-ts-mode typescript-ts-mode-indent-offset)))

;;;;;;;;;;;;;;;;;
;; tree-sitter ;;
;;;;;;;;;;;;;;;;;

(use-package tree-sitter
  :custom
  ;; Take syntax highlighting to the "angry fruit salad" level
  ;; Cmd-F here: https://www.masteringemacs.org/article/how-to-get-started-tree-sitter
  (treesit-font-lock-level 4)
  :config
  (global-tree-sitter-mode)
  (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))

;;;;;;;;;;;;;;;;;;;;
;; Language modes ;;
;;;;;;;;;;;;;;;;;;;;

(use-package typescript-ts-mode
  :ensure nil ; built-in
  :mode
  ;; Use the tree-sitter special modes
  ("\\.ts\\'" . typescript-ts-mode)
  ("\\.tsx\\'" . tsx-ts-mode)
  :hook
  (typescript-ts-mode . add-node-modules-path)
  (typescript-ts-mode . prettier-js-mode)
  (tsx-ts-mode . add-node-modules-path)
  (tsx-ts-mode . prettier-js-mode))