mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Split SourceLocation
into LineColumn
and SourceLocation
(#17587)
This commit is contained in:
parent
4443f6653c
commit
1c65e0ad25
29 changed files with 695 additions and 537 deletions
|
@ -21,7 +21,7 @@ use ruff_python_formatter::{format_module_ast, pretty_comments, PyFormatContext,
|
|||
use ruff_python_index::Indexer;
|
||||
use ruff_python_parser::{parse, parse_unchecked, Mode, ParseOptions, Parsed};
|
||||
use ruff_python_trivia::CommentRanges;
|
||||
use ruff_source_file::SourceLocation;
|
||||
use ruff_source_file::{LineColumn, OneIndexed};
|
||||
use ruff_text_size::Ranged;
|
||||
use ruff_workspace::configuration::Configuration;
|
||||
use ruff_workspace::options::{FormatOptions, LintCommonOptions, LintOptions, Options};
|
||||
|
@ -61,8 +61,8 @@ export interface Diagnostic {
|
|||
pub struct ExpandedMessage {
|
||||
pub code: Option<String>,
|
||||
pub message: String,
|
||||
pub start_location: SourceLocation,
|
||||
pub end_location: SourceLocation,
|
||||
pub start_location: Location,
|
||||
pub end_location: Location,
|
||||
pub fix: Option<ExpandedFix>,
|
||||
}
|
||||
|
||||
|
@ -74,8 +74,8 @@ pub struct ExpandedFix {
|
|||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
struct ExpandedEdit {
|
||||
location: SourceLocation,
|
||||
end_location: SourceLocation,
|
||||
location: Location,
|
||||
end_location: Location,
|
||||
content: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -214,16 +214,16 @@ impl Workspace {
|
|||
}) => ExpandedMessage {
|
||||
code: Some(kind.rule().noqa_code().to_string()),
|
||||
message: kind.body,
|
||||
start_location: source_code.source_location(range.start()),
|
||||
end_location: source_code.source_location(range.end()),
|
||||
start_location: source_code.line_column(range.start()).into(),
|
||||
end_location: source_code.line_column(range.end()).into(),
|
||||
fix: fix.map(|fix| ExpandedFix {
|
||||
message: kind.suggestion,
|
||||
edits: fix
|
||||
.edits()
|
||||
.iter()
|
||||
.map(|edit| ExpandedEdit {
|
||||
location: source_code.source_location(edit.start()),
|
||||
end_location: source_code.source_location(edit.end()),
|
||||
location: source_code.line_column(edit.start()).into(),
|
||||
end_location: source_code.line_column(edit.end()).into(),
|
||||
content: edit.content().map(ToString::to_string),
|
||||
})
|
||||
.collect(),
|
||||
|
@ -233,8 +233,8 @@ impl Workspace {
|
|||
ExpandedMessage {
|
||||
code: None,
|
||||
message,
|
||||
start_location: source_code.source_location(range.start()),
|
||||
end_location: source_code.source_location(range.end()),
|
||||
start_location: source_code.line_column(range.start()).into(),
|
||||
end_location: source_code.line_column(range.end()).into(),
|
||||
fix: None,
|
||||
}
|
||||
}
|
||||
|
@ -316,3 +316,18 @@ impl<'a> ParsedModule<'a> {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct Location {
|
||||
pub row: OneIndexed,
|
||||
pub column: OneIndexed,
|
||||
}
|
||||
|
||||
impl From<LineColumn> for Location {
|
||||
fn from(value: LineColumn) -> Self {
|
||||
Self {
|
||||
row: value.line,
|
||||
column: value.column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue