Skip to content

Commit

Permalink
add support for typespec-ts-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyuman committed Jan 27, 2025
1 parent 137cdd1 commit ff1e943
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions clients/lsp-typespec.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@

(lsp-dependency
'typespec-lsp
'(:npm :package "@typespec/compiler"
:path "tsp-server")
'(:npm
:package "@typespec/compiler"
:path "tsp-server")
'(:system "tsp-server"))

(defun lsp-typespec--server-executable-path ()
"Return the typespec-lsp server command."
(or
(when-let* ((workspace-folder (lsp-find-session-folder (lsp-session) default-directory)))
(let ((tsp-server-local-path (f-join workspace-folder "node_modules" ".bin"
(if (eq system-type 'windows-nt) "tsp-server.cmd" "tsp-server"))))
(if (eq system-type 'windows-nt) "tsp-server.cmd" "tsp-server"))))
(when (f-exists? tsp-server-local-path)
tsp-server-local-path)))
(executable-find "tsp-server")
Expand All @@ -63,15 +64,15 @@
("event" . default)))
:new-connection (lsp-stdio-connection `(,(lsp-typespec--server-executable-path) "--stdio"))
:activation-fn (lsp-activate-on "typespec")
:major-modes '(typespec-mode)
:major-modes '(typespec-mode typespec-ts-mode)
:server-id 'typespec-lsp))

(lsp-consistency-check lsp-typespec)

(defun lsp-typespec-semantic-tokens-refresh (&rest _)
"Force refresh semantic tokens."
(when-let* ((workspace (and lsp-semantic-tokens-enable
(lsp-find-workspace 'typespec-lsp (buffer-file-name)))))
(lsp-find-workspace 'typespec-lsp (buffer-file-name)))))
(--each (lsp--workspace-buffers workspace)
(when (lsp-buffer-live-p it)
(lsp-with-current-buffer it
Expand All @@ -80,7 +81,8 @@
(with-eval-after-load 'typespec
(when lsp-semantic-tokens-enable
;; refresh tokens
(add-hook 'typespec-mode-hook #'lsp-typespec-semantic-tokens-refresh)))
(dolist (hook '(typespec-mode-hook typespec-ts-mode-hook))
(add-hook hook #'lsp-typespec-semantic-tokens-refresh))))

(provide 'lsp-typespec)
;;; lsp-typespec.el ends here
Expand Down
1 change: 1 addition & 0 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ Changes take effect only when a new session is started."
(typescript-mode . "typescript")
(typescript-ts-mode . "typescript")
(typespec-mode . "typespec")
(typespec-ts-mode . "typespec")
(tsx-ts-mode . "typescriptreact")
(svelte-mode . "svelte")
(fsharp-mode . "fsharp")
Expand Down

0 comments on commit ff1e943

Please sign in to comment.