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

Output stderr when starting tsserver #473

Open
2 of 7 tasks
arichiardi opened this issue Aug 27, 2024 · 3 comments
Open
2 of 7 tasks

Output stderr when starting tsserver #473

arichiardi opened this issue Aug 27, 2024 · 3 comments

Comments

@arichiardi
Copy link

Checklist

  • I have searched both open and closed issues and cannot find a duplicate.
  • I can reproduce the problem with the latest version of the relevant packages.
  • The problem still occurs after I issued M-x tide-restart-server in the buffer where I had the problem.
  • I verified that the version and the configuration file path reported by M-x tide-verify-setup are correct.
  • If tide is reporting an error or warning I think should not be reported, I can run tsc (and tslint, if applicable) without the error or warning I'm seeing in tide.
  • If tide is not reporting an error or warning I think should be reported, tsc (or tslint, if applicable) reports the error or warning I was expecting to see.
  • I am positive the problem does not belong to typescript-mode or tsserver.

Relevant Version Numbers

  • Tide: v5.1.3
  • TypeScript: tsc --version Version 5.5.4
  • Emacs: 29.4

Steps to Reproduce the Bug

Not a bug but I have done some debugging for errors very similar to #438 and #87.

Expected Behavior

When the tsserver process cannot start, it would be good to see why in the message buffer.

Actual Behavior

In many occasions this does happen.


I was able to get good output by setting this:

(set-process-sentinel process #'tide-net-sentinel)

In my case the error was:

Couldn’t locate project root folder with a tsconfig.json or jsconfig.json file. Using ’/home/user/.config/emacs/lib/tide/’ as project root.

At the point I kind of asked myself why that's the case and stumble across Emacs Async Processes page. It might be the case that start-process, being a wrapper, does not do much with regards to :stderr (see make-process).

I am not sure cause haven't tried (yet) but probably using make-process would give more control over the output and will end up showing the right message.

@arichiardi
Copy link
Author

Ok, this outputs good error messages to *Messages*

(defun tide-start-server ()
  (when (tide-current-server)
    (error "Server already exist"))

  (message "(%s) Starting tsserver..." (tide-project-name))
  (let* ((default-directory (tide-project-root))
         (process-environment (append tide-tsserver-process-environment process-environment))
         (buf (generate-new-buffer tide-server-buffer-name))
         (tsserverjs (tide-locate-tsserver-executable))
         (node-process-arguments (append tide-node-flags (list tsserverjs) tide-tsserver-flags))
         (process-name "tsserver"))
    (make-process
     :name process-name
     :buffer buf
     :command (append (list tide-node-executable) node-process-arguments)
     ;; Use a pipe to communicate with the subprocess. This fixes a hang
     ;; when a >1k message is sent on macOS.
     :connection-type nil
     :stderr "*Messages*"
     :coding 'utf-8-unix
     :noquery t
     :filter #'tide-net-filter
     :sentinel #'tide-net-sentinel)
    (let ((process (get-process process-name)))
      (with-current-buffer (process-buffer process)
        (buffer-disable-undo))
      (process-put process 'project-name (tide-project-name))
      (process-put process 'project-root default-directory)
      (puthash (tide-project-name) process tide-servers)
      (message "(%s) tsserver server started successfully." (tide-project-name))
      (tide-each-buffer (tide-project-name) #'tide-configure-buffer))))

It should probably be refined but I wanted to check if this approach has drawbacks before PR-ing it. Thoughts?

@arichiardi
Copy link
Author

@ananthakumaran apologies for the ping but would you open to a PR with the above?

@arichiardi
Copy link
Author

Let me know what you think arichiardi@cf9bad1

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

1 participant