Combine Text alias rename with guarded diagram navigation
This commit is contained in:
@@ -220,12 +220,22 @@ pub struct ReferenceRow {
|
||||
pub evidence: Evidence,
|
||||
}
|
||||
|
||||
/// Exact lexical occurrence that answered the query, independent of row limits.
|
||||
/// The optional @ marker is separate from the alias; comments between them do
|
||||
/// not become part of either hit.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Origin {
|
||||
pub span: Span,
|
||||
pub marker: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Results {
|
||||
pub stamp: QueryStamp,
|
||||
pub action: Action,
|
||||
pub origin_path: String,
|
||||
pub origin_offset: usize,
|
||||
pub origin: Option<Origin>,
|
||||
pub alias: Option<String>,
|
||||
pub scope: Scope,
|
||||
pub disposition: Disposition,
|
||||
@@ -823,10 +833,28 @@ impl Snapshot {
|
||||
.ok_or(QueryError::MissingFile)?;
|
||||
let index = self.index()?;
|
||||
let hit = index.hit(file, query.byte_offset)?;
|
||||
let alias = match hit {
|
||||
Some(symbols::Hit::Definition(handle)) => Some(index.definition(handle)?.alias),
|
||||
Some(symbols::Hit::Reference(handle)) => Some(index.reference(handle)?.alias),
|
||||
None => None,
|
||||
let (alias, origin) = match hit {
|
||||
Some(symbols::Hit::Definition(handle)) => {
|
||||
let definition = index.definition(handle)?;
|
||||
(
|
||||
Some(definition.alias),
|
||||
Some(Origin {
|
||||
span: definition.alias_location.span,
|
||||
marker: None,
|
||||
}),
|
||||
)
|
||||
}
|
||||
Some(symbols::Hit::Reference(handle)) => {
|
||||
let reference = index.reference(handle)?;
|
||||
(
|
||||
Some(reference.alias),
|
||||
Some(Origin {
|
||||
span: reference.alias_location.span,
|
||||
marker: Some(reference.at.span),
|
||||
}),
|
||||
)
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
let mut budget = RowBudget {
|
||||
rows: self.limits.result_rows,
|
||||
@@ -840,6 +868,7 @@ impl Snapshot {
|
||||
action: query.action,
|
||||
origin_path: query.path.to_owned(),
|
||||
origin_offset: query.byte_offset,
|
||||
origin,
|
||||
alias: alias.map(str::to_owned),
|
||||
scope: self.scope.clone(),
|
||||
disposition: Disposition::NoSymbol,
|
||||
|
||||
@@ -107,6 +107,65 @@ fn reference_offset(fixture: &Fixture) -> usize {
|
||||
fixture.text("links.arcadia").find("source @").unwrap() + "source ".len()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn origin_keeps_exact_hit_when_display_rows_are_omitted() {
|
||||
let mut fixture = Fixture::standard();
|
||||
fixture
|
||||
.text_mut("links.arcadia")
|
||||
.push_str("// no @pump hit\r\n@pump @pump @ // intervening @pump\r\n pump");
|
||||
let source = fixture.text("links.arcadia");
|
||||
let start = source.rfind("pump").unwrap();
|
||||
let marker = source.rfind("@ // intervening").unwrap();
|
||||
let limits = Limits {
|
||||
result_rows: 0,
|
||||
..Limits::default()
|
||||
};
|
||||
let snapshot = fixture.snapshot(None, false, limits);
|
||||
let expected = Some(Origin {
|
||||
span: Span {
|
||||
start,
|
||||
end: start + 4,
|
||||
},
|
||||
marker: Some(Span {
|
||||
start: marker,
|
||||
end: marker + 1,
|
||||
}),
|
||||
});
|
||||
for offset in [start, start + 3, marker] {
|
||||
let result = query(&snapshot, "links.arcadia", offset, Action::References);
|
||||
assert_eq!(result.origin, expected);
|
||||
assert!(result.references.is_empty());
|
||||
assert!(result.omitted_references > 2);
|
||||
}
|
||||
let comment = source.rfind("intervening @pump").unwrap() + "intervening @".len();
|
||||
assert_eq!(
|
||||
query(&snapshot, "links.arcadia", comment, Action::Definition).origin,
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
query(&snapshot, "links.arcadia", start + 4, Action::Definition).origin,
|
||||
None
|
||||
);
|
||||
let definition_source = fixture.text("模块/活動.arcadia");
|
||||
let definition_start = definition_source.find("pump").unwrap();
|
||||
assert_eq!(
|
||||
query(
|
||||
&snapshot,
|
||||
"模块/活動.arcadia",
|
||||
definition_start,
|
||||
Action::Definition
|
||||
)
|
||||
.origin,
|
||||
Some(Origin {
|
||||
span: Span {
|
||||
start: definition_start,
|
||||
end: definition_start + 4
|
||||
},
|
||||
marker: None
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_multifile_unicode_crlf_definition_and_repeated_lexical_references() {
|
||||
let fixture = Fixture::standard();
|
||||
|
||||
Reference in New Issue
Block a user