Skip to content

Commit b45cd97

Browse files
kinto0meta-codesync[bot]
authored andcommitted
test find_references when config is larger than workspace folder
Summary: in this case, we should find references in the config even if the workspace folder doesn't contain these Reviewed By: connernilsen Differential Revision: D85207983 fbshipit-source-id: e9099bdfcdd5665d22e392d358e2651985d5fe5d
1 parent 7e163a7 commit b45cd97

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

pyrefly/lib/test/lsp/lsp_interaction/references.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,66 @@ fn test_references_for_usage_with_config() {
8585
interaction.shutdown();
8686
}
8787

88+
#[test]
89+
fn test_references_workspace_smaller_than_config() {
90+
let root = get_test_files_root();
91+
let root_path = root.path().join("config_with_workspace_smaller");
92+
let scope_uri = Url::from_file_path(root_path.clone()).unwrap();
93+
let mut interaction = LspInteraction::new_with_indexing_mode(IndexingMode::LazyBlocking);
94+
interaction.set_root(root_path.clone());
95+
interaction.initialize(InitializeSettings {
96+
workspace_folders: Some(vec![("test".to_owned(), scope_uri)]),
97+
configuration: Some(None),
98+
..Default::default()
99+
});
100+
101+
let core = root_path.join("core.py");
102+
let usage_in_config = root_path.join("usage_in_config.py");
103+
let usage_outside_workspace = root_path.join("subdir/usage_outside_workspace.py");
104+
105+
interaction.server.did_open("core.py");
106+
interaction.server.did_open("usage_in_config.py");
107+
108+
interaction.server.references("core.py", 6, 7, true);
109+
110+
interaction.client.expect_response(Response {
111+
id: RequestId::from(2),
112+
result: Some(serde_json::json!([
113+
{
114+
"range": {"start":{"line":5,"character":17},"end":{"character":22,"line":5}},
115+
"uri": Url::from_file_path(usage_outside_workspace.clone()).unwrap().to_string()
116+
},
117+
{
118+
"range": {"start":{"line":7,"character":0},"end":{"character":5,"line":7}},
119+
"uri": Url::from_file_path(usage_outside_workspace.clone()).unwrap().to_string()
120+
},
121+
{
122+
"range": {"start":{"line":8,"character":0},"end":{"character":5,"line":8}},
123+
"uri": Url::from_file_path(usage_outside_workspace.clone()).unwrap().to_string()
124+
},
125+
{
126+
"range": {"start":{"line":6,"character":6},"end":{"character":11,"line":6}},
127+
"uri": Url::from_file_path(core.clone()).unwrap().to_string()
128+
},
129+
{
130+
"range": {"start":{"line":5,"character":17},"end":{"character":22,"line":5}},
131+
"uri": Url::from_file_path(usage_in_config.clone()).unwrap().to_string()
132+
},
133+
{
134+
"range": {"start":{"line":7,"character":0},"end":{"character":5,"line":7}},
135+
"uri": Url::from_file_path(usage_in_config.clone()).unwrap().to_string()
136+
},
137+
{
138+
"range": {"start":{"line":8,"character":0},"end":{"character":5,"line":8}},
139+
"uri": Url::from_file_path(usage_in_config.clone()).unwrap().to_string()
140+
},
141+
])),
142+
error: None,
143+
});
144+
145+
interaction.shutdown();
146+
}
147+
88148
#[test]
89149
fn test_references_cross_file_no_config() {
90150
let root = get_test_files_root();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
7+
class Token:
8+
name = "default"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
search_path = ["."]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
from core import Token
7+
8+
Token
9+
Token.name
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
from core import Token
7+
8+
Token
9+
Token.name

0 commit comments

Comments
 (0)