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

Use window/logMessage instead of STDERR for log messages #1271

Open
radeksimko opened this issue May 2, 2023 · 0 comments
Open

Use window/logMessage instead of STDERR for log messages #1271

radeksimko opened this issue May 2, 2023 · 0 comments
Labels
enhancement New feature or request technical-debt

Comments

@radeksimko
Copy link
Member

radeksimko commented May 2, 2023

Background

Currently the server uses STDERR as the default channel for logs. This can be overridden via -log-file flag of the terraform-ls serve subcommand, to send logs to a file.

The default behaviour is however undesirable for a couple of reasons:

Using STDERR originally was mostly a pragmatic "shortcut" we took in the early versions of LS development, which felt fine given that window/logMessage is not considered mandatory for servers to implement per the spec and STDOUT is already used for LSP communication.

Concerns

There were a few concerns we didn't know how to best address (which also further supported the STDERR route at the time):

  • where do we send logs related to anything that happens prior to server setup, i.e. before initialization is finished and window/logMessage can be sent?
    • This is still an ongoing concern, but such situations and need for logging seem to be rare enough that we could only log errors and still send those to STDERR or something like that.
  • how do we decide on the log level inside the LS codebase?
    • This could be addressed either by adopting a library such as go-hclog or possibly the upcoming experimental slog package with some kind of custom adapters for LSP
  • how do we debug/log the LSP traffic itself without doubling the number of requests, i.e. without logging every e.g. textDocument/completion via window/logMessage?
    • This is still an ongoing concern, mostly dependent on various clients. The good news is that there are some relatively mature clients out there now which can do such logging on the client side.
  • Should we consider $/logTrace for anything at all? Where do we draw the line between debugging messages and server execution tracing?

We will likely have to log human-readable messages to LSP (as it accepts just string), but in the future this may change, so we should be able to take advantage of that eventually: microsoft/vscode#185904

Proposal

Explore solutions for the above ^ concerns and look into adopting window/logMessage

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_logMessage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request technical-debt
Projects
None yet
Development

No branches or pull requests

1 participant