ale icon indicating copy to clipboard operation
ale copied to clipboard

Implement comprehensive LSP debugging

Open w0rp opened this issue 6 years ago • 13 comments

ALE supports a variety of Language Server Protocol features, and they generally work pretty well, but there is one glaring issue with Language Server Protocol. How do you figure out what is going wrong or where? Every time an issue is reported, you have to ask the following questions.

  • Is this just a problem with the user's configuration?
  • Is it a problem in the user's environment?
  • Is it a bug in the server?
  • Is it actually a bug in ALE?
  • Is it all of the above?

There's no easy way to answer any of these questions, and most users have no hope of figuring it out themselves. To that end, I propose that we add support for comprehensively debugging LSP server communication, which will be disabled by default, which will print incredibly verbose information about what ALE is trying to do. We can log the following when the option is turned on.

  • Completion data that is sent to the language server.
  • Completion information that is received by a language server.
  • Positions of cursors with the lines they are on and so on for hover information, finding references, and go to definition requests.
  • When ALE tells a server that a document has changed.
  • When ALE attempts to use a server to perform some action it doesn't support.
  • Probably a whole lot more.

w0rp avatar Dec 10 '18 21:12 w0rp

Sounds neat. Right now, hie doesn't work in ale and I have no idea why while LanguageClient-neovim logged everything to a file, helping me troubleshooting the root cause.

teto avatar Dec 14 '18 00:12 teto

Yep, more debug information will help a lot of people.

w0rp avatar Dec 15 '18 10:12 w0rp

As a workaround, I was able to debug an LSP issue by using this shell script as ale_command_wrapper:

#!/bin/sh

tee "$1.in" | "$@" 2>"$1.err" | tee "$1.out"

gmacon avatar Apr 12 '19 14:04 gmacon

I'd like to be able to show the overall LSP status somewhere in my airline, so I can figure out whether I can't see errors yet because there really are no errors, or because the LSP hasn't finished reporting in yet. This is especially important for large projects in languages with slow compilation (e.g. Haskell).

masaeedu avatar Jun 07 '19 04:06 masaeedu

Unfortunately Language Server Protocol makes that impossible. I opened an issue with a suggestion that would make that possible for servers that implemented an addition to the specification: https://github.com/microsoft/language-server-protocol/issues/737

w0rp avatar Jun 08 '19 21:06 w0rp

What can people do in the meantime? I'm trying to get the new and official ocamllsp working but can't. I ran into the issue before and I thought I remember something about being able to read a log file but I'm not sure, it's just silently failing right now.

Risto-Stevcev avatar Mar 24 '20 22:03 Risto-Stevcev

Here's something I found somewhere, sorry I can't find it any more to give credit.

First, create a little wrapper shell script whose job it is to capture input, output, and stderr, and write them to files

#!/bin/bash
executable=$1
outputfile=${executable////-}  # strip out /es if executable is full path
# OK DO NOT USE THIS ACTUALLY COS TEE DOES SOME SORT OF BUFFERING OF STDIO
# WHICH WILL CAUSE SOME PROCESSES TO HANG. LIKE LINTERS.
exec tee "/tmp/$outputfile.in" | "$@" 2>"/tmp/$outputfile.err" | tee "/tmp/$outputfile.out"

save that to somewhere on your path, eg ~/.local/bin/ale-command-wrapper.sh

Then, in in .vimrc, set ale_command_wrapper:

" this allows you to debug interactions with language servers
let g:ale_command_wrapper = '~/.local/bin/ale-command-wrapper.sh'

now whenever vim spins up a language server, it'll go via the command wrapper, which will dump files into /tmp called eg /tmp/haskell-language-server.out.

hjwp avatar Mar 12 '21 12:03 hjwp

I like that suggestion as an easy way to get a log of things on Unix systems.

w0rp avatar Mar 15 '21 21:03 w0rp

for bonus points it would delete those files on exit! but my shell-fu isn't strong enough for that lol.

hjwp avatar Mar 16 '21 09:03 hjwp

~(it's actually completely broken for executables that have full paths. trying to fix)~ i tried to fix that. it works in at least one case lol

hjwp avatar Mar 17 '21 15:03 hjwp

@w0rp I've been banging my head against getting that wrapper to work reliably but shell buffering stuff is hard to wrangle.

would you be interested in a small cash subsidy for working on the LSP debugging feature "properly"?

hjwp avatar May 13 '21 16:05 hjwp

So now that https://github.com/microsoft/language-server-protocol/issues/737 is resolved as of a year and a half ago, how can one make it work with ale in order to get LSP status in the statusline?

jwodder avatar Nov 24 '23 13:11 jwodder

rust-analyzer takes forever to start up for some reason. I would like some sort of callback as well. Would really help.

coffeebe4code avatar Dec 29 '23 17:12 coffeebe4code