Cleanup term search related changes

This commit is contained in:
Tavo Annus 2024-02-01 11:02:19 +02:00
parent 88964c0b6a
commit 125791386d
26 changed files with 590 additions and 516 deletions

View file

@ -333,10 +333,12 @@ impl flags::AnalysisStats {
mut file_ids: Vec<FileId>,
verbosity: Verbosity,
) {
let mut cargo_config = CargoConfig::default();
cargo_config.sysroot = match self.no_sysroot {
true => None,
false => Some(RustLibSource::Discover),
let cargo_config = CargoConfig {
sysroot: match self.no_sysroot {
true => None,
false => Some(RustLibSource::Discover),
},
..Default::default()
};
let mut bar = match verbosity {
@ -392,16 +394,15 @@ impl flags::AnalysisStats {
continue;
}
let range = sema.original_range(&expected_tail.syntax()).range;
let range = sema.original_range(expected_tail.syntax()).range;
let original_text: String = db
.file_text(file_id)
.chars()
.into_iter()
.skip(usize::from(range.start()))
.take(usize::from(range.end()) - usize::from(range.start()))
.collect();
let scope = match sema.scope(&expected_tail.syntax()) {
let scope = match sema.scope(expected_tail.syntax()) {
Some(it) => it,
None => continue,
};
@ -425,14 +426,15 @@ impl flags::AnalysisStats {
};
fn trim(s: &str) -> String {
s.chars().into_iter().filter(|c| !c.is_whitespace()).collect()
s.chars().filter(|c| !c.is_whitespace()).collect()
}
let todo = syntax::ast::make::ext::expr_todo().to_string();
let mut formatter = |_: &hir::Type| todo.clone();
let mut syntax_hit_found = false;
for term in found_terms {
let generated = term.gen_source_code(&scope, &mut formatter, false, true);
let generated =
term.gen_source_code(&scope, &mut formatter, false, true).unwrap();
syntax_hit_found |= trim(&original_text) == trim(&generated);
// Validate if type-checks

View file

@ -93,9 +93,10 @@ xflags::xflags! {
/// and annotations. This is useful for benchmarking the memory usage on a project that has
/// been worked on for a bit in a longer running session.
optional --run-all-ide-things
/// Run term search
/// Run term search on all the tail expressions (of functions, block, if statements etc.)
optional --run-term-search
/// Validate term search by running `cargo check` on every response
/// Validate term search by running `cargo check` on every response.
/// Note that this also temporarily modifies the files on disk, use with caution!
optional --validate-term-search
}

View file

@ -287,7 +287,7 @@ config_data! {
}
}"#,
/// Whether to enable term search based snippets like `Some(foo.bar().baz())`.
completion_term_search_enable: bool = "true",
completion_termSearch_enable: bool = "false",
/// List of rust-analyzer diagnostics to disable.
diagnostics_disabled: FxHashSet<String> = "[]",
@ -1537,7 +1537,7 @@ impl Config {
&& completion_item_edit_resolve(&self.caps),
enable_self_on_the_fly: self.data.completion_autoself_enable,
enable_private_editable: self.data.completion_privateEditable_enable,
enable_term_search: self.data.completion_term_search_enable,
enable_term_search: self.data.completion_termSearch_enable,
full_function_signatures: self.data.completion_fullFunctionSignatures_enable,
callable: match self.data.completion_callable_snippets {
CallableCompletionDef::FillArguments => Some(CallableSnippets::FillArguments),

View file

@ -123,6 +123,7 @@ pub(crate) fn completion_item_kind(
CompletionItemKind::Method => lsp_types::CompletionItemKind::METHOD,
CompletionItemKind::Snippet => lsp_types::CompletionItemKind::SNIPPET,
CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::REFERENCE,
CompletionItemKind::Expression => lsp_types::CompletionItemKind::SNIPPET,
CompletionItemKind::SymbolKind(symbol) => match symbol {
SymbolKind::Attribute => lsp_types::CompletionItemKind::FUNCTION,
SymbolKind::Const => lsp_types::CompletionItemKind::CONSTANT,