ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Replace `tracing` log functions in `ruff server` with LSP-compliant logging functions

Open snowsignal opened this issue 10 months ago • 5 comments

Summary

Closes https://github.com/astral-sh/ruff/issues/10968.

At the moment, the log level is always set to Info. Log level configuration will be implemented in a follow-up.

Test Plan

Add a series of logs, one for each level, to the definition of Server::new, after the logger is initialized: Screenshot 2024-04-26 at 4 16 25 PM

You should see the following logs in the output of the VS Code extension: Screenshot 2024-04-26 at 4 21 23 PM

snowsignal avatar Apr 26 '24 23:04 snowsignal

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

github-actions[bot] avatar Apr 26 '24 23:04 github-actions[bot]

Is there an alternate design whereby we wire up tracing to emit to the LSP client? I.e., some kind of tracing configuration that would let us continue to use tracing::info! and friends, but also emit to the client?

charliermarsh avatar Apr 27 '24 01:04 charliermarsh

@charliermarsh I think that should be possible by setting up our own subscriber that then forwards messages to the LSP.

I think the problem this approach is that it only works for ruff_server, but we will use tracing in runes too and we don't have the luxury to change all tracing calls there.

I think we need to explore an alternative approach that captures all tracing messages (subscriber) and forwards them correctly OR setup an alternative subscriber that writes e.g. to a file, although I would prefer seeing the tracing messages in vs code.

MichaReiser avatar Apr 27 '24 07:04 MichaReiser

Yeah I would prefer trying to integrate this into tracing too (for those reasons, plus it's the API I would've naturally reached for if I went to write code in the LSP as a future editor / author). @snowsignal can you give it a shot?

charliermarsh avatar Apr 27 '24 11:04 charliermarsh

@charliermarsh Sure, I'll see what I can do!

snowsignal avatar Apr 27 '24 23:04 snowsignal

This PR is really outdated, especially with the major refactors we made to server initialization. I'll re-implement this feature in a new PR that's based off of the latest main.

snowsignal avatar Jun 04 '24 23:06 snowsignal