mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Refactor the code
This commit is contained in:
parent
d9bd1f171d
commit
50e06ee95a
11 changed files with 48 additions and 34 deletions
|
@ -15,9 +15,15 @@ pub struct CompletionConfig {
|
|||
pub add_call_argument_snippets: bool,
|
||||
pub snippet_cap: Option<SnippetCap>,
|
||||
pub merge: Option<MergeBehaviour>,
|
||||
/// A set of capabilities, enabled on the cliend and supported on the server.
|
||||
pub resolve_capabilities: FxHashSet<CompletionResolveCapability>,
|
||||
}
|
||||
|
||||
/// A resolve capability, supported on a server.
|
||||
/// If the client registers any of those in its completion resolve capabilities,
|
||||
/// the server is able to render completion items' corresponding fields later,
|
||||
/// not during an initial completion item request.
|
||||
/// See https://github.com/rust-analyzer/rust-analyzer/issues/6366 for more details.
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
|
||||
pub enum CompletionResolveCapability {
|
||||
Documentation,
|
||||
|
@ -30,7 +36,8 @@ impl CompletionConfig {
|
|||
self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None }
|
||||
}
|
||||
|
||||
pub fn should_resolve_immediately(&self) -> bool {
|
||||
/// Whether the completions' additional edits are calculated later, during a resolve request or not.
|
||||
pub fn should_resolve_additional_edits_immediately(&self) -> bool {
|
||||
!self.resolve_capabilities.contains(&CompletionResolveCapability::AdditionalTextEdits)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,8 +67,7 @@ pub struct CompletionItem {
|
|||
/// possible match.
|
||||
ref_match: Option<(Mutability, CompletionScore)>,
|
||||
|
||||
/// The data later to be used in the `completionItem/resolve` response
|
||||
/// to add the insert import edit.
|
||||
/// The import data to add to completion's edits.
|
||||
import_to_add: Option<ImportToAdd>,
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,10 @@ impl<'a> Render<'a> {
|
|||
local_name,
|
||||
)
|
||||
.kind(CompletionItemKind::UnresolvedReference)
|
||||
.add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately())
|
||||
.add_import(
|
||||
import_to_add,
|
||||
self.ctx.completion.config.should_resolve_additional_edits_immediately(),
|
||||
)
|
||||
.build();
|
||||
return Some(item);
|
||||
}
|
||||
|
@ -249,7 +252,10 @@ impl<'a> Render<'a> {
|
|||
|
||||
let item = item
|
||||
.kind(kind)
|
||||
.add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately())
|
||||
.add_import(
|
||||
import_to_add,
|
||||
self.ctx.completion.config.should_resolve_additional_edits_immediately(),
|
||||
)
|
||||
.set_documentation(docs)
|
||||
.set_ref_match(ref_match)
|
||||
.build();
|
||||
|
|
|
@ -71,7 +71,10 @@ impl<'a> EnumVariantRender<'a> {
|
|||
.kind(CompletionItemKind::EnumVariant)
|
||||
.set_documentation(self.variant.docs(self.ctx.db()))
|
||||
.set_deprecated(self.ctx.is_deprecated(self.variant))
|
||||
.add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately())
|
||||
.add_import(
|
||||
import_to_add,
|
||||
self.ctx.completion.config.should_resolve_additional_edits_immediately(),
|
||||
)
|
||||
.detail(self.detail());
|
||||
|
||||
if self.variant_kind == StructKind::Tuple {
|
||||
|
|
|
@ -47,7 +47,10 @@ impl<'a> FunctionRender<'a> {
|
|||
.set_deprecated(self.ctx.is_deprecated(self.func))
|
||||
.detail(self.detail())
|
||||
.add_call_parens(self.ctx.completion, self.name, params)
|
||||
.add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately())
|
||||
.add_import(
|
||||
import_to_add,
|
||||
self.ctx.completion.config.should_resolve_additional_edits_immediately(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,10 @@ impl<'a> MacroRender<'a> {
|
|||
.kind(CompletionItemKind::Macro)
|
||||
.set_documentation(self.docs.clone())
|
||||
.set_deprecated(self.ctx.is_deprecated(self.macro_))
|
||||
.add_import(import_to_add, self.ctx.completion.config.should_resolve_immediately())
|
||||
.add_import(
|
||||
import_to_add,
|
||||
self.ctx.completion.config.should_resolve_additional_edits_immediately(),
|
||||
)
|
||||
.detail(self.detail());
|
||||
|
||||
let needs_bang = self.needs_bang();
|
||||
|
|
|
@ -97,7 +97,6 @@ pub(crate) fn check_edit_with_config(
|
|||
.unwrap_or_else(|| panic!("can't find {:?} completion in {:#?}", what, completions));
|
||||
let mut actual = db.file_text(position.file_id).to_string();
|
||||
completion.text_edit().apply(&mut actual);
|
||||
// git how to apply imports now?
|
||||
assert_eq_text!(&ra_fixture_after, &actual)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue