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

lsp-csharp.el: fix breakage with the latest emacs #3349

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Add [[https://github.com/remarkjs/remark-language-server][remark-language-server]]
* Deprecate unified-languge-server in favor of remark-language-server
* Made it possible to disable ~lsp-response-timeout~ entirely.
* Fix csharp-ls startup on emacs@master (and emacs@emacs-28 on macOS) due to a switch posix_spawn and not setting proper sigmask on child processes.
** Release 8.0.0
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.
* Set ~lsp-clients-angular-language-server-command~ after the first connection to speed up subsequent connections.
Expand Down
41 changes: 35 additions & 6 deletions clients/lsp-csharp.el
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,39 @@ is returned so lsp-mode can display this file."
(with-temp-buffer (insert-file-contents metadata-file-name)
(buffer-string))))))

(defun lsp-csharp--cls-make-launch-cmd ()
"Return command line to invoke csharp-ls."

;; latest emacs-28 (on macOS) and master (as of Sat Feb 12 EET 2022) has an issue
;; that it launches processes using posix_spawn but does not reset sigmask properly
;; thus causing dotnet runtime to lockup awaiting a SIGCHLD signal that never comes
;; from subprocesses that quit
;;
;; as a workaround we will wrap csharp-ls invocation in "/usr/bin/env --default-signal"
;; (on linux) and "/bin/ksh -c" (on macos) so it launches with proper sigmask
;;
;; see https://lists.gnu.org/archive/html/emacs-devel/2022-02/msg00461.html

(let ((startup-wrapper (cond ((and (eq 'darwin system-type)
(version<= "28.0" emacs-version))
(list "/bin/ksh" "-c"))

((and (eq 'gnu/linux system-type)
(version<= "29.0" emacs-version))
(list "/usr/bin/env" "--default-signal"))

(t nil)))
(solution-file-params (when lsp-csharp-solution-file
(list "-s" lsp-csharp-solution-file))))
(append startup-wrapper
(list "csharp-ls")
solution-file-params)))

(defun lsp-csharp--cls-test-csharp-ls-present ()
"Return non-nil if dotnet tool csharp-ls is installed globally."
(string-match-p "csharp-ls"
(shell-command-to-string "dotnet tool list -g")))

(defun lsp-csharp--cls-download-server (_client callback error-callback update?)
"Install/update csharp-ls language server using `dotnet tool'.

Expand All @@ -424,12 +457,8 @@ Will invoke CALLBACK or ERROR-CALLBACK based on result. Will update if UPDATE? i
"dotnet" "tool" (if update? "update" "install") "-g" "csharp-ls"))

(lsp-register-client
(make-lsp-client :new-connection
(lsp-stdio-connection
#'(lambda ()
(append (list "csharp-ls")
(when lsp-csharp-solution-file
(list "-s" lsp-csharp-solution-file)))))
(make-lsp-client :new-connection (lsp-stdio-connection #'lsp-csharp--cls-make-launch-cmd
#'lsp-csharp--cls-test-csharp-ls-present)
:priority -2
:server-id 'csharp-ls
:major-modes '(csharp-mode csharp-tree-sitter-mode)
Expand Down