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

Server log messages should use window/logMessage #10968

Closed
dhruvmanila opened this issue Apr 16, 2024 · 3 comments · Fixed by #11747
Closed

Server log messages should use window/logMessage #10968

dhruvmanila opened this issue Apr 16, 2024 · 3 comments · Fixed by #11747
Assignees
Labels
server Related to the LSP server

Comments

@dhruvmanila
Copy link
Member

Currently, the server uses the tracing module for log messages which sends everything to stderr. This gets picked up by the client and is added to the log messages at different level regardless of the level used in the server. This level is set by the client.

Here's what VS Code shows:

2024-04-16 12:00:50.229 [info] ┐ruff_server::server::api::notifications::did_change::run{file=file:///Users/dhruv/playground/python/animation.py}
┘
2024-04-16 11:59:47.905 [info]    0.101369s ERROR ruff_server::session The following error occurred when trying to find a configuration file at `/Users/dhruv/playground/python`:
No pyproject.toml/ruff.toml/.ruff.toml file was found
   0.101425s ERROR ruff_server::session Falling back to default configuration for `/Users/dhruv/playground/python`

Here's what Neovim shows:

[START][2024-04-16 12:06:02] LSP logging initiated
[ERROR][2024-04-16 12:06:02] .../vim/lsp/rpc.lua:789	"rpc"	"/Users/dhruv/work/astral/ruff-test/target/debug/ruff"	"stderr"	"   0.001027s DEBUG ruff_server::server No workspace(s) were provided during initialization. Using the current working directory as a default workspace...\n"
[ERROR][2024-04-16 12:06:02] .../vim/lsp/rpc.lua:789	"rpc"	"/Users/dhruv/work/astral/ruff-test/target/debug/ruff"	"stderr"	"   0.041356s ERROR ruff_server::session The following error occurred when trying to find a configuration file at `/Users/dhruv/playground/python`:\nNo pyproject.toml/ruff.toml/.ruff.toml file was found\n   0.041386s ERROR ruff_server::session Falling back to default configuration for `/Users/dhruv/playground/python`\n"
[ERROR][2024-04-16 12:06:02] .../vim/lsp/rpc.lua:789	"rpc"	"/Users/dhruv/work/astral/ruff-test/target/debug/ruff"	"stderr"	"   0.044606s WARN ruff_server::server LSP client does not support dynamic capability registration - automatic configuration reloading will not be available.\n┐ruff_server::server::api::notifications::did_open::run{file=file:///Users/dhruv/playground/python/errors.py}\n┘\n"

This is not a high priority. We would need to look at all the messages using tracing and convert most of them to use the notification request instead.

@dhruvmanila dhruvmanila added the server Related to the LSP server label Apr 16, 2024
@dhruvmanila
Copy link
Member Author

cc @snowsignal

@snowsignal snowsignal self-assigned this Apr 16, 2024
@snowsignal
Copy link
Member

Thanks for opening an issue for this @dhruvmanila

@snowsignal
Copy link
Member

We decided to continue using stderr for now. I'll keep this issue open to track the tracing rewrite.

snowsignal added a commit that referenced this issue Jun 11, 2024
… with options to log to a file (#11747)

## Summary

Fixes #10968.
Fixes #11545.

The server's tracing system has been rewritten from the ground up. The
server now has trace level and log level settings which restrict the
tracing events and spans that get logged.

* A `logLevel` setting has been added, which lets a user set the log
level. By default, it is set to `"info"`.
* A `logFile` setting has also been added, which lets the user supply an
optional file to send tracing output (it does not have to exist as a
file yet). By default, if this is unset, tracing output will be sent to
`stderr`.
* A `$/setTrace` handler has also been added, and we also set the trace
level from the initialization options. For editors without direct
support for tracing, the environment variable `RUFF_TRACE` can override
the trace level.
* Small changes have been made to how we display tracing output. We no
longer use `tracing-tree`, and instead use
`tracing_subscriber::fmt::Layer` to format output. Thread names are now
included in traces, and I've made some adjustment to thread worker names
to be more useful.

## Test Plan

In VS Code, with `ruff.trace.server` set to its default value, no logs
from Ruff should appear.

After changing `ruff.trace.server` to either `messages` or `verbose`,
you should see log messages at `info` level or higher appear in Ruff's
output:
<img width="1005" alt="Screenshot 2024-06-10 at 10 35 04 AM"
src="https://github.com/astral-sh/ruff/assets/19577865/6050d107-9815-4bd2-96d0-e86f096a57f5">

In Helix, by default, no logs from Ruff should appear.

To set the trace level in Helix, you'll need to modify your language
configuration as follows:
```toml
[language-server.ruff]
command = "/Users/jane/astral/ruff/target/debug/ruff"
args = ["server", "--preview"]
environment = { "RUFF_TRACE" = "messages" }
```

After doing this, logs of `info` level or higher should be visible in
Helix:
<img width="1216" alt="Screenshot 2024-06-10 at 10 39 26 AM"
src="https://github.com/astral-sh/ruff/assets/19577865/8ff88692-d3f7-4fd1-941e-86fb338fcdcc">

You can use `:log-open` to quickly open the Helix log file.

In Neovim, by default, no logs from Ruff should appear.

To set the trace level in Neovim, you'll need to modify your
configuration as follows:
```lua
require('lspconfig').ruff.setup {
  cmd = {"/path/to/debug/executable", "server", "--preview"},
  cmd_env = { RUFF_TRACE = "messages" }
}
```

You should see logs appear in `:LspLog` that look like the following:
<img width="1490" alt="Screenshot 2024-06-11 at 11 24 01 AM"
src="https://github.com/astral-sh/ruff/assets/19577865/576cd5fa-03cf-477a-b879-b29a9a1200ff">

You can adjust `logLevel` and `logFile` in `settings`:
```lua
require('lspconfig').ruff.setup {
  cmd = {"/path/to/debug/executable", "server", "--preview"},
  cmd_env = { RUFF_TRACE = "messages" },
  settings = {
    logLevel = "debug",
    logFile = "your/log/file/path/log.txt"
  }
}
```

The `logLevel` and `logFile` can also be set in Helix like so:
```toml
[language-server.ruff.config.settings]
logLevel = "debug"
logFile = "your/log/file/path/log.txt"
```

Even if this log file does not exist, it should now be created and
written to after running the server:

<img width="1148" alt="Screenshot 2024-06-10 at 10 43 44 AM"
src="https://github.com/astral-sh/ruff/assets/19577865/ab533cf7-d5ac-4178-97f1-e56da17450dd">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server
Projects
None yet
2 participants