Skip to content

Commit cbe4d3c

Browse files
Merge pull request #329 from juergenhoetzel/tramp-tty
Make `eglot-fsharp' tramp aware
2 parents 09fec6c + 6e3c918 commit cbe4d3c

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

eglot-fsharp.el

+29-23
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,38 @@
9191

9292
(defun eglot-fsharp--installed-version ()
9393
"Return version string of fsautocomplete."
94-
(seq-some (lambda (s) (and (string-match "^fsautocomplete[[:space:]]+\\([0-9\.]*\\)[[:space:]]+" s) (match-string 1 s)))
95-
(process-lines "dotnet" "tool" "list" "--tool-path" (file-name-directory (eglot-fsharp--path-to-server)))))
94+
(with-temp-buffer
95+
(process-file "dotnet" nil t nil "tool" "list" "--tool-path" (file-name-directory (eglot-fsharp--path-to-server)))
96+
(goto-char (point-min))
97+
(when (search-forward-regexp "^fsautocomplete[[:space:]]+\\([0-9\.]*\\)[[:space:]]+" nil t)
98+
(match-string 1))))
9699

97100
(defun eglot-fsharp-current-version-p (version)
98-
"Return t if the installation is not outdated."
99-
(when (file-exists-p (eglot-fsharp--path-to-server))
100-
(if (eq version 'latest)
101-
(equal (eglot-fsharp--latest-version)
102-
(eglot-fsharp--installed-version))
103-
(equal eglot-fsharp-server-version (eglot-fsharp--installed-version)))))
101+
"Return t if the installation is up-to-date compared to VERSION string."
102+
(and (file-exists-p (concat (file-remote-p default-directory) (eglot-fsharp--path-to-server)))
103+
(equal version (eglot-fsharp--installed-version))))
104104

105105
(defun eglot-fsharp--install-core (version)
106106
"Download and install fsautocomplete as a dotnet tool at version VERSION in `eglot-fsharp-server-install-dir'."
107-
(let ((default-directory (file-name-directory (eglot-fsharp--path-to-server)))
108-
(stderr-file (make-temp-file "dotnet_stderr")))
107+
(let* ((default-directory (concat (file-remote-p default-directory)
108+
(file-name-directory (eglot-fsharp--path-to-server))))
109+
(stderr-file (make-temp-file "dotnet_stderr"))
110+
(local-tool-path (or (file-remote-p default-directory 'localname) default-directory)))
109111
(condition-case err
110112
(progn
111113
(unless (eglot-fsharp-current-version-p version)
112114
(message "Installing fsautocomplete version %s" version)
113-
(when (file-exists-p (eglot-fsharp--path-to-server))
114-
(unless (zerop (call-process "dotnet" nil `(nil
115+
(when (file-exists-p (concat (file-remote-p default-directory)
116+
(eglot-fsharp--path-to-server)))
117+
(unless (zerop (process-file "dotnet" nil `(nil
115118
,stderr-file)
116119
nil "tool" "uninstall"
117120
"fsautocomplete" "--tool-path"
118-
default-directory))
121+
local-tool-path))
119122
(error "'dotnet tool uninstall fsautocomplete --tool-path %s' failed" default-directory))))
120-
(unless (zerop (call-process "dotnet" nil `(nil ,stderr-file) nil
123+
(unless (zerop (process-file "dotnet" nil `(nil ,stderr-file) nil
121124
"tool" "install" "fsautocomplete"
122-
"--tool-path" default-directory "--version"
125+
"--tool-path" local-tool-path "--version"
123126
version))
124127
(error "'dotnet tool install fsautocomplete --tool-path %s --version %s' failed" default-directory version)))
125128
(error
@@ -131,21 +134,24 @@
131134

132135
(defun eglot-fsharp--maybe-install (&optional version)
133136
"Downloads F# compiler service, and install in `eglot-fsharp-server-install-dir'."
134-
(make-directory (file-name-directory (eglot-fsharp--path-to-server)) t)
137+
(make-directory (concat (file-remote-p default-directory)
138+
(file-name-directory (eglot-fsharp--path-to-server))) t)
135139
(let* ((version (or version (if (eq eglot-fsharp-server-version 'latest)
136140
(eglot-fsharp--latest-version)
137141
eglot-fsharp-server-version))))
138-
(eglot-fsharp--install-core version)))
142+
(unless (eglot-fsharp-current-version-p version)
143+
(eglot-fsharp--install-core version))))
139144

140145
;;;###autoload
141-
(defun eglot-fsharp
142-
(interactive)
143-
"Return `eglot' contact when FsAutoComplete is installed.
146+
(defun eglot-fsharp (interactive)
147+
"Return `eglot' contact when FsAutoComplete is installed.
144148
Ensure FsAutoComplete is installed (when called INTERACTIVE)."
145149
(when interactive (eglot-fsharp--maybe-install))
146-
(when (file-exists-p (eglot-fsharp--path-to-server))
147-
(cons 'eglot-fsautocomplete (cons (eglot-fsharp--path-to-server)
148-
eglot-fsharp-server-args))))
150+
(cons 'eglot-fsautocomplete
151+
(if (file-remote-p default-directory)
152+
`("sh" ,shell-command-switch ,(concat "cat|" (mapconcat #'shell-quote-argument
153+
(cons (eglot-fsharp--path-to-server) eglot-fsharp-server-args) " ")))
154+
(cons (eglot-fsharp--path-to-server) eglot-fsharp-server-args))))
149155

150156

151157
(defclass eglot-fsautocomplete (eglot-lsp-server) ()

0 commit comments

Comments
 (0)