jaredly / reason-language-server

A language server for reason, in reason
MIT License
659 stars 84 forks source link

textDocument/rangeFormatting always hangs? #423

Open jjlee opened 4 years ago

jjlee commented 4 years ago

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 commented 4 years ago

I'm facing the same issue, and thought it could be because of refmt, but apparently no: https://github.com/facebook/reason/issues/2549

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

jjlee commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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.