Skip to content

Commit 8349840

Browse files
Allow to use "fsautocomplete" from the global tool-path.
Setting `eglot-fsharp-server-install-dir' to nil disables the custom "~/.emacs.d/FsAutoComplete/netcore/" tool path. Fixes #341
1 parent b4d31c3 commit 8349840

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
@@ -1,6 +1,6 @@
11
;;; eglot-fsharp.el --- fsharp-mode eglot integration -*- lexical-binding: t; -*-
22

3-
;; Copyright (C) 2019-2023 Jürgen Hötzel
3+
;; Copyright (C) 2019-2024 Jürgen Hötzel
44

55
;; Author: Jürgen Hötzel <juergen@hoetzel.info>
66
;; Package-Requires: ((emacs "27.1") (eglot "1.4") (fsharp-mode "1.10") (jsonrpc "1.0.14"))
@@ -41,7 +41,7 @@
4141
"Install directory for FsAutoComplete."
4242
:group 'eglot-fsharp
4343
:risky t
44-
:type 'directory)
44+
:type '(choice directory (const :tag "Use dotnet default for tool-path" nil)))
4545

4646
(defcustom eglot-fsharp-server-version 'latest
4747
"FsAutoComplete version to install or update."
@@ -63,7 +63,7 @@
6363
:abstractClassStubGenerationObjectIdentifier "this"
6464
:addFsiWatcher nil
6565
:codeLenses (:references (:enabled t)
66-
:signature (:enabled t))
66+
:signature (:enabled t))
6767
:disableFailedProjectNotifications nil
6868
:dotnetRoot ""
6969
:enableAdaptiveLspServer t
@@ -120,7 +120,10 @@
120120

121121
(defun eglot-fsharp--path-to-server ()
122122
"Return FsAutoComplete path."
123-
(file-truename (concat eglot-fsharp-server-install-dir "netcore/fsautocomplete" (if (eq system-type 'windows-nt) ".exe" ""))))
123+
(let ((base (if eglot-fsharp-server-install-dir
124+
(concat eglot-fsharp-server-install-dir "netcore/")
125+
"~/.dotnet/tools/")))
126+
(expand-file-name (concat base "fsautocomplete" (if (eq system-type 'windows-nt) ".exe" "")))))
124127

125128
;; cache to prevent repetitive queries
126129
(defvar eglot-fsharp--latest-version nil "Latest fsautocomplete.exe version string.")
@@ -135,7 +138,9 @@
135138
(defun eglot-fsharp--installed-version ()
136139
"Return version string of fsautocomplete."
137140
(with-temp-buffer
138-
(process-file "dotnet" nil t nil "tool" "list" "--tool-path" (file-name-directory (eglot-fsharp--path-to-server)))
141+
(if eglot-fsharp-server-install-dir
142+
(process-file "dotnet" nil t nil "tool" "list" "--tool-path" (file-name-directory (eglot-fsharp--path-to-server)))
143+
(process-file "dotnet" nil t nil "tool" "list" "-g"))
139144
(goto-char (point-min))
140145
(when (search-forward-regexp "^fsautocomplete[[:space:]]+\\([0-9\.]*\\)[[:space:]]+" nil t)
141146
(match-string 1))))
@@ -150,35 +155,36 @@
150155
(let* ((default-directory (concat (file-remote-p default-directory)
151156
(file-name-directory (eglot-fsharp--path-to-server))))
152157
(stderr-file (make-temp-file "dotnet_stderr"))
153-
(local-tool-path (or (file-remote-p default-directory 'localname) default-directory)))
158+
(local-tool-path (or (file-remote-p default-directory 'localname) default-directory))
159+
(process-file-uninstall-args (if eglot-fsharp-server-install-dir
160+
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "uninstall" "fsautocomplete" "--tool-path" local-tool-path)
161+
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "uninstall" "-g" "fsautocomplete")))
162+
(process-file-install-args (if eglot-fsharp-server-install-dir
163+
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "install" "fsautocomplete" "--tool-path" local-tool-path "--version" version)
164+
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "install" "fsautocomplete" "-g" "--version" version))))
165+
(unless (file-directory-p default-directory)
166+
(make-directory default-directory))
154167
(condition-case err
155168
(progn
156-
(unless (eglot-fsharp-current-version-p version)
157-
(message "Installing fsautocomplete version %s" version)
158-
(when (file-exists-p (concat (file-remote-p default-directory)
159-
(eglot-fsharp--path-to-server)))
160-
(unless (zerop (process-file "dotnet" nil `(nil
161-
,stderr-file)
162-
nil "tool" "uninstall"
163-
"fsautocomplete" "--tool-path"
164-
local-tool-path))
165-
(error "'dotnet tool uninstall fsautocomplete --tool-path %s' failed" default-directory))))
166-
(unless (zerop (process-file "dotnet" nil `(nil ,stderr-file) nil
167-
"tool" "install" "fsautocomplete"
168-
"--tool-path" local-tool-path "--version"
169-
version))
169+
(unless (or (eglot-fsharp-current-version-p version) (not (eglot-fsharp--installed-version)))
170+
(message "Uninstalling fsautocomplete version %s" (eglot-fsharp--installed-version))
171+
(unless (zerop (apply #'process-file process-file-uninstall-args))
172+
(error "'dotnet tool uninstall fsautocomplete ... failed")))
173+
(unless (zerop (apply #'process-file process-file-install-args))
170174
(error "'dotnet tool install fsautocomplete --tool-path %s --version %s' failed" default-directory version)))
171175
(error
172176
(let ((stderr (with-temp-buffer
173177
(insert-file-contents stderr-file)
174178
(buffer-string))))
175179
(delete-file stderr-file)
176-
(signal (car err) (format "%s: %s" (cdr err) stderr)))))))
180+
(signal (car err) (format "%s: %s" (cdr err) stderr)))))
181+
(message "Installed fsautocomplete to %s" (eglot-fsharp--path-to-server))))
177182

178183
(defun eglot-fsharp--maybe-install (&optional version)
179184
"Downloads F# compiler service, and install in `eglot-fsharp-server-install-dir'."
180-
(make-directory (concat (file-remote-p default-directory)
181-
(file-name-directory (eglot-fsharp--path-to-server))) t)
185+
(unless eglot-fsharp-server-install-dir
186+
(make-directory (concat (file-remote-p default-directory)
187+
(file-name-directory (eglot-fsharp--path-to-server))) t))
182188
(let* ((version (or version (if (eq eglot-fsharp-server-version 'latest)
183189
(eglot-fsharp--latest-version)
184190
eglot-fsharp-server-version))))

0 commit comments

Comments
 (0)