2513: Report correct original range in goto_definition r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-12-09 18:47:00 +00:00 committed by GitHub
commit 897b550049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

@ -19,25 +19,23 @@ pub(crate) fn goto_definition(
position: FilePosition, position: FilePosition,
) -> Option<RangeInfo<Vec<NavigationTarget>>> { ) -> Option<RangeInfo<Vec<NavigationTarget>>> {
let file = db.parse_or_expand(position.file_id.into())?; let file = db.parse_or_expand(position.file_id.into())?;
let token = file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?; let original_token =
let token = descend_into_macros(db, position.file_id, token); file.token_at_offset(position.offset).filter(|it| !it.kind().is_trivia()).next()?;
let token = descend_into_macros(db, position.file_id, original_token.clone());
let res = match_ast! { let nav_targets = match_ast! {
match (token.value.parent()) { match (token.value.parent()) {
ast::NameRef(name_ref) => { ast::NameRef(name_ref) => {
let navs = reference_definition(db, token.with_value(&name_ref)).to_vec(); reference_definition(db, token.with_value(&name_ref)).to_vec()
RangeInfo::new(name_ref.syntax().text_range(), navs.to_vec())
}, },
ast::Name(name) => { ast::Name(name) => {
let navs = name_definition(db, token.with_value(&name))?; name_definition(db, token.with_value(&name))?
RangeInfo::new(name.syntax().text_range(), navs)
}, },
_ => return None, _ => return None,
} }
}; };
Some(res) Some(RangeInfo::new(original_token.text_range(), nav_targets))
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -26,6 +26,8 @@ export class Config {
public excludeGlobs = []; public excludeGlobs = [];
public useClientWatching = false; public useClientWatching = false;
public featureFlags = {}; public featureFlags = {};
// for internal use
public withSysroot: null | boolean = null;
public cargoWatchOptions: CargoWatchOptions = { public cargoWatchOptions: CargoWatchOptions = {
enableOnStartup: 'ask', enableOnStartup: 'ask',
trace: 'off', trace: 'off',
@ -148,5 +150,8 @@ export class Config {
if (config.has('featureFlags')) { if (config.has('featureFlags')) {
this.featureFlags = config.get('featureFlags') || {}; this.featureFlags = config.get('featureFlags') || {};
} }
if (config.has('withSysroot')) {
this.withSysroot = config.get('withSysroot') || false;
}
} }
} }

View file

@ -57,7 +57,8 @@ export class Server {
maxInlayHintLength: Server.config.maxInlayHintLength, maxInlayHintLength: Server.config.maxInlayHintLength,
excludeGlobs: Server.config.excludeGlobs, excludeGlobs: Server.config.excludeGlobs,
useClientWatching: Server.config.useClientWatching, useClientWatching: Server.config.useClientWatching,
featureFlags: Server.config.featureFlags featureFlags: Server.config.featureFlags,
withSysroot: Server.config.withSysroot
}, },
traceOutputChannel traceOutputChannel
}; };