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

textDocument/rangeFormatting always hangs? #423

Open
jjlee opened this issue Mar 12, 2020 · 5 comments
Open

textDocument/rangeFormatting always hangs? #423

jjlee opened this issue Mar 12, 2020 · 5 comments

Comments

@jjlee
Copy link

jjlee commented Mar 12, 2020

reason-language-server hangs for me when sending it the following textDocument/rangeFormatting request (I gave it 60 seconds):

{
  "textDocument": {
    "uri": "file:///home/me/dev/node-scratch/my-new-project/src/Baz.re"
  },
  "options": {
    "tabSize": 2,
    "insertSpaces": true
  },
  "range": {
    "start": {
      "line": 2,
      "character": 0
    },
    "end": {
      "line": 2,
      "character": 16
    }
  }
}

Baz.re looks like this:

let foo = "Bar";
let bar = 231;

emacs lsp-mode.el (lsp-mode-20200311.612) seems to send this request whenever I paste a line of text into the file I'm editing (for example, if I paste in let foo = "Bar"; again so that I have two lines in a row like that). I checked the logs for vscode when pasting text, and VS Code does not seem to do that -- in fact I wasn't able to trigger it to send a textDocument/rangeFormatting at all.

So I have a suspicion that most of the editor LSP clients for Reason use the node.js implementation (all of which are implemented using the same node module I think) and never use that method, and that reason-language-server may never respond properly to requests of that method, always hanging?

If I hack lsp-mode.el to prevent it from trying, at least basics work -- in reason-mode with lsp enabled and using reason-language-server, syntax highlighting and tooltips (lsp-ui-mode) work and I can get type info using lsp-describe-thing-at-point. So perhaps one possible fix is to remove support for that method? (guessing totally here, I know nothing about LSP nor Reason)

@gaku-sei
Copy link

gaku-sei commented Mar 13, 2020

I'm facing the same issue, and thought it could be because of refmt, but apparently no: reasonml/reason#2549

edit: I forgot to mention that rls is hanging on VS Code.

@jjlee
Copy link
Author

jjlee commented Mar 13, 2020

I now remember that when I explicity told emacs to reformat a region (before I applied my hacks to the emacs code), I got broken formatting. I haven't verified it's using the same method in that case, but I'm pretty sure it is. So I think it does not hang under some circumstances.

@jjlee
Copy link
Author

jjlee commented Mar 13, 2020

Hm, does refmt even use the language server protocol?

I saw the hanging issue described in this issue literally on a new autogenerated project that I created by following the instructions on the Reason website: https://reasonml.github.io/docs/en/installation#new-project

So @gaku-sei I'm not sure whether your issue has the same cause as mine.

@gaku-sei
Copy link

@jjlee for me it's very fluctuating actually 😕
It will sometimes work like a charm for a couple of hours, and suddenly start hanging like crazy... I tried to disable all the extensions on vs code, and it seems to be better, but it's hard to tell now ^^

@cristianoc
Copy link
Contributor

@gaku-sei something to keep in mind is that compilation happens as-you-type, so refmt is fed unique text with half-typed words etc. That is the ideal recipe to make things less reproducible.

jjlee added a commit to jjlee/lsp-mode that referenced this issue May 10, 2020
jaredly/reason-language-server#423

In spacemacs (right now I'm on 3747afb from the develop branch), if I:

1. Apply this very hacky patch
2. Add this to my spacemacs init.el:
   dotspacemacs-additional-packages
   '(
     (lsp :location "~/dev/lsp-mode/")
     )
3. Load a ReasonML (.re) file
4. Disable merlin linting: SPC SPC merlin-mode RET
5. Ensure LSP gets loaded: SPC SPC lsp RET
6. Run this (replacing the file path with where you put the
reason-language-server binary):
    (lsp-register-client
     (make-lsp-client :new-connection (lsp-stdio-connection "/path/to/rls-linux/reason-language-server")
                      :major-modes '(reason-mode)
                      :notification-handlers (ht ("client/registerCapability" 'ignore))
                      :priority 1
                      :server-id 'reason-ls))

    (spacemacs|define-jump-handlers reason-mode)
7. SPC SPC lsp again

... then it seems to work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants