tide
tide copied to clipboard
EditorConfig Support
Specifically for the code formatting, integration with editorconfig-emacs would be amazing.
I would greatly appreciate this as well!
@ananthakumaran what would be needed for implementing this?
For each buffer tide will make a configure rpc request to tsserver. This contains formatOptions, which will be used by tsserver for other rpc requests like format etc. Tide already supports tsfmt.json file. https://github.com/ananthakumaran/tide/blob/master/tide.el#L712. Adding editor config support would be similar, the file needs to be parsed and each option needs to be mapped to the corresponding options in the protocol.
I might try to implement support for this the coming weeks, but I'm not very experienced in elisp or typescript.
Would it be sane to require https://github.com/editorconfig/editorconfig-emacs as a prerequisite? So that tide
won't have to deal with parsing and finding the editorconfig file
Yes, using a standard implementation is better.
PRs welcome.
I think we're 99% of the way there. tide respects typescript-indent-level
. Editorconfig will set this accordingly. I think what's happening is tide is usually set up before editorconfig hooks are ran. This means editorconfig does change the typescript settings, but tide is unaware they have been changed out from under itself. Here's a quick and dirty workaround that appears to do the trick -- ensures tide's server knows about the latest changes applied by editorconfig:
(add-hook 'editorconfig-after-apply-functions (defun winny/fix-tide-indentation (props)
(when (and (boundp 'tide-mode) tide-mode)
(tide-command:configure))))
This bug also manifests if user manually sets typescript-indent-level
. I think it's the same surprising behavior because in both cases this var is being overridden in a way tide is unaware of. But this is normal and expected emacs behavior - it's probably not a safe bet to assume a var never changes over the lifecycle of a buffer.
Maybe tide could monitor this var (and reconfigure itself) so it behaves in a unsurprising way in all cases?