aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/item.rs')
-rw-r--r--crates/completion/src/item.rs29
1 files changed, 27 insertions, 2 deletions
diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs
index 4e56f28f3..dd25ca75c 100644
--- a/crates/completion/src/item.rs
+++ b/crates/completion/src/item.rs
@@ -4,10 +4,10 @@ use std::fmt;
4 4
5use hir::{Documentation, ModPath, Mutability}; 5use hir::{Documentation, ModPath, Mutability};
6use ide_db::helpers::{ 6use ide_db::helpers::{
7 insert_use::{self, ImportScope, MergeBehaviour}, 7 insert_use::{self, ImportScope, ImportScopePtr, MergeBehaviour},
8 mod_path_to_ast, 8 mod_path_to_ast,
9}; 9};
10use syntax::{algo, TextRange}; 10use syntax::{algo, SyntaxNode, TextRange};
11use text_edit::TextEdit; 11use text_edit::TextEdit;
12 12
13use crate::config::SnippetCap; 13use crate::config::SnippetCap;
@@ -275,7 +275,32 @@ pub struct ImportEdit {
275 pub merge_behaviour: Option<MergeBehaviour>, 275 pub merge_behaviour: Option<MergeBehaviour>,
276} 276}
277 277
278#[derive(Debug, Clone)]
279pub struct ImportEditPtr {
280 pub import_path: ModPath,
281 pub import_scope: ImportScopePtr,
282 pub merge_behaviour: Option<MergeBehaviour>,
283}
284
285impl ImportEditPtr {
286 pub fn into_import_edit(self, root: &SyntaxNode) -> Option<ImportEdit> {
287 Some(ImportEdit {
288 import_path: self.import_path,
289 import_scope: self.import_scope.into_scope(root)?,
290 merge_behaviour: self.merge_behaviour,
291 })
292 }
293}
294
278impl ImportEdit { 295impl ImportEdit {
296 pub fn get_edit_ptr(&self) -> ImportEditPtr {
297 ImportEditPtr {
298 import_path: self.import_path.clone(),
299 import_scope: self.import_scope.get_ptr(),
300 merge_behaviour: self.merge_behaviour,
301 }
302 }
303
279 /// Attempts to insert the import to the given scope, producing a text edit. 304 /// Attempts to insert the import to the given scope, producing a text edit.
280 /// May return no edit in edge cases, such as scope already containing the import. 305 /// May return no edit in edge cases, such as scope already containing the import.
281 pub fn to_text_edit(&self) -> Option<TextEdit> { 306 pub fn to_text_edit(&self) -> Option<TextEdit> {