Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aguynamedben opened this issue Jun 25, 2024 · 3 comments
Open

Comments

@aguynamedben
Copy link

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))
@zerolfx
Copy link
Collaborator

zerolfx commented Jul 3, 2024

Consider adding your custom indentation setting to the front of the copilot-indentation-alist.

@ezmiller
Copy link

Did you figure this out @aguynamedben?

@aguynamedben
Copy link
Author

@ezmiller No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants