Some(comments)
}
}
-
- pub fn label(&self, db: &impl HirDatabase) -> Option<String> {
- let def_loc = self.def_id.loc(db);
- let syntax = db.file_item(def_loc.source_item_id);
- let node = ast::FnDef::cast(&syntax).expect("fn def should point to FnDef node");
-
- let label: String = if let Some(body) = node.body() {
- let body_range = body.syntax().range();
- let label: String = node
- .syntax()
- .children()
- .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
- .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
- .map(|node| node.text().to_string())
- .collect();
- label
- } else {
- node.syntax().text().to_string()
- };
-
- Some(label.trim().to_owned())
- }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
use hir::PerNs;
use crate::completion::completion_context::CompletionContext;
-use ra_syntax::TextRange;
+use ra_syntax::{
+ ast::{self, AstNode},
+ TextRange
+};
use ra_text_edit::TextEdit;
/// `CompletionItem` describes a single completion variant in the editor pop-up.
self.documentation = Some(docs);
}
- if let Some(label) = function.label(ctx.db) {
+ if let Some(label) = function_label(ctx, function) {
self.detail = Some(label);
}
}
}
+fn function_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
+ let node = function.source(ctx.db).1;
+
+ let label: String = if let Some(body) = node.body() {
+ let body_range = body.syntax().range();
+ let label: String = node
+ .syntax()
+ .children()
+ .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
+ .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
+ .map(|node| node.text().to_string())
+ .collect();
+ label
+ } else {
+ node.syntax().text().to_string()
+ };
+
+ Some(label.trim().to_owned())
+}
+
#[cfg(test)]
pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) {
use crate::mock_analysis::{single_file_with_position, analysis_and_position};