mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Merge commit 'af40101841
' into sync-from-ra
This commit is contained in:
parent
79fa976864
commit
3afeb24198
115 changed files with 3106 additions and 3623 deletions
|
@ -792,6 +792,7 @@ impl flags::AnalysisStats {
|
|||
max_length: Some(25),
|
||||
closing_brace_hints_min_lines: Some(20),
|
||||
fields_to_resolve: InlayFieldsToResolve::empty(),
|
||||
range_exclusive_hints: true,
|
||||
},
|
||||
file_id,
|
||||
None,
|
||||
|
|
|
@ -7,8 +7,8 @@ use std::{
|
|||
};
|
||||
|
||||
use ide::{
|
||||
LineCol, MonikerDescriptorKind, StaticIndex, StaticIndexedFile, TextRange, TokenId,
|
||||
TokenStaticData,
|
||||
LineCol, MonikerDescriptorKind, MonikerResult, StaticIndex, StaticIndexedFile,
|
||||
SymbolInformationKind, TextRange, TokenId,
|
||||
};
|
||||
use ide_db::LineIndexDatabase;
|
||||
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
|
||||
|
@ -78,6 +78,7 @@ impl flags::Scip {
|
|||
|
||||
let mut symbols_emitted: HashSet<TokenId> = HashSet::default();
|
||||
let mut tokens_to_symbol: HashMap<TokenId, String> = HashMap::new();
|
||||
let mut tokens_to_enclosing_symbol: HashMap<TokenId, Option<String>> = HashMap::new();
|
||||
|
||||
for StaticIndexedFile { file_id, tokens, .. } in si.files {
|
||||
let mut local_count = 0;
|
||||
|
@ -109,10 +110,24 @@ impl flags::Scip {
|
|||
let symbol = tokens_to_symbol
|
||||
.entry(id)
|
||||
.or_insert_with(|| {
|
||||
let symbol = token_to_symbol(token).unwrap_or_else(&mut new_local_symbol);
|
||||
let symbol = token
|
||||
.moniker
|
||||
.as_ref()
|
||||
.map(moniker_to_symbol)
|
||||
.unwrap_or_else(&mut new_local_symbol);
|
||||
scip::symbol::format_symbol(symbol)
|
||||
})
|
||||
.clone();
|
||||
let enclosing_symbol = tokens_to_enclosing_symbol
|
||||
.entry(id)
|
||||
.or_insert_with(|| {
|
||||
token
|
||||
.enclosing_moniker
|
||||
.as_ref()
|
||||
.map(moniker_to_symbol)
|
||||
.map(scip::symbol::format_symbol)
|
||||
})
|
||||
.clone();
|
||||
|
||||
let mut symbol_roles = Default::default();
|
||||
|
||||
|
@ -128,15 +143,22 @@ impl flags::Scip {
|
|||
.map(|hover| hover.markup.as_str())
|
||||
.filter(|it| !it.is_empty())
|
||||
.map(|it| vec![it.to_owned()]);
|
||||
let signature_documentation =
|
||||
token.signature.clone().map(|text| scip_types::Document {
|
||||
relative_path: relative_path.clone(),
|
||||
language: "rust".to_string(),
|
||||
text,
|
||||
..Default::default()
|
||||
});
|
||||
let symbol_info = scip_types::SymbolInformation {
|
||||
symbol: symbol.clone(),
|
||||
documentation: documentation.unwrap_or_default(),
|
||||
relationships: Vec::new(),
|
||||
special_fields: Default::default(),
|
||||
kind: Default::default(),
|
||||
display_name: String::new(),
|
||||
signature_documentation: Default::default(),
|
||||
enclosing_symbol: String::new(),
|
||||
kind: symbol_kind(token.kind).into(),
|
||||
display_name: token.display_name.clone().unwrap_or_default(),
|
||||
signature_documentation: signature_documentation.into(),
|
||||
enclosing_symbol: enclosing_symbol.unwrap_or_default(),
|
||||
};
|
||||
|
||||
symbols.push(symbol_info)
|
||||
|
@ -228,14 +250,36 @@ fn new_descriptor(name: &str, suffix: scip_types::descriptor::Suffix) -> scip_ty
|
|||
}
|
||||
}
|
||||
|
||||
/// Loosely based on `def_to_moniker`
|
||||
///
|
||||
/// Only returns a Symbol when it's a non-local symbol.
|
||||
/// So if the visibility isn't outside of a document, then it will return None
|
||||
fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
|
||||
use scip_types::descriptor::Suffix::*;
|
||||
fn symbol_kind(kind: SymbolInformationKind) -> scip_types::symbol_information::Kind {
|
||||
use scip_types::symbol_information::Kind as ScipKind;
|
||||
match kind {
|
||||
SymbolInformationKind::AssociatedType => ScipKind::AssociatedType,
|
||||
SymbolInformationKind::Attribute => ScipKind::Attribute,
|
||||
SymbolInformationKind::Constant => ScipKind::Constant,
|
||||
SymbolInformationKind::Enum => ScipKind::Enum,
|
||||
SymbolInformationKind::EnumMember => ScipKind::EnumMember,
|
||||
SymbolInformationKind::Field => ScipKind::Field,
|
||||
SymbolInformationKind::Function => ScipKind::Function,
|
||||
SymbolInformationKind::Macro => ScipKind::Macro,
|
||||
SymbolInformationKind::Method => ScipKind::Method,
|
||||
SymbolInformationKind::Module => ScipKind::Module,
|
||||
SymbolInformationKind::Parameter => ScipKind::Parameter,
|
||||
SymbolInformationKind::SelfParameter => ScipKind::SelfParameter,
|
||||
SymbolInformationKind::StaticMethod => ScipKind::StaticMethod,
|
||||
SymbolInformationKind::StaticVariable => ScipKind::StaticVariable,
|
||||
SymbolInformationKind::Struct => ScipKind::Struct,
|
||||
SymbolInformationKind::Trait => ScipKind::Trait,
|
||||
SymbolInformationKind::TraitMethod => ScipKind::TraitMethod,
|
||||
SymbolInformationKind::Type => ScipKind::Type,
|
||||
SymbolInformationKind::TypeAlias => ScipKind::TypeAlias,
|
||||
SymbolInformationKind::TypeParameter => ScipKind::TypeParameter,
|
||||
SymbolInformationKind::Union => ScipKind::Union,
|
||||
SymbolInformationKind::Variable => ScipKind::Variable,
|
||||
}
|
||||
}
|
||||
|
||||
let moniker = token.moniker.as_ref()?;
|
||||
fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
|
||||
use scip_types::descriptor::Suffix::*;
|
||||
|
||||
let package_name = moniker.package_information.name.clone();
|
||||
let version = moniker.package_information.version.clone();
|
||||
|
@ -260,7 +304,7 @@ fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
|
|||
})
|
||||
.collect();
|
||||
|
||||
Some(scip_types::Symbol {
|
||||
scip_types::Symbol {
|
||||
scheme: "rust-analyzer".into(),
|
||||
package: Some(scip_types::Package {
|
||||
manager: "cargo".to_string(),
|
||||
|
@ -271,7 +315,7 @@ fn token_to_symbol(token: &TokenStaticData) -> Option<scip_types::Symbol> {
|
|||
.into(),
|
||||
descriptors,
|
||||
special_fields: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -309,7 +353,7 @@ mod test {
|
|||
for &(range, id) in &file.tokens {
|
||||
if range.contains(offset - TextSize::from(1)) {
|
||||
let token = si.tokens.get(id).unwrap();
|
||||
found_symbol = token_to_symbol(token);
|
||||
found_symbol = token.moniker.as_ref().map(moniker_to_symbol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -359,6 +403,21 @@ pub mod module {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn symbol_for_trait_alias() {
|
||||
check_symbol(
|
||||
r#"
|
||||
//- /foo/lib.rs crate:foo@0.1.0,https://a.b/foo.git library
|
||||
#![feature(trait_alias)]
|
||||
pub mod module {
|
||||
pub trait MyTrait {}
|
||||
pub trait MyTraitAlias$0 = MyTrait;
|
||||
}
|
||||
"#,
|
||||
"rust-analyzer cargo foo 0.1.0 module/MyTraitAlias#",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn symbol_for_trait_constant() {
|
||||
check_symbol(
|
||||
|
@ -525,4 +584,15 @@ pub mod example_mod {
|
|||
"rust-analyzer cargo main . foo/Bar#",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn symbol_for_for_type_alias() {
|
||||
check_symbol(
|
||||
r#"
|
||||
//- /lib.rs crate:main
|
||||
pub type MyTypeAlias$0 = u8;
|
||||
"#,
|
||||
"rust-analyzer cargo main . MyTypeAlias#",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,6 +399,8 @@ config_data! {
|
|||
/// Whether to show function parameter name inlay hints at the call
|
||||
/// site.
|
||||
inlayHints_parameterHints_enable: bool = "true",
|
||||
/// Whether to show exclusive range inlay hints.
|
||||
inlayHints_rangeExclusiveHints_enable: bool = "false",
|
||||
/// Whether to show inlay hints for compiler inserted reborrows.
|
||||
/// This setting is deprecated in favor of #rust-analyzer.inlayHints.expressionAdjustmentHints.enable#.
|
||||
inlayHints_reborrowHints_enable: ReborrowHintsDef = "\"never\"",
|
||||
|
@ -1464,6 +1466,7 @@ impl Config {
|
|||
} else {
|
||||
None
|
||||
},
|
||||
range_exclusive_hints: self.data.inlayHints_rangeExclusiveHints_enable,
|
||||
fields_to_resolve: InlayFieldsToResolve {
|
||||
resolve_text_edits: client_capability_fields.contains("textEdits"),
|
||||
resolve_hint_tooltip: client_capability_fields.contains("tooltip"),
|
||||
|
|
|
@ -458,7 +458,6 @@ pub(crate) fn handle_workspace_symbol(
|
|||
|
||||
let config = snap.config.workspace_symbol();
|
||||
let (all_symbols, libs) = decide_search_scope_and_kind(¶ms, &config);
|
||||
let limit = config.search_limit;
|
||||
|
||||
let query = {
|
||||
let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
|
||||
|
@ -469,14 +468,11 @@ pub(crate) fn handle_workspace_symbol(
|
|||
if libs {
|
||||
q.libs();
|
||||
}
|
||||
q.limit(limit);
|
||||
q
|
||||
};
|
||||
let mut res = exec_query(&snap, query)?;
|
||||
let mut res = exec_query(&snap, query, config.search_limit)?;
|
||||
if res.is_empty() && !all_symbols {
|
||||
let mut query = Query::new(params.query);
|
||||
query.limit(limit);
|
||||
res = exec_query(&snap, query)?;
|
||||
res = exec_query(&snap, Query::new(params.query), config.search_limit)?;
|
||||
}
|
||||
|
||||
return Ok(Some(lsp_types::WorkspaceSymbolResponse::Nested(res)));
|
||||
|
@ -519,9 +515,10 @@ pub(crate) fn handle_workspace_symbol(
|
|||
fn exec_query(
|
||||
snap: &GlobalStateSnapshot,
|
||||
query: Query,
|
||||
limit: usize,
|
||||
) -> anyhow::Result<Vec<lsp_types::WorkspaceSymbol>> {
|
||||
let mut res = Vec::new();
|
||||
for nav in snap.analysis.symbol_search(query)? {
|
||||
for nav in snap.analysis.symbol_search(query, limit)? {
|
||||
let container_name = nav.container_name.as_ref().map(|v| v.to_string());
|
||||
|
||||
let info = lsp_types::WorkspaceSymbol {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue