Skip to content

Commit b74b293

Browse files
ndmitchellfacebook-github-bot
authored andcommitted
Rename .span to resolve_span
Summary: Returns a ResolvedSpan, so more consistent. Plus in future we may want to return a real Span from the span function. Reviewed By: bobyangyf Differential Revision: D47194444 fbshipit-source-id: 1e178cfecde5307ed221f7034ee867aa407d1099
1 parent 857e0e5 commit b74b293

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

starlark/src/lsp/definition.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ pub(crate) mod helpers {
692692
.begin_column as u32
693693
}
694694

695-
pub(crate) fn span(&self, identifier: &str) -> ResolvedSpan {
695+
pub(crate) fn resolved_span(&self, identifier: &str) -> ResolvedSpan {
696696
*self
697697
.ranges
698698
.get(identifier)
@@ -802,8 +802,8 @@ mod test {
802802
let module = parsed.module()?;
803803

804804
let expected: Definition = IdentifierDefinition::LoadedLocation {
805-
source: parsed.span("print_click"),
806-
destination: parsed.span("print"),
805+
source: parsed.resolved_span("print_click"),
806+
destination: parsed.resolved_span("print"),
807807
path: "bar.star".to_owned(),
808808
name: "other_print".to_owned(),
809809
}
@@ -849,12 +849,12 @@ mod test {
849849
let module = parsed.module()?;
850850

851851
let expected_add = Definition::from(IdentifierDefinition::Location {
852-
source: parsed.span("add_click"),
853-
destination: parsed.span("add"),
852+
source: parsed.resolved_span("add_click"),
853+
destination: parsed.resolved_span("add"),
854854
});
855855
let expected_invalid = Definition::from(IdentifierDefinition::Location {
856-
source: parsed.span("invalid_symbol_click"),
857-
destination: parsed.span("invalid_symbol"),
856+
source: parsed.resolved_span("invalid_symbol_click"),
857+
destination: parsed.resolved_span("invalid_symbol"),
858858
});
859859

860860
assert_eq!(
@@ -912,8 +912,8 @@ mod test {
912912

913913
assert_eq!(
914914
Definition::from(IdentifierDefinition::Location {
915-
source: parsed.span("x_param"),
916-
destination: parsed.span("x")
915+
source: parsed.resolved_span("x_param"),
916+
destination: parsed.resolved_span("x")
917917
}),
918918
module.find_definition_at_location(
919919
parsed.begin_line("x_param"),
@@ -950,8 +950,8 @@ mod test {
950950

951951
assert_eq!(
952952
Definition::from(IdentifierDefinition::Location {
953-
source: parsed.span("x_var"),
954-
destination: parsed.span("x")
953+
source: parsed.resolved_span("x_var"),
954+
destination: parsed.resolved_span("x")
955955
}),
956956
module.find_definition_at_location(
957957
parsed.begin_line("x_var"),
@@ -960,8 +960,8 @@ mod test {
960960
);
961961
assert_eq!(
962962
Definition::from(IdentifierDefinition::Location {
963-
source: parsed.span("y_var1"),
964-
destination: parsed.span("y2")
963+
source: parsed.resolved_span("y_var1"),
964+
destination: parsed.resolved_span("y2")
965965
}),
966966
module.find_definition_at_location(
967967
parsed.begin_line("y_var1"),
@@ -971,8 +971,8 @@ mod test {
971971

972972
assert_eq!(
973973
Definition::from(IdentifierDefinition::Location {
974-
source: parsed.span("y_var2"),
975-
destination: parsed.span("y1")
974+
source: parsed.resolved_span("y_var2"),
975+
destination: parsed.resolved_span("y1")
976976
}),
977977
module.find_definition_at_location(
978978
parsed.begin_line("y_var2"),
@@ -981,7 +981,7 @@ mod test {
981981
);
982982
assert_eq!(
983983
Definition::from(IdentifierDefinition::Unresolved {
984-
source: parsed.span("z_var"),
984+
source: parsed.resolved_span("z_var"),
985985
name: "z".to_owned()
986986
}),
987987
module.find_definition_at_location(
@@ -1078,7 +1078,7 @@ mod test {
10781078

10791079
fn test(parsed: &FixtureWithRanges, module: &LspModule, name: &str) {
10801080
let expected = Definition::from(IdentifierDefinition::StringLiteral {
1081-
source: parsed.span(&format!("{}_click", name)),
1081+
source: parsed.resolved_span(&format!("{}_click", name)),
10821082
literal: name.to_owned(),
10831083
});
10841084
let actual = module
@@ -1129,12 +1129,12 @@ mod test {
11291129

11301130
let expected = |span_id: &str, segments: &[&str]| -> Definition {
11311131
let root_definition_location = IdentifierDefinition::Unresolved {
1132-
source: parsed.span(&format!("{}_root", span_id)),
1132+
source: parsed.resolved_span(&format!("{}_root", span_id)),
11331133
name: "foo".to_owned(),
11341134
};
11351135
if segments.len() > 1 {
11361136
DottedDefinition {
1137-
source: parsed.span(span_id),
1137+
source: parsed.resolved_span(span_id),
11381138
root_definition_location,
11391139
segments: segments.iter().map(|s| (*s).to_owned()).collect(),
11401140
}
@@ -1184,14 +1184,14 @@ mod test {
11841184

11851185
let expected = |span_id: &str, segments: &[&str]| -> Definition {
11861186
let root_definition_location = IdentifierDefinition::LoadedLocation {
1187-
source: parsed.span(&format!("{}_root", span_id)),
1188-
destination: parsed.span("root"),
1187+
source: parsed.resolved_span(&format!("{}_root", span_id)),
1188+
destination: parsed.resolved_span("root"),
11891189
path: "defs.bzl".to_owned(),
11901190
name: "foo".to_owned(),
11911191
};
11921192
if segments.len() > 1 {
11931193
DottedDefinition {
1194-
source: parsed.span(span_id),
1194+
source: parsed.resolved_span(span_id),
11951195
root_definition_location,
11961196
segments: segments.iter().map(|s| (*s).to_owned()).collect(),
11971197
}
@@ -1240,12 +1240,12 @@ mod test {
12401240

12411241
let expected = |span_id: &str, segments: &[&str]| -> Definition {
12421242
let root_definition_location = IdentifierDefinition::Location {
1243-
source: parsed.span(&format!("{}_root", span_id)),
1244-
destination: parsed.span("root"),
1243+
source: parsed.resolved_span(&format!("{}_root", span_id)),
1244+
destination: parsed.resolved_span("root"),
12451245
};
12461246
if segments.len() > 1 {
12471247
DottedDefinition {
1248-
source: parsed.span(span_id),
1248+
source: parsed.resolved_span(span_id),
12491249
root_definition_location,
12501250
segments: segments.iter().map(|s| (*s).to_owned()).collect(),
12511251
}

starlark/src/lsp/server.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,8 @@ mod test {
991991

992992
let expected_location = expected_location_link_from_spans(
993993
bar_uri.clone(),
994-
foo.span("baz_click"),
995-
bar.span("baz"),
994+
foo.resolved_span("baz_click"),
995+
bar.resolved_span("baz"),
996996
);
997997

998998
let mut server = TestServer::new()?;
@@ -1040,8 +1040,8 @@ mod test {
10401040

10411041
let expected_location = expected_location_link_from_spans(
10421042
bar_uri.clone(),
1043-
foo.span("baz_click"),
1044-
bar.span("baz"),
1043+
foo.resolved_span("baz_click"),
1044+
bar.resolved_span("baz"),
10451045
);
10461046

10471047
let mut server = TestServer::new()?;
@@ -1085,8 +1085,8 @@ mod test {
10851085

10861086
let expected_location = expected_location_link_from_spans(
10871087
bar_uri.clone(),
1088-
foo.span("baz_click"),
1089-
bar.span("baz"),
1088+
foo.resolved_span("baz_click"),
1089+
bar.resolved_span("baz"),
10901090
);
10911091

10921092
let mut server = TestServer::new()?;
@@ -1127,8 +1127,8 @@ mod test {
11271127
let foo = FixtureWithRanges::from_fixture(foo_uri.path(), &foo_contents)?;
11281128
let expected_location = expected_location_link_from_spans(
11291129
foo_uri.clone(),
1130-
foo.span("baz_click"),
1131-
foo.span("baz_loc"),
1130+
foo.resolved_span("baz_click"),
1131+
foo.resolved_span("baz_loc"),
11321132
);
11331133

11341134
let mut server = TestServer::new()?;
@@ -1171,8 +1171,8 @@ mod test {
11711171

11721172
let expected_location = expected_location_link_from_spans(
11731173
foo_uri.clone(),
1174-
foo.span("not_baz"),
1175-
foo.span("not_baz_loc"),
1174+
foo.resolved_span("not_baz"),
1175+
foo.resolved_span("not_baz_loc"),
11761176
);
11771177

11781178
let mut server = TestServer::new()?;
@@ -1217,8 +1217,8 @@ mod test {
12171217

12181218
let expected_location = expected_location_link_from_spans(
12191219
bar_uri.clone(),
1220-
foo.span("baz_click"),
1221-
bar.span("baz"),
1220+
foo.resolved_span("baz_click"),
1221+
bar.resolved_span("baz"),
12221222
);
12231223

12241224
let mut server = TestServer::new()?;
@@ -1262,8 +1262,8 @@ mod test {
12621262

12631263
let expected_location = expected_location_link_from_spans(
12641264
foo_uri.clone(),
1265-
foo.span("not_baz_loc"),
1266-
foo.span("not_baz_loc"),
1265+
foo.resolved_span("not_baz_loc"),
1266+
foo.resolved_span("not_baz_loc"),
12671267
);
12681268

12691269
let mut server = TestServer::new()?;
@@ -1311,7 +1311,7 @@ mod test {
13111311
let foo = FixtureWithRanges::from_fixture(foo_uri.path(), &foo_contents)?;
13121312

13131313
let expected_location = LocationLink {
1314-
origin_selection_range: Some(foo.span("bar_click").into()),
1314+
origin_selection_range: Some(foo.resolved_span("bar_click").into()),
13151315
target_uri: bar_uri,
13161316
target_range: Default::default(),
13171317
target_selection_range: Default::default(),
@@ -1358,7 +1358,7 @@ mod test {
13581358

13591359
let bar_contents = r#""Just <bar>a string</bar>""#;
13601360
let bar = FixtureWithRanges::from_fixture(bar_uri.path(), bar_contents)?;
1361-
let bar_range = bar.span("bar");
1361+
let bar_range = bar.resolved_span("bar");
13621362
let bar_range_str = format!(
13631363
"{}:{}:{}:{}",
13641364
bar_range.begin_line, bar_range.begin_column, bar_range.end_line, bar_range.end_column
@@ -1457,7 +1457,7 @@ mod test {
14571457
};
14581458
let expected_location = expected_location_link_from_spans(
14591459
bar_uri.clone(),
1460-
foo.span(&format!("{}_click", name)),
1460+
foo.resolved_span(&format!("{}_click", name)),
14611461
range,
14621462
);
14631463

@@ -1564,7 +1564,7 @@ mod test {
15641564
let response = goto_definition_response_location(&mut server, req_id)?;
15651565

15661566
let expected = LocationLink {
1567-
origin_selection_range: Some(foo.span("bar").into()),
1567+
origin_selection_range: Some(foo.resolved_span("bar").into()),
15681568
target_uri: bar_uri,
15691569
target_range: Default::default(),
15701570
target_selection_range: Default::default(),
@@ -1582,7 +1582,7 @@ mod test {
15821582
let response = goto_definition_response_location(&mut server, req_id)?;
15831583

15841584
let expected = LocationLink {
1585-
origin_selection_range: Some(foo.span("baz").into()),
1585+
origin_selection_range: Some(foo.resolved_span("baz").into()),
15861586
target_uri: baz_uri,
15871587
target_range: Default::default(),
15881588
target_selection_range: Default::default(),
@@ -1600,7 +1600,7 @@ mod test {
16001600
let response = goto_definition_response_location(&mut server, req_id)?;
16011601

16021602
let expected = LocationLink {
1603-
origin_selection_range: Some(foo.span("dir1").into()),
1603+
origin_selection_range: Some(foo.resolved_span("dir1").into()),
16041604
target_uri: dir1_uri,
16051605
target_range: Default::default(),
16061606
target_selection_range: Default::default(),
@@ -1619,7 +1619,7 @@ mod test {
16191619
let response = goto_definition_response_location(&mut server, req_id)?;
16201620

16211621
let expected = LocationLink {
1622-
origin_selection_range: Some(foo.span("dir2").into()),
1622+
origin_selection_range: Some(foo.resolved_span("dir2").into()),
16231623
target_uri: dir2_uri,
16241624
target_range: Default::default(),
16251625
target_selection_range: Default::default(),
@@ -1731,8 +1731,8 @@ mod test {
17311731

17321732
let expected_n1_location = expected_location_link_from_spans(
17331733
native_uri,
1734-
foo.span("click_n1"),
1735-
native.span("n1_loc"),
1734+
foo.resolved_span("click_n1"),
1735+
native.resolved_span("n1_loc"),
17361736
);
17371737

17381738
let goto_definition = goto_definition_request(
@@ -1748,8 +1748,8 @@ mod test {
17481748

17491749
let expected_n2_location = expected_location_link_from_spans(
17501750
foo_uri.clone(),
1751-
foo.span("click_n2"),
1752-
foo.span("n2_loc"),
1751+
foo.resolved_span("click_n2"),
1752+
foo.resolved_span("n2_loc"),
17531753
);
17541754

17551755
let goto_definition = goto_definition_request(
@@ -1856,8 +1856,8 @@ mod test {
18561856
.map(|(fixture, uri, id)| {
18571857
expected_location_link_from_spans(
18581858
(*uri).clone(),
1859-
foo.span(id),
1860-
fixture.span(&format!("dest_{}", id)),
1859+
foo.resolved_span(id),
1860+
fixture.resolved_span(&format!("dest_{}", id)),
18611861
)
18621862
})
18631863
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)