-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffold
textDocuments/references
implementation
commit-id:c0e7d4d8
- Loading branch information
Showing
9 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod goto_definition; | ||
pub mod references; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use lsp_types::{Location, ReferenceParams}; | ||
|
||
use crate::lang::db::AnalysisDatabase; | ||
|
||
pub fn references(_params: ReferenceParams, _db: &AnalysisDatabase) -> Option<Vec<Location>> { | ||
// TODO(mkaput): Implement this. | ||
None | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use cairo_lang_test_utils::parse_test_file::TestRunnerResult; | ||
use cairo_lang_utils::ordered_hash_map::OrderedHashMap; | ||
use lsp_types::{ | ||
ClientCapabilities, ReferenceClientCapabilities, ReferenceContext, ReferenceParams, | ||
TextDocumentClientCapabilities, TextDocumentPositionParams, lsp_request, | ||
}; | ||
|
||
use crate::support::cursor::{peek_caret, peek_selection}; | ||
use crate::support::{cursors, sandbox}; | ||
|
||
cairo_lang_test_utils::test_file_test!( | ||
references, | ||
"tests/test_data/references", | ||
{ | ||
fns: "fns.txt", | ||
}, | ||
test_references | ||
); | ||
|
||
fn caps(base: ClientCapabilities) -> ClientCapabilities { | ||
ClientCapabilities { | ||
text_document: base.text_document.or_else(Default::default).map(|it| { | ||
TextDocumentClientCapabilities { | ||
references: Some(ReferenceClientCapabilities { dynamic_registration: Some(false) }), | ||
..it | ||
} | ||
}), | ||
..base | ||
} | ||
} | ||
|
||
fn test_references( | ||
inputs: &OrderedHashMap<String, String>, | ||
args: &OrderedHashMap<String, String>, | ||
) -> TestRunnerResult { | ||
let (cairo, cursors) = cursors(&inputs["cairo_code"]); | ||
|
||
let mut ls = sandbox! { | ||
files { | ||
"cairo_project.toml" => inputs["cairo_project.toml"].clone(), | ||
"src/lib.cairo" => cairo.clone(), | ||
} | ||
client_capabilities = caps; | ||
}; | ||
|
||
ls.open_all_cairo_files_and_wait_for_project_update(); | ||
|
||
let mut outputs = OrderedHashMap::default(); | ||
for (n, position) in cursors.carets().into_iter().enumerate() { | ||
let mut report = String::new(); | ||
report.push_str(&peek_caret(&cairo, position)); | ||
|
||
let params = ReferenceParams { | ||
text_document_position: TextDocumentPositionParams { | ||
text_document: ls.doc_id("src/lib.cairo"), | ||
position, | ||
}, | ||
context: ReferenceContext { | ||
include_declaration: args["include_declaration"] == "true", | ||
}, | ||
work_done_progress_params: Default::default(), | ||
partial_result_params: Default::default(), | ||
}; | ||
let response = ls.send_request::<lsp_request!("textDocument/references")>(params); | ||
|
||
if let Some(mut locations) = response { | ||
// LS does not guarantee any order of the results. | ||
locations | ||
.sort_by_key(|loc| (loc.uri.as_str().to_owned(), loc.range.start, loc.range.end)); | ||
|
||
report.push_str("---"); | ||
for location in locations { | ||
report.push('\n'); | ||
report.push_str(&peek_selection(&cairo, &location.range)); | ||
} | ||
} else { | ||
report.push_str("none response") | ||
} | ||
|
||
outputs.insert(format!("References #{n}"), report); | ||
} | ||
TestRunnerResult::success(outputs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! > Test references of function. | ||
|
||
//! > test_runner_name | ||
test_references(include_declaration: false) | ||
|
||
//! > cairo_project.toml | ||
[crate_roots] | ||
hello = "src" | ||
|
||
[config.global] | ||
edition = "2024_07" | ||
|
||
//! > cairo_code | ||
fn pow<caret>2(x: felt252) -> felt252 { x * x } | ||
|
||
fn main() { | ||
let x = po<caret>w2(2) + pow2(3); | ||
} | ||
|
||
//! > References #0 | ||
fn pow<caret>2(x: felt252) -> felt252 { x * x } | ||
none response | ||
|
||
//! > References #1 | ||
let x = po<caret>w2(2) + pow2(3); | ||
none response | ||
|
||
//! > ========================================================================== | ||
|
||
//! > Test references of function including declaration. | ||
|
||
//! > test_runner_name | ||
test_references(include_declaration: true) | ||
|
||
//! > cairo_project.toml | ||
[crate_roots] | ||
hello = "src" | ||
|
||
[config.global] | ||
edition = "2024_07" | ||
|
||
//! > cairo_code | ||
fn pow<caret>2(x: felt252) -> felt252 { x * x } | ||
|
||
fn main() { | ||
let x = po<caret>w2(2) + pow2(3); | ||
} | ||
|
||
//! > References #0 | ||
fn pow<caret>2(x: felt252) -> felt252 { x * x } | ||
none response | ||
|
||
//! > References #1 | ||
let x = po<caret>w2(2) + pow2(3); | ||
none response |