Skip to content

Commit

Permalink
Merge pull request #342 from juergenhoetzel/allow-system-tool-path
Browse files Browse the repository at this point in the history
Allow to use "fsautocomplete" from the global tool-path.
  • Loading branch information
juergenhoetzel committed May 14, 2024
2 parents b4d31c3 + cfc7047 commit 677d78c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 69 deletions.
90 changes: 45 additions & 45 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,58 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
dotnet: [6.0.200]
dotnet: [8.0.x]
emacs_version:
- 27.2
- 28.1
- 28.2
- 29.3
- snapshot
steps:
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet }}
- uses: actions/checkout@v2
- name: Install Eldev
run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh
- name: Show dotnet sdks
run: dotnet --list-sdks
- name: Show dotnet version
run: dotnet --info
- name: Test
run: |
echo "Archives:"
eldev archives
echo "Dependencies:"
eldev -v dependencies
echo "Testing:"
eldev -dtT test
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet }}
- uses: actions/checkout@v2
- name: Install Eldev
run: curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/github-eldev | sh
- name: Show dotnet sdks
run: dotnet --list-sdks
- name: Show dotnet version
run: dotnet --info
- name: Test
run: |
echo "Archives:"
eldev archives
echo "Dependencies:"
eldev -v dependencies
echo "Testing:"
eldev -dtT test
windows-build:
runs-on: windows-latest
strategy:
fail-fast: false
steps:
- uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.200
- name: Show dotnet sdks
run: dotnet --list-sdks
- name: Show dotnet version
run: dotnet --info
- name: Set up Emacs on Windows
uses: jcs090218/setup-emacs-windows@master
with:
version: 28.1
- uses: actions/checkout@v2
- name: Install Eldev
run: curl.exe -fsSL https://raw.github.com/doublep/eldev/master/webinstall/eldev.bat | cmd /Q
- name: Test
run: |
echo "Archives:"
~/.local/bin/eldev.bat archives
echo "Dependencies:"
~/.local/bin/eldev.bat dependencies
echo "Testing:"
~/.local/bin/eldev.bat -p -dtT test
- uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.200
- name: Show dotnet sdks
run: dotnet --list-sdks
- name: Show dotnet version
run: dotnet --info
- name: Set up Emacs on Windows
uses: jcs090218/setup-emacs-windows@master
with:
version: 28.1
- uses: actions/checkout@v2
- name: Install Eldev
run: curl.exe -fsSL https://raw.github.com/doublep/eldev/master/webinstall/eldev.bat | cmd /Q
- name: Test
run: |
echo "Archives:"
~/.local/bin/eldev.bat archives
echo "Dependencies:"
~/.local/bin/eldev.bat dependencies
echo "Testing:"
~/.local/bin/eldev.bat -p -dtT test
51 changes: 28 additions & 23 deletions eglot-fsharp.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; eglot-fsharp.el --- fsharp-mode eglot integration -*- lexical-binding: t; -*-

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

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

(defcustom eglot-fsharp-server-version 'latest
"FsAutoComplete version to install or update."
Expand All @@ -63,7 +63,7 @@
:abstractClassStubGenerationObjectIdentifier "this"
:addFsiWatcher nil
:codeLenses (:references (:enabled t)
:signature (:enabled t))
:signature (:enabled t))
:disableFailedProjectNotifications nil
:dotnetRoot ""
:enableAdaptiveLspServer t
Expand Down Expand Up @@ -120,7 +120,10 @@

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

;; cache to prevent repetitive queries
(defvar eglot-fsharp--latest-version nil "Latest fsautocomplete.exe version string.")
Expand All @@ -135,7 +138,9 @@
(defun eglot-fsharp--installed-version ()
"Return version string of fsautocomplete."
(with-temp-buffer
(process-file "dotnet" nil t nil "tool" "list" "--tool-path" (file-name-directory (eglot-fsharp--path-to-server)))
(if eglot-fsharp-server-install-dir
(process-file "dotnet" nil t nil "tool" "list" "--tool-path" (file-name-directory (eglot-fsharp--path-to-server)))
(process-file "dotnet" nil t nil "tool" "list" "-g"))
(goto-char (point-min))
(when (search-forward-regexp "^fsautocomplete[[:space:]]+\\([0-9\.]*\\)[[:space:]]+" nil t)
(match-string 1))))
Expand All @@ -150,35 +155,35 @@
(let* ((default-directory (concat (file-remote-p default-directory)
(file-name-directory (eglot-fsharp--path-to-server))))
(stderr-file (make-temp-file "dotnet_stderr"))
(local-tool-path (or (file-remote-p default-directory 'localname) default-directory)))
(local-tool-path (or (file-remote-p default-directory 'localname) default-directory))
(process-file-uninstall-args (if eglot-fsharp-server-install-dir
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "uninstall" "fsautocomplete" "--tool-path" local-tool-path)
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "uninstall" "-g" "fsautocomplete")))
(process-file-install-args (if eglot-fsharp-server-install-dir
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "install" "fsautocomplete" "--tool-path" local-tool-path "--version" version)
(list "dotnet" nil `(nil ,stderr-file) nil "tool" "install" "fsautocomplete" "-g" "--version" version))))
(make-directory default-directory t)
(condition-case err
(progn
(unless (eglot-fsharp-current-version-p version)
(message "Installing fsautocomplete version %s" version)
(when (file-exists-p (concat (file-remote-p default-directory)
(eglot-fsharp--path-to-server)))
(unless (zerop (process-file "dotnet" nil `(nil
,stderr-file)
nil "tool" "uninstall"
"fsautocomplete" "--tool-path"
local-tool-path))
(error "'dotnet tool uninstall fsautocomplete --tool-path %s' failed" default-directory))))
(unless (zerop (process-file "dotnet" nil `(nil ,stderr-file) nil
"tool" "install" "fsautocomplete"
"--tool-path" local-tool-path "--version"
version))
(unless (or (eglot-fsharp-current-version-p version) (not (eglot-fsharp--installed-version)))
(message "Uninstalling fsautocomplete version %s" (eglot-fsharp--installed-version))
(unless (zerop (apply #'process-file process-file-uninstall-args))
(error "'dotnet tool uninstall fsautocomplete ... failed")))
(unless (zerop (apply #'process-file process-file-install-args))
(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)
(buffer-string))))
(delete-file stderr-file)
(signal (car err) (format "%s: %s" (cdr err) stderr)))))))
(signal (car err) (format "%s: %s" (cdr err) stderr)))))
(message "Installed fsautocomplete to %s" (eglot-fsharp--path-to-server))))

(defun eglot-fsharp--maybe-install (&optional version)
"Downloads F# compiler service, and install in `eglot-fsharp-server-install-dir'."
(make-directory (concat (file-remote-p default-directory)
(file-name-directory (eglot-fsharp--path-to-server))) t)
(unless eglot-fsharp-server-install-dir
(make-directory (concat (file-remote-p default-directory)
(file-name-directory (eglot-fsharp--path-to-server))) t))
(let* ((version (or version (if (eq eglot-fsharp-server-version 'latest)
(eglot-fsharp--latest-version)
eglot-fsharp-server-version))))
Expand Down
2 changes: 1 addition & 1 deletion test/eglot-fsharp-integration-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(find-file-noselect file))

(defun eglot-fsharp--tests-connect (&optional timeout)
(let* ((timeout (or timeout 10))
(let* ((timeout (or timeout 30))
(eglot-sync-connect t)
(eglot-connect-timeout timeout))
(apply #'eglot--connect (eglot--guess-contact))))
Expand Down

0 comments on commit 677d78c

Please sign in to comment.