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

Fix installing fsautocomplete process #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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))))))))
Comment on lines +67 to +71
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use cache.

(defvar eglot-fsharp--latest-version nil "Latest fsautocomplete.exe version string.")

The cache variable is declared but it is never used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of (eglot-fsharp--latest-version) is to ALWAYS return the exact version string, so we can compare the version string of the locally installed version string and prevent downloading the nuget artefact.

Maybe I should document this better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juergenhoetzel Should I remove cache variable ? Comparison is already implemented. Sorry I didn't catch what you mean.

(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)
(equal (eglot-fsharp--latest-version)
(eglot-fsharp--installed-version))
(equal eglot-fsharp-server-version (eglot-fsharp--installed-version)))))


(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)
Comment on lines -80 to +81
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version argument is string type, so it is never '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)))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eglot-fsharp-server-version may be symbol. So version should be used here.


(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)))
Comment on lines -100 to -104
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block is always evaluated even if desired version is installed. I suppose if this expression should be evaluated if (eglot-fsharp-current-version-p version) is nil

(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