|
91 | 91 |
|
92 | 92 | (defun eglot-fsharp--installed-version ()
|
93 | 93 | "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)))) |
96 | 99 |
|
97 | 100 | (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)))) |
104 | 104 |
|
105 | 105 | (defun eglot-fsharp--install-core (version)
|
106 | 106 | "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))) |
109 | 111 | (condition-case err
|
110 | 112 | (progn
|
111 | 113 | (unless (eglot-fsharp-current-version-p version)
|
112 | 114 | (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 |
115 | 118 | ,stderr-file)
|
116 | 119 | nil "tool" "uninstall"
|
117 | 120 | "fsautocomplete" "--tool-path"
|
118 |
| - default-directory)) |
| 121 | + local-tool-path)) |
119 | 122 | (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 |
121 | 124 | "tool" "install" "fsautocomplete"
|
122 |
| - "--tool-path" default-directory "--version" |
| 125 | + "--tool-path" local-tool-path "--version" |
123 | 126 | version))
|
124 | 127 | (error "'dotnet tool install fsautocomplete --tool-path %s --version %s' failed" default-directory version)))
|
125 | 128 | (error
|
|
131 | 134 |
|
132 | 135 | (defun eglot-fsharp--maybe-install (&optional version)
|
133 | 136 | "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) |
135 | 139 | (let* ((version (or version (if (eq eglot-fsharp-server-version 'latest)
|
136 | 140 | (eglot-fsharp--latest-version)
|
137 | 141 | eglot-fsharp-server-version))))
|
138 |
| - (eglot-fsharp--install-core version))) |
| 142 | + (unless (eglot-fsharp-current-version-p version) |
| 143 | + (eglot-fsharp--install-core version)))) |
139 | 144 |
|
140 | 145 | ;;;###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. |
144 | 148 | Ensure FsAutoComplete is installed (when called INTERACTIVE)."
|
145 | 149 | (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)))) |
149 | 155 |
|
150 | 156 |
|
151 | 157 | (defclass eglot-fsautocomplete (eglot-lsp-server) ()
|
|
0 commit comments