Fork me on GitHub
#emacs
<
2023-08-31
>
lilactown18:08:03

has anyone gotten eglot to work with typescript JSX? For some reason, if the first file I have open when I start the LSP server is a JSX file, it will show a bunch of errors about the JSX syntax (trying to interpret them as type annotations). Other JSX files work just fine

lilactown18:08:46

here's my relevant config:

(use-package typescript-mode
  :after tree-sitter
  :config
  ;; we choose this instead of tsx-mode so that eglot can automatically figure out language for server
  ;; see  and 
  (define-derived-mode typescriptreact-mode typescript-mode
    "TypeScript TSX")

  ;; use our derived mode for tsx files
  (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescriptreact-mode))
  ;; by default, typescript-mode is mapped to the treesitter typescript parser
  ;; use our derived mode to map both .tsx AND .ts -> typescriptreact-mode -> treesitter tsx
  (add-to-list 'tree-sitter-major-mode-language-alist '(typescriptreact-mode . tsx)))

(use-package eglot
  :config
   (put 'typescriptreact-mode 'eglot-language-id "typescriptreact"))

Derek00:09:04

My setup differs but I don’t see anything like this. I’m using the new emacs 29.1 treesitter modes

Derek00:09:36

relevant config:

(use-package eglot
  :custom
  (eglot-autoshutdown t)
  (eglot-confirm-server-initiated-edits nil)
  (eglot-ignored-server-capabilities '(:inlayHintProvider))
  :custom-face (eglot-highlight-symbol-face ((t :inherit normal)))
  :hook
  ((python-base-mode-hook
    typescript-ts-base-mode-hook) . eglot-ensure))

(use-package tsx-ts-mode
  :mode ("\\.tsx\\'"))

(use-package typescript-ts-mode
  :mode ("\\.ts\\'"))