fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
205 stars 62 forks source link

Possibly wrong path for fsautocomplete #341

Closed arialdomartini closed 1 month ago

arialdomartini commented 1 month ago

Description

eglot-fsharp--path-to-server expects fsautocomplete to be in netcore subdir. dotnet tool install does not install it in that subdir.

Repro steps

Actual behavior

I get the error:

Error in post-command-hook (#[0 "\303\301!\205\0r\301q\210\304\305\300\242\306#\210
?\205\0\307\310\311 \")\207" [(#0) #<buffer Program.fs> eglot--managed-mode buffer-live-p remove-hook post-command-hook t apply eglot--connect eglot--guess-contact] 4]): (file-missing "Doing vfork" "No such file or directory")

Known workarounds

I think the problem is with the function:

(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" ""))))

which uses the hardcoded value netcore/fsautocomplete.

With the help of @protesilaos I modified it to:

(defun eglot-fsharp--path-to-server ()
    "Return FsAutoComplete path."
    (file-truename (concat eglot-fsharp-server-install-dir "fsautocomplete" (if (eq system-type 'windows-nt) ".exe" ""))))

which fixed the problem.
I work on Arch Linux with SDK 8. I am not sure if this path is also valid for other configurations. It would probably a good idea to have that value parametric.

Related information

arialdomartini commented 1 month ago

I just found out that the problem arises only if fsautocomplete has being installed via dotnet tool.

The ambiguity could be because dotnet tool and eglot-fsharp install fsautocomplete in 2 different paths:

Tool Install path
dotnet tool ~/.dotnet/tools
eglot-fsharp ~/.dotnet/tools/netcore
arialdomartini commented 1 month ago

I think I found the problem. I had this configuration in place:

(use-package eglot-fsharp
  :ensure t
  :after fsharp-mode
  :config
  (setq eglot-fsharp-server-install-dir "~/.dotnet/tools/"))

because I wanted to make sure that fsautocomplete was not downloaded twice. I learnt that by default eglot-fsharp does not downlod fsautocomplete in ~/.dotnet, but in the startard XDG directory.

My suggestion would be to include the hardcoded netcore path in eglot-fsharp-server-install-dir so in case a user configures it, as above, netcore is not added, with something like:

(defcustom eglot-fsharp-server-install-dir
  (concat (locate-user-emacs-file "FsAutoComplete") "/" "netcore")
  "Install directory for FsAutoComplete."
  :group 'eglot-fsharp
  :risky t
  :type 'directory)

With this,

juergenhoetzel commented 1 month ago

Fixed in #342

(use-package eglot-fsharp
  :ensure t
  :after fsharp-mode
  :custom (eglot-fsharp-server-install-dir nil))

will use the global user tool path.

arialdomartini commented 1 month ago

Works like a breeze! Thank you.