Skip to content

Commit

Permalink
Fix installing fsautocomplete process
Browse files Browse the repository at this point in the history
- Use cache for avoiding getting latest version
- Fix version checking
- Don't always install fsautocomplete
  • Loading branch information
syohex committed Nov 8, 2022
1 parent cfd3f88 commit 962f215
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions eglot-fsharp.el
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@

(defun eglot-fsharp--latest-version ()
"Return latest fsautocomplete.exe version."
(let* ((json (with-temp-buffer (url-insert-file-contents "https://azuresearch-usnc.nuget.org/query?q=fsautocomplete&prerelease=false&packageType=DotnetTool")
(json-parse-buffer)))
(versions (gethash "versions" (aref (gethash "data" json) 0))))
(gethash "version" (aref versions (1- (length versions))))))
(or eglot-fsharp--latest-version
(let* ((json (with-temp-buffer (url-insert-file-contents "https://azuresearch-usnc.nuget.org/query?q=fsautocomplete&prerelease=false&packageType=DotnetTool")
(json-parse-buffer)))
(versions (gethash "versions" (aref (gethash "data" json) 0))))
(setq eglot-fsharp--latest-version (gethash "version" (aref versions (1- (length versions))))))))

(defun eglot-fsharp--installed-version ()
"Return version string of fsautocomplete."
Expand All @@ -77,10 +78,10 @@
(defun eglot-fsharp-current-version-p (version)
"Return t if the installation is not outdated."
(when (file-exists-p (eglot-fsharp--path-to-server))
(if (eq version 'latest)
(if (eq eglot-fsharp-server-version 'latest)
(equal (eglot-fsharp--latest-version)
(eglot-fsharp--installed-version))
(equal eglot-fsharp-server-version (eglot-fsharp--installed-version)))))
(equal version (eglot-fsharp--installed-version)))))

(defun eglot-fsharp--install-core (version)
"Download and install fsautocomplete as a dotnet tool at version VERSION in `eglot-fsharp-server-install-dir'."
Expand All @@ -96,12 +97,12 @@
nil "tool" "uninstall"
"fsautocomplete" "--tool-path"
default-directory))
(error "'dotnet tool uninstall fsautocomplete --tool-path %s' failed" default-directory))))
(unless (zerop (call-process "dotnet" nil `(nil ,stderr-file) nil
"tool" "install" "fsautocomplete"
"--tool-path" default-directory "--version"
version))
(error "'dotnet tool install fsautocomplete --tool-path %s --version %s' failed" default-directory version)))
(error "'dotnet tool uninstall fsautocomplete --tool-path %s' failed" default-directory)))
(unless (zerop (call-process "dotnet" nil `(nil ,stderr-file) nil
"tool" "install" "fsautocomplete"
"--tool-path" default-directory "--version"
version))
(error "'dotnet tool install fsautocomplete --tool-path %s --version %s' failed" default-directory version))))
(error
(let ((stderr (with-temp-buffer
(insert-file-contents stderr-file)
Expand Down

0 comments on commit 962f215

Please sign in to comment.