-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get-type command #730
Open
TedDriggs
wants to merge
4
commits into
racer-rust:master
Choose a base branch
from
TedDriggs:get_type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add get-type command #730
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ src/scopes | |
*.racertmp | ||
target/ | ||
*.py[cod] | ||
.vscode/** | ||
.vscode/** |
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 |
---|---|---|
|
@@ -150,7 +150,7 @@ impl Drop for TmpDir { | |
} | ||
|
||
fn get_pos_and_source(src: &str) -> (usize, String) { | ||
let point = src.find('~').unwrap(); | ||
let point = src.find('~').expect("Test input must contain a `~` character to represent cursor location"); | ||
(point, src.replace('~', "")) | ||
} | ||
|
||
|
@@ -190,7 +190,17 @@ fn get_definition(src: &str, dir: Option<TmpDir>) -> Match { | |
let cache = racer::FileCache::default(); | ||
let session = racer::Session::new(&cache); | ||
|
||
find_definition(&path, completion_point, &session).unwrap() | ||
find_definition(&path, completion_point, &session).expect("find-definition must produce a definition") | ||
} | ||
|
||
fn get_type(src: &str, dir: Option<TmpDir>) -> Match { | ||
let dir = dir.unwrap_or_else(|| TmpDir::new()); | ||
let (search_point, clean_src) = get_pos_and_source(src); | ||
let path = dir.write_file("src.rs", &clean_src); | ||
let cache = racer::FileCache::default(); | ||
let session = racer::Session::new(&cache); | ||
|
||
racer::get_type(&path, search_point, &session).expect("get-type must produce a type") | ||
} | ||
|
||
|
||
|
@@ -3242,6 +3252,153 @@ fn closure_bracket_scope_nested_match_outside() { | |
assert_eq!("| x: i32 |", got.contextstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_explicit_local_var() { | ||
let _lock = sync!(); | ||
let src = " | ||
fn main() { | ||
let value: Option<u16> = Some(5); | ||
if val~ue.is_some() { | ||
// do nothing | ||
} | ||
} | ||
"; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Option", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_fn_arg() { | ||
let _lock = sync!(); | ||
let src = r#" | ||
fn say_hello(name: &str) { | ||
if nam~e != "teddriggs" { | ||
// do nothing | ||
} | ||
} | ||
"#; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("str", got.matchstr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See this comment |
||
} | ||
|
||
#[test] | ||
fn get_type_finds_tuple_field() { | ||
let _lock = sync!(); | ||
let src = " | ||
struct Bar; | ||
struct Foo(Bar); | ||
|
||
fn do_things(foo: Foo) -> Bar { | ||
foo.0~ | ||
} | ||
"; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Bar", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_struct_field() { | ||
let _lock = sync!(); | ||
let src = " | ||
struct Bar; | ||
struct Foo { value: Bar } | ||
|
||
fn do_things(foo: Foo) -> Bar { | ||
foo.va~lue | ||
} | ||
"; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Bar", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_destructured() { | ||
let _lock = sync!(); | ||
let src = " | ||
struct Bar; | ||
struct Foo { value: Bar } | ||
|
||
fn do_things(foo: Foo) -> Bar { | ||
let Foo { value: value } = foo; | ||
valu~e | ||
} | ||
"; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Bar", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_single_character_var_at_end() { | ||
let _lock = sync!(); | ||
let src = " | ||
struct Bar; | ||
fn do_things(y: Bar) -> Bar { | ||
y~ | ||
} | ||
"; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Bar", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_single_character_var_at_start() { | ||
let _lock = sync!(); | ||
let src = " | ||
struct Bar; | ||
fn do_things(y: Bar) -> Bar { | ||
~y | ||
} | ||
"; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Bar", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_function_return() { | ||
let _lock = sync!(); | ||
let src = r#" | ||
struct Bar; | ||
fn do_things(y: Bar) -> Bar { | ||
y | ||
} | ||
|
||
fn main() { | ||
let z = do_things(); | ||
println!("{:?}", ~z); | ||
} | ||
"#; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("Bar", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn get_type_finds_function() { | ||
let _lock = sync!(); | ||
let src = r#" | ||
struct Bar; | ||
|
||
fn do_things(y: Bar) -> Bar { | ||
y | ||
} | ||
|
||
fn main() { | ||
let z = do_th~ings(); | ||
println!("{:?}", ~z); | ||
} | ||
"#; | ||
|
||
let got = get_type(src, None); | ||
assert_eq!("do_things", got.matchstr); | ||
} | ||
|
||
#[test] | ||
fn literal_string_method() { | ||
let _lock = sync!(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, can we not determine that it's an
Option<usize>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't put generic types into the
matchstr
property today; they're in thegeneric_types
array instead. I could try and do something to push that data intomatchstr
but I'm not sure which approach would be better for tooling authors.