-
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.
commit-id:db86574a
- Loading branch information
Showing
19 changed files
with
593 additions
and
546 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
use crate::goto_definition::goto_definition; | ||
use crate::support::insta::test_transform; | ||
|
||
#[test] | ||
fn enum_item_in_type() { | ||
test_transform!(goto_definition, r#" | ||
enum Foo { Bar } | ||
fn calc(foo: Fo<caret>o) {} | ||
"#, @r" | ||
<sel>enum Foo { Bar }</sel> | ||
fn calc(foo: Foo) {} | ||
"); | ||
} | ||
|
||
#[test] | ||
fn enum_item_in_expr() { | ||
test_transform!(goto_definition, r#" | ||
enum Foo { Bar } | ||
fn main() { | ||
let foo = Fo<caret>o::Bar; | ||
} | ||
"#, @r" | ||
<sel>enum Foo { Bar }</sel> | ||
fn main() { | ||
let foo = Foo::Bar; | ||
} | ||
"); | ||
} | ||
|
||
#[test] | ||
fn enum_variant_in_expr() { | ||
test_transform!(goto_definition, r#" | ||
enum Foo { Bar } | ||
fn main() { let foo = Foo::Ba<caret>r; } | ||
"#, @r" | ||
enum Foo { <sel>Bar</sel> } | ||
fn main() { let foo = Foo::Bar; } | ||
"); | ||
} | ||
|
||
#[test] | ||
fn enum_variant_in_pattern() { | ||
test_transform!(goto_definition, r#" | ||
enum Foo { Bar } | ||
fn main() { | ||
let foo = Foo::Bar; | ||
match foo { | ||
Foo::Ba<caret>r => {} | ||
} | ||
} | ||
"#, @r" | ||
enum Foo { <sel>Bar</sel> } | ||
fn main() { | ||
let foo = Foo::Bar; | ||
match foo { | ||
Foo::Bar => {} | ||
} | ||
} | ||
"); | ||
} |
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,19 @@ | ||
use crate::goto_definition::goto_definition; | ||
use crate::support::insta::test_transform; | ||
|
||
#[test] | ||
fn fn_call() { | ||
test_transform!(goto_definition, r" | ||
fn main() { fo<caret>o(); } | ||
fn foo() {} // good | ||
mod bar { | ||
fn foo() {} // bad | ||
} | ||
", @r" | ||
fn main() { foo(); } | ||
<sel>fn foo() {}</sel> // good | ||
mod bar { | ||
fn foo() {} // bad | ||
} | ||
") | ||
} |
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,11 @@ | ||
use crate::goto_definition::goto_definition; | ||
use crate::support::insta::test_transform; | ||
|
||
#[test] | ||
fn inline_macro() { | ||
test_transform!(goto_definition, r#" | ||
fn main() { | ||
prin<caret>t!("Hello, world!"); | ||
} | ||
"#, @"none response") | ||
} |
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,75 @@ | ||
use lsp_types::{ | ||
ClientCapabilities, GotoCapability, GotoDefinitionParams, GotoDefinitionResponse, | ||
TextDocumentClientCapabilities, TextDocumentPositionParams, lsp_request, | ||
}; | ||
|
||
use crate::support::cairo_project_toml::CAIRO_PROJECT_TOML_2024_07; | ||
use crate::support::cursor::render_selections; | ||
use crate::support::{cursors, sandbox}; | ||
|
||
mod enums; | ||
mod fns; | ||
mod macros; | ||
mod paths; | ||
mod structs; | ||
mod traits; | ||
mod vars; | ||
|
||
fn caps(base: ClientCapabilities) -> ClientCapabilities { | ||
ClientCapabilities { | ||
text_document: base.text_document.or_else(Default::default).map(|it| { | ||
TextDocumentClientCapabilities { | ||
definition: Some(GotoCapability { | ||
dynamic_registration: Some(false), | ||
link_support: None, | ||
}), | ||
..it | ||
} | ||
}), | ||
..base | ||
} | ||
} | ||
|
||
fn goto_definition(cairo_code: &str) -> String { | ||
let (cairo, cursors) = cursors(cairo_code); | ||
|
||
let mut ls = sandbox! { | ||
files { | ||
"cairo_project.toml" => CAIRO_PROJECT_TOML_2024_07, | ||
"src/lib.cairo" => cairo.clone(), | ||
} | ||
client_capabilities = caps; | ||
}; | ||
|
||
ls.open_all_cairo_files_and_wait_for_project_update(); | ||
|
||
assert_eq!(cursors.carets().len(), 1); | ||
let position = cursors.carets()[0]; | ||
|
||
let code_action_params = GotoDefinitionParams { | ||
text_document_position_params: TextDocumentPositionParams { | ||
text_document: ls.doc_id("src/lib.cairo"), | ||
position, | ||
}, | ||
work_done_progress_params: Default::default(), | ||
partial_result_params: Default::default(), | ||
}; | ||
let response = ls.send_request::<lsp_request!("textDocument/definition")>(code_action_params); | ||
|
||
let ranges = match response { | ||
Some(GotoDefinitionResponse::Scalar(location)) => { | ||
vec![location.range] | ||
} | ||
Some(GotoDefinitionResponse::Array(locations)) => { | ||
locations.into_iter().map(|location| location.range).collect() | ||
} | ||
Some(GotoDefinitionResponse::Link(_)) => { | ||
panic!("unexpected GotoDefinitionResponse::Link"); | ||
} | ||
None => { | ||
return "none response".into(); | ||
} | ||
}; | ||
|
||
render_selections(&cairo, &ranges) | ||
} |
Oops, something went wrong.