-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ruff server - A new built-in LSP for Ruff, written in Rust
#10158
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
Changes from all commits
56c1b3c
282c02a
113da96
72f7688
702a046
66e257a
6877bc0
972759d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ console_error_panic_hook = { version = "0.1.7" } | |
| console_log = { version = "1.0.0" } | ||
| countme = { version = "3.0.1" } | ||
| criterion = { version = "0.5.1", default-features = false } | ||
| crossbeam = { version = "0.8.4" } | ||
| dirs = { version = "5.0.0" } | ||
| drop_bomb = { version = "0.1.5" } | ||
| env_logger = { version = "0.10.1" } | ||
|
|
@@ -52,10 +53,14 @@ is-macro = { version = "0.3.5" } | |
| is-wsl = { version = "0.4.0" } | ||
| itertools = { version = "0.12.1" } | ||
| js-sys = { version = "0.3.67" } | ||
| jod-thread = { version = "0.1.2" } | ||
| lalrpop-util = { version = "0.20.0", default-features = false } | ||
| lexical-parse-float = { version = "0.8.0", features = ["format"] } | ||
| libc = { version = "0.2.153" } | ||
| libcst = { version = "1.1.0", default-features = false } | ||
| log = { version = "0.4.17" } | ||
| lsp-server = { version = "0.7.6" } | ||
| lsp-types = { version = "0.95.0", features = ["proposed"] } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend to use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll have to make this a follow-up issue - this would be a pretty fundamental re-write. |
||
| memchr = { version = "2.7.1" } | ||
| mimalloc = { version = "0.1.39" } | ||
| natord = { version = "1.0.9" } | ||
|
|
@@ -97,6 +102,7 @@ toml = { version = "0.8.9" } | |
| tracing = { version = "0.1.40" } | ||
| tracing-indicatif = { version = "0.3.6" } | ||
| tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
| tracing-tree = { version = "0.2.4" } | ||
| typed-arena = { version = "2.0.2" } | ||
| unic-ucd-category = { version = "0.9" } | ||
| unicode-ident = { version = "1.0.12" } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| use crate::ExitStatus; | ||
| use anyhow::Result; | ||
| use ruff_linter::logging::LogLevel; | ||
| use ruff_server::Server; | ||
| use tracing::{level_filters::LevelFilter, metadata::Level, subscriber::Interest, Metadata}; | ||
| use tracing_subscriber::{ | ||
| layer::{Context, Filter, SubscriberExt}, | ||
| Layer, Registry, | ||
| }; | ||
| use tracing_tree::time::Uptime; | ||
|
|
||
| pub(crate) fn run_server(log_level: LogLevel) -> Result<ExitStatus> { | ||
| let trace_level = if log_level == LogLevel::Verbose { | ||
| Level::TRACE | ||
| } else { | ||
| Level::DEBUG | ||
| }; | ||
|
|
||
| let subscriber = Registry::default().with( | ||
| tracing_tree::HierarchicalLayer::default() | ||
| .with_indent_lines(true) | ||
| .with_indent_amount(2) | ||
| .with_bracketed_fields(true) | ||
| .with_targets(true) | ||
| .with_writer(|| Box::new(std::io::stderr())) | ||
| .with_timer(Uptime::default()) | ||
| .with_filter(LoggingFilter { trace_level }), | ||
| ); | ||
|
|
||
| tracing::subscriber::set_global_default(subscriber)?; | ||
|
|
||
| let server = Server::new()?; | ||
|
|
||
| server.run().map(|()| ExitStatus::Success) | ||
| } | ||
|
|
||
| struct LoggingFilter { | ||
| trace_level: Level, | ||
| } | ||
|
|
||
| impl LoggingFilter { | ||
| fn is_enabled(&self, meta: &Metadata<'_>) -> bool { | ||
| let filter = if meta.target().starts_with("ruff") { | ||
| self.trace_level | ||
| } else { | ||
| Level::INFO | ||
| }; | ||
|
|
||
| meta.level() <= &filter | ||
| } | ||
| } | ||
|
|
||
| impl<S> Filter<S> for LoggingFilter { | ||
| fn enabled(&self, meta: &Metadata<'_>, _cx: &Context<'_, S>) -> bool { | ||
| self.is_enabled(meta) | ||
| } | ||
|
|
||
| fn callsite_enabled(&self, meta: &'static Metadata<'static>) -> Interest { | ||
| if self.is_enabled(meta) { | ||
| Interest::always() | ||
| } else { | ||
| Interest::never() | ||
| } | ||
| } | ||
|
|
||
| fn max_level_hint(&self) -> Option<LevelFilter> { | ||
| Some(LevelFilter::from_level(self.trace_level)) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.