Skip to content

Commit ccc39ec

Browse files
author
UnboundVariable
committed
Merge branch 'main' into references
* main: (28 commits) [ty] highlight the argument in `static_assert` error messages (astral-sh#19426) [ty] Infer single-valuedness for enums based on `int`/`str` (astral-sh#19510) [ty] Restructure submodule query around `File` dependency [ty] Make `Module` a Salsa ingredient [ty] Reachability analysis for `isinstance(…)` branches (astral-sh#19503) [ty] Normalize single-member enums to their instance type (astral-sh#19502) [ty] Invert `ty_ide` and `ty_project` dependency (astral-sh#19501) [ty] Implement mock language server for testing (astral-sh#19391) [ty] Detect enums if metaclass is a subtype of EnumType/EnumMeta (astral-sh#19481) [ty] perform type narrowing for places marked `global` too (astral-sh#19381) [ty] Use `ThinVec` for sub segments in `PlaceExpr` (astral-sh#19470) [ty] Splat variadic arguments into parameter list (astral-sh#18996) [`flake8-pyi`] Skip fix if all `Union` members are `None` (`PYI016`) (astral-sh#19416) Skip notebook with errors in ecosystem check (astral-sh#19491) [ty] Consistent use of American english (in rules) (astral-sh#19488) [ty] Support iterating over enums (astral-sh#19486) Fix panic for illegal `Literal[…]` annotations with inner subscript expressions (astral-sh#19489) Move fix suggestion to subdiagnostic (astral-sh#19464) [ty] Implement non-stdlib stub mapping for classes and functions (astral-sh#19471) [ty] Disallow illegal uses of `ClassVar` (astral-sh#19483) ... # Conflicts: # crates/ty_ide/src/goto.rs
2 parents ed72129 + 88bd829 commit ccc39ec

File tree

107 files changed

+5488
-1066
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+5488
-1066
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ jobs:
143143
env:
144144
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
145145
run: |
146-
if git diff --quiet "${MERGE_BASE}...HEAD" -- ':**' \
147-
':!**/*.md' \
148-
':crates/ty_python_semantic/resources/mdtest/**/*.md' \
146+
# NOTE: Do not exclude all Markdown files here, but rather use
147+
# specific exclude patterns like 'docs/**'), because tests for
148+
# 'ty' are written in Markdown.
149+
if git diff --quiet "${MERGE_BASE}...HEAD" -- \
149150
':!docs/**' \
150151
':!assets/**' \
151-
':.github/workflows/ci.yaml' \
152152
; then
153153
echo "changed=false" >> "$GITHUB_OUTPUT"
154154
else

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ strum_macros = { version = "0.27.0" }
166166
syn = { version = "2.0.55" }
167167
tempfile = { version = "3.9.0" }
168168
test-case = { version = "3.3.1" }
169+
thin-vec = { version = "0.2.14" }
169170
thiserror = { version = "2.0.0" }
170171
tikv-jemallocator = { version = "0.6.0" }
171172
toml = { version = "0.9.0" }

crates/ruff/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl LintCacheData {
454454
CacheMessage {
455455
rule,
456456
body: msg.body().to_string(),
457-
suggestion: msg.suggestion().map(ToString::to_string),
457+
suggestion: msg.first_help_text().map(ToString::to_string),
458458
range: msg.expect_range(),
459459
parent: msg.parent(),
460460
fix: msg.fix().cloned(),

crates/ruff_db/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ ty_static = { workspace = true }
2525
anstyle = { workspace = true }
2626
arc-swap = { workspace = true }
2727
camino = { workspace = true }
28-
countme = { workspace = true }
2928
dashmap = { workspace = true }
3029
dunce = { workspace = true }
3130
filetime = { workspace = true }
@@ -59,6 +58,11 @@ tempfile = { workspace = true }
5958
cache = ["ruff_cache"]
6059
junit = ["dep:quick-junit"]
6160
os = ["ignore", "dep:etcetera"]
62-
serde = ["camino/serde1", "dep:serde", "dep:serde_json", "ruff_diagnostics/serde"]
61+
serde = [
62+
"camino/serde1",
63+
"dep:serde",
64+
"dep:serde_json",
65+
"ruff_diagnostics/serde",
66+
]
6367
# Exposes testing utilities.
6468
testing = ["tracing-subscriber"]

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ impl Diagnostic {
122122
/// directly. If callers want or need to avoid cloning the diagnostic
123123
/// message, then they can also pass a `DiagnosticMessage` directly.
124124
pub fn info<'a>(&mut self, message: impl IntoDiagnosticMessage + 'a) {
125-
self.sub(SubDiagnostic::new(Severity::Info, message));
125+
self.sub(SubDiagnostic::new(SubDiagnosticSeverity::Info, message));
126+
}
127+
128+
/// Adds a "help" sub-diagnostic with the given message.
129+
///
130+
/// See the closely related [`Diagnostic::info`] method for more details.
131+
pub fn help<'a>(&mut self, message: impl IntoDiagnosticMessage + 'a) {
132+
self.sub(SubDiagnostic::new(SubDiagnosticSeverity::Help, message));
126133
}
127134

128135
/// Adds a "sub" diagnostic to this diagnostic.
@@ -377,9 +384,15 @@ impl Diagnostic {
377384
self.primary_message()
378385
}
379386

380-
/// Returns the fix suggestion for the violation.
381-
pub fn suggestion(&self) -> Option<&str> {
382-
self.primary_annotation()?.get_message()
387+
/// Returns the message of the first sub-diagnostic with a `Help` severity.
388+
///
389+
/// Note that this is used as the fix title/suggestion for some of Ruff's output formats, but in
390+
/// general this is not the guaranteed meaning of such a message.
391+
pub fn first_help_text(&self) -> Option<&str> {
392+
self.sub_diagnostics()
393+
.iter()
394+
.find(|sub| matches!(sub.inner.severity, SubDiagnosticSeverity::Help))
395+
.map(|sub| sub.inner.message.as_str())
383396
}
384397

385398
/// Returns the URL for the rule documentation, if it exists.
@@ -565,7 +578,10 @@ impl SubDiagnostic {
565578
/// Callers can pass anything that implements `std::fmt::Display`
566579
/// directly. If callers want or need to avoid cloning the diagnostic
567580
/// message, then they can also pass a `DiagnosticMessage` directly.
568-
pub fn new<'a>(severity: Severity, message: impl IntoDiagnosticMessage + 'a) -> SubDiagnostic {
581+
pub fn new<'a>(
582+
severity: SubDiagnosticSeverity,
583+
message: impl IntoDiagnosticMessage + 'a,
584+
) -> SubDiagnostic {
569585
let inner = Box::new(SubDiagnosticInner {
570586
severity,
571587
message: message.into_diagnostic_message(),
@@ -643,7 +659,7 @@ impl SubDiagnostic {
643659

644660
#[derive(Debug, Clone, Eq, PartialEq, get_size2::GetSize)]
645661
struct SubDiagnosticInner {
646-
severity: Severity,
662+
severity: SubDiagnosticSeverity,
647663
message: DiagnosticMessage,
648664
annotations: Vec<Annotation>,
649665
}
@@ -1170,6 +1186,30 @@ impl Severity {
11701186
}
11711187
}
11721188

1189+
/// Like [`Severity`] but exclusively for sub-diagnostics.
1190+
///
1191+
/// This supports an additional `Help` severity that may not be needed in main diagnostics.
1192+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, get_size2::GetSize)]
1193+
pub enum SubDiagnosticSeverity {
1194+
Help,
1195+
Info,
1196+
Warning,
1197+
Error,
1198+
Fatal,
1199+
}
1200+
1201+
impl SubDiagnosticSeverity {
1202+
fn to_annotate(self) -> AnnotateLevel {
1203+
match self {
1204+
SubDiagnosticSeverity::Help => AnnotateLevel::Help,
1205+
SubDiagnosticSeverity::Info => AnnotateLevel::Info,
1206+
SubDiagnosticSeverity::Warning => AnnotateLevel::Warning,
1207+
SubDiagnosticSeverity::Error => AnnotateLevel::Error,
1208+
SubDiagnosticSeverity::Fatal => AnnotateLevel::Error,
1209+
}
1210+
}
1211+
}
1212+
11731213
/// Configuration for rendering diagnostics.
11741214
#[derive(Clone, Debug)]
11751215
pub struct DisplayDiagnosticConfig {

0 commit comments

Comments
 (0)