mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Switch to Rust 2024 edition (#18129)
This commit is contained in:
parent
e67b35743a
commit
9ae698fe30
1082 changed files with 4211 additions and 3300 deletions
|
@ -1,5 +1,5 @@
|
|||
use super::notebook;
|
||||
use super::PositionEncoding;
|
||||
use super::notebook;
|
||||
use lsp_types as types;
|
||||
use ruff_notebook::NotebookIndex;
|
||||
use ruff_source_file::LineIndex;
|
||||
|
@ -13,7 +13,7 @@ pub(crate) struct NotebookRange {
|
|||
|
||||
pub(crate) trait RangeExt {
|
||||
fn to_text_range(&self, text: &str, index: &LineIndex, encoding: PositionEncoding)
|
||||
-> TextRange;
|
||||
-> TextRange;
|
||||
}
|
||||
|
||||
pub(crate) trait ToRangeExt {
|
||||
|
|
|
@ -82,9 +82,11 @@ impl TextDocument {
|
|||
new_version: DocumentVersion,
|
||||
encoding: PositionEncoding,
|
||||
) {
|
||||
if let [lsp_types::TextDocumentContentChangeEvent {
|
||||
range: None, text, ..
|
||||
}] = changes.as_slice()
|
||||
if let [
|
||||
lsp_types::TextDocumentContentChangeEvent {
|
||||
range: None, text, ..
|
||||
},
|
||||
] = changes.as_slice()
|
||||
{
|
||||
tracing::debug!("Fast path - replacing entire document");
|
||||
self.modify(|contents, version| {
|
||||
|
|
|
@ -3,16 +3,16 @@ use std::borrow::Cow;
|
|||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::{
|
||||
PositionEncoding,
|
||||
edit::{Replacement, ToRangeExt},
|
||||
resolve::is_document_excluded_for_linting,
|
||||
session::DocumentQuery,
|
||||
PositionEncoding,
|
||||
};
|
||||
use ruff_linter::package::PackageRoot;
|
||||
use ruff_linter::{
|
||||
linter::FixerResult,
|
||||
packaging::detect_package_root,
|
||||
settings::{flags, LinterSettings},
|
||||
settings::{LinterSettings, flags},
|
||||
};
|
||||
use ruff_notebook::SourceValue;
|
||||
use ruff_source_file::LineIndex;
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::path::Path;
|
|||
|
||||
use ruff_formatter::PrintedRange;
|
||||
use ruff_python_ast::PySourceType;
|
||||
use ruff_python_formatter::{format_module_source, FormatModuleError};
|
||||
use ruff_python_formatter::{FormatModuleError, format_module_source};
|
||||
use ruff_text_size::TextRange;
|
||||
use ruff_workspace::FormatterSettings;
|
||||
|
||||
|
@ -73,8 +73,8 @@ mod tests {
|
|||
use ruff_text_size::{TextRange, TextSize};
|
||||
use ruff_workspace::FormatterSettings;
|
||||
|
||||
use crate::format::{format, format_range};
|
||||
use crate::TextDocument;
|
||||
use crate::format::{format, format_range};
|
||||
|
||||
#[test]
|
||||
fn format_per_file_version() {
|
||||
|
|
|
@ -4,14 +4,15 @@ use rustc_hash::FxHashMap;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
DIAGNOSTIC_NAME, PositionEncoding,
|
||||
edit::{NotebookRange, ToRangeExt},
|
||||
resolve::is_document_excluded_for_linting,
|
||||
session::DocumentQuery,
|
||||
PositionEncoding, DIAGNOSTIC_NAME,
|
||||
};
|
||||
use ruff_diagnostics::{Applicability, Edit, Fix};
|
||||
use ruff_linter::{
|
||||
directives::{extract_directives, Flags},
|
||||
Locator,
|
||||
directives::{Flags, extract_directives},
|
||||
generate_noqa_edits,
|
||||
linter::check_path,
|
||||
message::{DiagnosticMessage, Message},
|
||||
|
@ -20,7 +21,6 @@ use ruff_linter::{
|
|||
registry::AsRule,
|
||||
settings::flags,
|
||||
source_kind::SourceKind,
|
||||
Locator,
|
||||
};
|
||||
use ruff_notebook::Notebook;
|
||||
use ruff_python_codegen::Stylist;
|
||||
|
|
|
@ -9,9 +9,9 @@ use serde::Deserialize;
|
|||
use std::{path::PathBuf, str::FromStr, sync::Arc};
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing_subscriber::{
|
||||
Layer,
|
||||
fmt::{format::FmtSpan, time::ChronoLocal, writer::BoxMakeWriter},
|
||||
layer::SubscriberExt,
|
||||
Layer,
|
||||
};
|
||||
|
||||
pub(crate) fn init_logging(log_level: LogLevel, log_file: Option<&std::path::Path>) {
|
||||
|
|
|
@ -26,13 +26,13 @@ use types::WorkspaceFoldersServerCapabilities;
|
|||
|
||||
use self::connection::Connection;
|
||||
use self::connection::ConnectionInitializer;
|
||||
use self::schedule::event_loop_thread;
|
||||
use self::schedule::Scheduler;
|
||||
use self::schedule::Task;
|
||||
use self::schedule::event_loop_thread;
|
||||
use crate::PositionEncoding;
|
||||
use crate::session::AllSettings;
|
||||
use crate::session::Session;
|
||||
use crate::workspace::Workspaces;
|
||||
use crate::PositionEncoding;
|
||||
|
||||
mod api;
|
||||
mod client;
|
||||
|
@ -248,10 +248,14 @@ impl Server {
|
|||
if let Err(err) = scheduler
|
||||
.request::<lsp_types::request::RegisterCapability>(params, response_handler)
|
||||
{
|
||||
tracing::error!("An error occurred when trying to register the configuration file watcher: {err}");
|
||||
tracing::error!(
|
||||
"An error occurred when trying to register the configuration file watcher: {err}"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
tracing::warn!("LSP client does not support dynamic capability registration - automatic configuration reloading will not be available.");
|
||||
tracing::warn!(
|
||||
"LSP client does not support dynamic capability registration - automatic configuration reloading will not be available."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use requests as request;
|
|||
|
||||
use self::traits::{NotificationHandler, RequestHandler};
|
||||
|
||||
use super::{client::Responder, schedule::BackgroundSchedule, Result};
|
||||
use super::{Result, client::Responder, schedule::BackgroundSchedule};
|
||||
|
||||
/// Defines the `document_url` method for implementers of [`traits::Notification`] and [`traits::Request`],
|
||||
/// given the parameter type used by the implementer.
|
||||
|
@ -96,7 +96,9 @@ pub(super) fn notification<'a>(notif: server::Notification) -> Task<'a> {
|
|||
}
|
||||
.unwrap_or_else(|err| {
|
||||
tracing::error!("Encountered error when routing notification: {err}");
|
||||
show_err_msg!("Ruff failed to handle a notification from the editor. Check the logs for more details.");
|
||||
show_err_msg!(
|
||||
"Ruff failed to handle a notification from the editor. Check the logs for more details."
|
||||
);
|
||||
Task::nothing()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_types as types;
|
||||
use lsp_types::notification as notif;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_server::ErrorCode;
|
||||
use lsp_types as types;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_types as types;
|
||||
use lsp_types::notification as notif;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_server::ErrorCode;
|
||||
use lsp_types as types;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::schedule::Task;
|
||||
use crate::server::Result;
|
||||
use crate::session::Session;
|
||||
use lsp_types as types;
|
||||
use lsp_types::notification as notif;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::session::Session;
|
||||
use lsp_types as types;
|
||||
use lsp_types::notification as notif;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::server::api::diagnostics::clear_diagnostics_for_document;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::api::diagnostics::clear_diagnostics_for_document;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_types as types;
|
||||
use lsp_types::notification as notif;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::session::Session;
|
||||
use lsp_types::notification as notif;
|
||||
use lsp_types::{self as types, NotebookDocumentIdentifier};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::session::Session;
|
||||
use crate::TextDocument;
|
||||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_types as types;
|
||||
use lsp_types::notification as notif;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::edit::NotebookDocument;
|
||||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::server::Result;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::api::diagnostics::publish_diagnostics_for_document;
|
||||
use crate::server::client::{Notifier, Requester};
|
||||
use crate::session::Session;
|
||||
use lsp_server::ErrorCode;
|
||||
use lsp_types as types;
|
||||
|
|
|
@ -3,13 +3,13 @@ use lsp_types::{self as types, request as req};
|
|||
use rustc_hash::FxHashSet;
|
||||
use types::{CodeActionKind, CodeActionOrCommand};
|
||||
|
||||
use crate::edit::WorkspaceEditTracker;
|
||||
use crate::lint::{fixes_for_diagnostics, DiagnosticFix};
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::SupportedCodeAction;
|
||||
use crate::server::{client::Notifier, Result};
|
||||
use crate::session::DocumentSnapshot;
|
||||
use crate::DIAGNOSTIC_NAME;
|
||||
use crate::edit::WorkspaceEditTracker;
|
||||
use crate::lint::{DiagnosticFix, fixes_for_diagnostics};
|
||||
use crate::server::SupportedCodeAction;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::{Result, client::Notifier};
|
||||
use crate::session::DocumentSnapshot;
|
||||
|
||||
use super::code_action_resolve::{resolve_edit_for_fix_all, resolve_edit_for_organize_imports};
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@ use lsp_types::{self as types, request as req};
|
|||
|
||||
use ruff_linter::codes::Rule;
|
||||
|
||||
use crate::PositionEncoding;
|
||||
use crate::edit::WorkspaceEditTracker;
|
||||
use crate::fix::Fixes;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::SupportedCodeAction;
|
||||
use crate::server::{client::Notifier, Result};
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::{Result, client::Notifier};
|
||||
use crate::session::{DocumentQuery, DocumentSnapshot, ResolvedClientCapabilities};
|
||||
use crate::PositionEncoding;
|
||||
|
||||
pub(crate) struct CodeActionResolve;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::server::api::diagnostics::generate_diagnostics;
|
||||
use crate::server::{client::Notifier, Result};
|
||||
use crate::server::{Result, client::Notifier};
|
||||
use crate::session::DocumentSnapshot;
|
||||
use lsp_types::{self as types, request as req};
|
||||
use types::{
|
||||
|
|
|
@ -4,12 +4,12 @@ use std::str::FromStr;
|
|||
use crate::edit::WorkspaceEditTracker;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::schedule::Task;
|
||||
use crate::server::{client, SupportedCommand};
|
||||
use crate::server::{SupportedCommand, client};
|
||||
use crate::session::Session;
|
||||
use crate::{DIAGNOSTIC_NAME, DocumentKey};
|
||||
use crate::{edit::DocumentVersion, server};
|
||||
use crate::{DocumentKey, DIAGNOSTIC_NAME};
|
||||
use lsp_server::ErrorCode;
|
||||
use lsp_types::{self as types, request as req, TextDocumentIdentifier};
|
||||
use lsp_types::{self as types, TextDocumentIdentifier, request as req};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub(crate) struct ExecuteCommand;
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::edit::{Replacement, ToRangeExt};
|
|||
use crate::fix::Fixes;
|
||||
use crate::resolve::is_document_excluded_for_formatting;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::{client::Notifier, Result};
|
||||
use crate::server::{Result, client::Notifier};
|
||||
use crate::session::{DocumentQuery, DocumentSnapshot};
|
||||
use crate::{PositionEncoding, TextDocument};
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use anyhow::Context;
|
||||
use lsp_types::{self as types, request as req, Range};
|
||||
use lsp_types::{self as types, Range, request as req};
|
||||
|
||||
use crate::edit::{RangeExt, ToRangeExt};
|
||||
use crate::resolve::is_document_excluded_for_formatting;
|
||||
use crate::server::api::LSPResult;
|
||||
use crate::server::{client::Notifier, Result};
|
||||
use crate::server::{Result, client::Notifier};
|
||||
use crate::session::{DocumentQuery, DocumentSnapshot};
|
||||
use crate::{PositionEncoding, TextDocument};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::server::{client::Notifier, Result};
|
||||
use crate::server::{Result, client::Notifier};
|
||||
use crate::session::DocumentSnapshot;
|
||||
use anyhow::Context;
|
||||
use lsp_types::{self as types, request as req};
|
||||
|
|
|
@ -4,7 +4,7 @@ use lsp_server::{Notification, RequestId};
|
|||
use rustc_hash::FxHashMap;
|
||||
use serde_json::Value;
|
||||
|
||||
use super::{schedule::Task, ClientSender};
|
||||
use super::{ClientSender, schedule::Task};
|
||||
|
||||
type ResponseBuilder<'s> = Box<dyn FnOnce(lsp_server::Response) -> Task<'s>>;
|
||||
|
||||
|
|
|
@ -124,7 +124,9 @@ impl Connection {
|
|||
lsp::Message::Notification(lsp::Notification { method, .. })
|
||||
if method == lsp_types::notification::Exit::METHOD =>
|
||||
{
|
||||
anyhow::bail!("Server received an exit notification before a shutdown request was sent. Exiting...");
|
||||
anyhow::bail!(
|
||||
"Server received an exit notification before a shutdown request was sent. Exiting..."
|
||||
);
|
||||
}
|
||||
_ => Ok(false),
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use self::{
|
|||
thread::ThreadPriority,
|
||||
};
|
||||
|
||||
use super::{client::Client, ClientSender};
|
||||
use super::{ClientSender, client::Client};
|
||||
|
||||
/// The event loop thread is actually a secondary thread that we spawn from the
|
||||
/// _actual_ main thread. This secondary thread has a larger stack size
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
use std::{
|
||||
num::NonZeroUsize,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@ pub(crate) use ruff_settings::RuffSettings;
|
|||
use crate::edit::LanguageId;
|
||||
use crate::workspace::{Workspace, Workspaces};
|
||||
use crate::{
|
||||
edit::{DocumentKey, DocumentVersion, NotebookDocument},
|
||||
PositionEncoding, TextDocument,
|
||||
edit::{DocumentKey, DocumentVersion, NotebookDocument},
|
||||
};
|
||||
|
||||
use super::{settings::ResolvedClientSettings, ClientSettings};
|
||||
use super::{ClientSettings, settings::ResolvedClientSettings};
|
||||
|
||||
mod ruff_settings;
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use anyhow::Context;
|
||||
use ignore::{WalkBuilder, WalkState};
|
||||
|
||||
use ruff_linter::settings::types::GlobPath;
|
||||
use ruff_linter::{settings::types::FilePattern, settings::types::PreviewMode};
|
||||
use ruff_workspace::Settings;
|
||||
use ruff_workspace::pyproject::find_fallback_target_version;
|
||||
use ruff_workspace::resolver::match_exclusion;
|
||||
use ruff_workspace::Settings;
|
||||
use ruff_workspace::{
|
||||
configuration::{Configuration, FormatConfiguration, LintConfiguration, RuleSelection},
|
||||
pyproject::{find_user_settings_toml, settings_toml},
|
||||
|
|
|
@ -6,9 +6,9 @@ use serde::Deserialize;
|
|||
use serde_json::{Map, Value};
|
||||
use thiserror::Error;
|
||||
|
||||
use ruff_linter::RuleSelector;
|
||||
use ruff_linter::line_width::LineLength;
|
||||
use ruff_linter::rule_selector::ParseError;
|
||||
use ruff_linter::RuleSelector;
|
||||
use ruff_workspace::options::Options;
|
||||
|
||||
/// Maps a workspace URI to its associated client settings. Used during server initialization.
|
||||
|
@ -441,11 +441,7 @@ impl ResolvedClientSettings {
|
|||
*contains_invalid_settings = true;
|
||||
tracing::error!("Unknown rule selectors found in `{key}`: {unknown:?}");
|
||||
}
|
||||
if known.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(known)
|
||||
}
|
||||
if known.is_empty() { None } else { Some(known) }
|
||||
}
|
||||
|
||||
/// Attempts to resolve a setting using a list of available client settings as sources.
|
||||
|
|
|
@ -3,8 +3,8 @@ use std::ops::Deref;
|
|||
use lsp_types::{Url, WorkspaceFolder};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::session::WorkspaceSettingsMap;
|
||||
use crate::ClientSettings;
|
||||
use crate::session::WorkspaceSettingsMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Workspaces(Vec<Workspace>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue