Skip to content

Commit d8080c6

Browse files
committed
Say which basedpython constructs a document uses, from the tree rather than from the text
`by/explainTranspilation` reports every basedpython-specific construct in a document and what each lowers to. A client that wanted this had to guess from the source text — one regex for `?.`, another for `??`, another for `data class` — and a regex cannot tell an operator from the same characters inside a string or a comment, cannot see that `?` in a type position means something else, and drifts from the language the moment a construct is added. The parser here is the one the transpiler runs, so the answer is the one the lowering is about to act on. `?.` in particular is not looked for at all: the parser records it as a flag on the access, so this reports what was written rather than what the characters resemble. `by/transpile` also takes a fragment now. A selection has no document of its own, and the alternative — writing it to a temp file and running the CLI over that — is the thing the request exists to remove; the document it names is only what routes the request to a server.
1 parent e9244e2 commit d8080c6

9 files changed

Lines changed: 328 additions & 13 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/basedpython/Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ruff_linter/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ pub use locator::Locator;
99
pub use noqa::{SuppressionKind, generate_suppression_edits};
1010
#[cfg(feature = "clap")]
1111
pub use registry::clap_completion::RuleParser;
12+
pub use rule_documentation::rule_documentation;
1213
#[cfg(feature = "clap")]
1314
pub use rule_selector::clap_completion::UnresolvedRuleSelectorParser;
14-
pub use rule_documentation::rule_documentation;
1515
pub use rule_selector::{RuleSelector, UnresolvedRuleSelector};
1616
pub use rules::pycodestyle::rules::IOError;
1717

@@ -41,8 +41,8 @@ pub mod packaging;
4141
pub mod preview;
4242
pub mod registry;
4343
mod renamer;
44-
mod rule_redirects;
4544
pub mod rule_documentation;
45+
mod rule_redirects;
4646
pub mod rule_selector;
4747
pub mod rules;
4848
pub mod settings;

crates/ty_server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ruff_diagnostics = { workspace = true }
2020
ruff_macros = { workspace = true }
2121
ruff_notebook = { workspace = true }
2222
ruff_python_ast = { workspace = true }
23+
ruff_python_parser = { workspace = true }
2324
ruff_source_file = { workspace = true }
2425
ruff_ranged_value = { workspace = true }
2526
ruff_text_size = { workspace = true }

crates/ty_server/src/server/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub(super) fn request(req: server::Request) -> Task {
9494
requests::TranspileRequestHandler::METHOD => background_document_request_task::<
9595
requests::TranspileRequestHandler,
9696
>(req, BackgroundSchedule::Worker),
97+
requests::ExplainTranspilationHandler::METHOD => background_document_request_task::<
98+
requests::ExplainTranspilationHandler,
99+
>(req, BackgroundSchedule::Worker),
97100
requests::SemanticTokensRequestHandler::METHOD => background_document_request_task::<
98101
requests::SemanticTokensRequestHandler,
99102
>(req, BackgroundSchedule::Worker),

crates/ty_server/src/server/api/requests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ mod code_action;
1818
mod code_lens;
1919
mod completion;
2020
mod data_flow;
21-
mod explain_rule;
22-
mod transpile;
2321
mod diagnostic;
2422
mod doc_highlights;
2523
mod document_symbols;
2624
mod execute_command;
25+
mod explain_rule;
26+
mod explain_transpilation;
2727
mod folding_range;
2828
mod goto_declaration;
2929
mod goto_definition;
@@ -41,6 +41,7 @@ mod semantic_tokens;
4141
mod semantic_tokens_range;
4242
mod shutdown;
4343
mod signature_help;
44+
mod transpile;
4445
mod type_hierarchy_subtypes;
4546
mod type_hierarchy_supertypes;
4647
mod workspace_diagnostic;
@@ -52,12 +53,12 @@ pub(super) use code_action::CodeActionRequestHandler;
5253
pub(super) use code_lens::CodeLensRequestHandler;
5354
pub(super) use completion::CompletionRequestHandler;
5455
pub(super) use data_flow::DataFlowRequestHandler;
55-
pub(super) use explain_rule::ExplainRuleHandler;
56-
pub(super) use transpile::TranspileRequestHandler;
5756
pub(super) use diagnostic::DocumentDiagnosticRequestHandler;
5857
pub(super) use doc_highlights::DocumentHighlightRequestHandler;
5958
pub(super) use document_symbols::DocumentSymbolRequestHandler;
6059
pub(super) use execute_command::ExecuteCommand;
60+
pub(super) use explain_rule::ExplainRuleHandler;
61+
pub(super) use explain_transpilation::ExplainTranspilationHandler;
6162
pub(super) use folding_range::FoldingRangeRequestHandler;
6263
pub(super) use goto_declaration::GotoDeclarationRequestHandler;
6364
pub(super) use goto_definition::GotoDefinitionRequestHandler;
@@ -75,6 +76,7 @@ pub(super) use semantic_tokens::SemanticTokensRequestHandler;
7576
pub(super) use semantic_tokens_range::SemanticTokensRangeRequestHandler;
7677
pub(super) use shutdown::ShutdownHandler;
7778
pub(super) use signature_help::SignatureHelpRequestHandler;
79+
pub(super) use transpile::TranspileRequestHandler;
7880
pub(super) use type_hierarchy_subtypes::TypeHierarchySubtypesRequestHandler;
7981
pub(super) use type_hierarchy_supertypes::TypeHierarchySupertypesRequestHandler;
8082
pub(super) use workspace_diagnostic::WorkspaceDiagnosticRequestHandler;

crates/ty_server/src/server/api/requests/explain_rule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use ty_python_semantic::default_lint_registry;
1515
use crate::server::api::traits::{
1616
BackgroundRequestHandler, RequestHandler, RetriableRequestHandler,
1717
};
18-
use crate::session::client::Client;
1918
use crate::session::SessionSnapshot;
19+
use crate::session::client::Client;
2020

2121
pub(crate) enum ExplainRuleRequest {}
2222

0 commit comments

Comments
 (0)