fsprojects / fsharp-language-server

Other
219 stars 37 forks source link

Notes/Fixes For Emacs Users #31

Closed adamnew123456 closed 5 years ago

adamnew123456 commented 5 years ago

Since there isn't much documentation on what Emacs configuration looks like, I thought I'd share a few things I discovered, so that someone (hopefully me, if I can find the time) can flesh this out into a more complete config.

The only problem I had with the server itself is that lsp-mode checks the value of the "jsonrpc" attribute, which isn't set when the server replies to client messages. It isn't fatal, but causes messages to appear in the Warnings buffer for every message lsp-mode receives.

The fix is trivial (just add "jsonrpc":"2.0" to the two JSON templates in the LSP project) but it also requires updating a few tests too. If you want, I can update those and send a full PR.

This is what I have regarding the actual configuration, at least with Spacemacs:

  1. fsharp-mode will usually run FSAC, which conflicts with the completion provided by lsp-mode. Make sure to (setq fsharp-ac-intellisense-enabled nil) prior to loading fsharp-mode to disable FSAC.
  2. You'll need to link in the LSP company backend as part of the fsharp-mode load hook. With Spacemacs, the config looks like this and should probably go in your post-init-company:
(spacemacs|add-company-backends 
 :backends company-lsp
 :modes fsharp-mode
 :append-hooks nil
 :call-hooks t)
(company-mode)
  1. You'll also want to activate the LSP keybinds, instead of fsharp-mode keybinds that require FSAC. With Spacemacs, you'll want to put this into init-fsharp-mode's :config entry: (spacemacs/lsp-bind-keys-for-mode 'fsharp-mode)
  2. If you're using a recent LSP mode, you can define and initialize the LSP service this way. It needs to happen when you're already in fsharp-mode, so the fsharp-mode hook is a good place to run this:
(require 'lsp)
(lsp-register-client
 (make-lsp-client 
  :new-connection (lsp-stdio-connection "FSharpLanguageServer") ;; Must be on your PATH
  :major-modes '(fsharp-mode)
  :server-id 'fsharp-lsp))
(lsp) ;; Auto-initializes to fsharp-lsp as long as you're in fsharp-mode
georgewfraser commented 5 years ago

It would be fantastic if you would make a PR adding "jsonrpc":"2.0", and EMacs instructions in README.md. Don't worry if the instructions aren't perfect---right now, we have nothing!