reddit / emacs

Eglot Typescript Server Configuration

kentrose · 2022-12-15 16:19
When I edit typescript files with eglot active, it resets *indent-tabs-mode* and inserts tabs. I can toggle *indent-tabs-mode* to go back to spaces, but I'd like to leave it set the way I like. I'm trying to follow the instructions for *eglot-workspace-configuration* in the eglot manual, but it's not working. I've tried creating a **.dir.local.el** file to set preferences for "typescript-language-server" (see below), but *eglot-show-workspace-configuration* shows nil, so I don't think these are being found. The *kap/eglot-current-server* command I've written (see below) confirms that I'm running "(typescript-language-server --stdio)". (use-package eglot :hook ((js-ts-mode . eglot-ensure) (tsx-ts-mode . eglot-ensure) (typescript-ts-mode . eglot-ensure)) :custom (eglot-stay-out-of indent-tabs-mode) ;; (This didn't work) :bind (:map eglot-mode-map)) (defun kap/eglot-current-server () (interactive) (message "%s" (process-command (jsonrpc--process (eglot-current-server))))) And **.dir.local.el** looks like this: ((nil . ((eglot-workspace-configuration . (:typescript-language-server (:typescript.format.convertTabsToSpaces nil) (:javascript.format.convertTabsToSpaces nil)))))) The root problem is the insistence of eglot and/or the lsp server on tabs rather than spaces. But the bigger issue I'd like is how to get configuration into the lsp server. Has anyone got **.dir.local.el** configuration to work for the "typescript-language-server"?
orzechod · 2022-12-15 19:22
[`eglot-stay-out-of` is not a `defcustom`, it's a `defvar`](https://github.com/joaotavora/eglot/blob/master/eglot.el#L1640); I'm not sure that `:custom` will apply to it. what happens if you use `:config` instead? > But the bigger issue I'd like is how to get configuration into the lsp server. Has anyone got .dir.local.el configuration to work for the "typescript-language-server"? I believe the file name is `.dir-locals.el`. does that file name work for you?
kentrose · 2022-12-16 05:26
You're right! I had the filename wrong for `.dir-locals.el`. Fixed that and it is finding it now. However, I had to fiddle with the syntax (monitoring errors in the `*messages*` buffer) to get a version that would compile, and this still didn't seem to have any effect. I'd love to see an example showing how to get preferences working for `typescript-language-server`. On the tabbing issue, the fix seems to be to add a hook which is evaluated after the mode is finished initializing (see below). I didn't mention that I'm running Emacs 29, and have switched from `lsp-mode` to `eglot`, and from `tree-sitter` to `tsitter`. I'm pretty sure that `indent-tab-mode` could be disabled in the `:config` section before, but the following works for now: (use-package typescript-mode :defer :mode (("\\.ts\\'" . tsx-ts-mode) ("\\.tsx\\'" . tsx-ts-mode)) :interpreter "ts-node" :custom (js-indent-level 2) (js-jsx-indent-level 2) (evil-shift-width 2) (truncate-lines t) (add-node-modules-path) :hook (tsx-ts-mode . (lambda () (indent-tabs-mode -1))))