aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/descriptors.rs
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-09 15:08:17 +0100
committerJeremy A. Kolb <[email protected]>2018-10-11 21:40:46 +0100
commitf8a2b533045757c42c206b2596448baf4737f1f0 (patch)
tree587e681ec5323d8deabcc6d533de033e7aa79be7 /crates/ra_analysis/src/descriptors.rs
parent2ba6f18586d02a6dbc32e0bea88f7b4236277ea1 (diff)
Language Server: textDocument/signatureHelp
Implements a pretty barebones function signature help mechanism in the language server. Users can use `Analysis::resolve_callback()` to get basic information about a call site. Fixes #102
Diffstat (limited to 'crates/ra_analysis/src/descriptors.rs')
-rw-r--r--crates/ra_analysis/src/descriptors.rs56
1 files changed, 55 insertions, 1 deletions
diff --git a/crates/ra_analysis/src/descriptors.rs b/crates/ra_analysis/src/descriptors.rs
index 0731b5572..4dcac1aa2 100644
--- a/crates/ra_analysis/src/descriptors.rs
+++ b/crates/ra_analysis/src/descriptors.rs
@@ -4,7 +4,8 @@ use std::{
4use relative_path::RelativePathBuf; 4use relative_path::RelativePathBuf;
5use ra_syntax::{ 5use ra_syntax::{
6 SmolStr, 6 SmolStr,
7 ast::{self, NameOwner}, 7 ast::{self, NameOwner, AstNode, TypeParamsOwner},
8 text_utils::is_subrange
8}; 9};
9use { 10use {
10 FileId, 11 FileId,
@@ -218,3 +219,56 @@ fn resolve_submodule(
218 } 219 }
219 (points_to, problem) 220 (points_to, problem)
220} 221}
222
223#[derive(Debug, Clone)]
224pub struct FnDescriptor {
225 pub name: Option<String>,
226 pub label : String,
227 pub ret_type: Option<String>,
228 pub params: Vec<String>,
229}
230
231impl FnDescriptor {
232 pub fn new(node: ast::FnDef) -> Self {
233 let name = node.name().map(|name| name.text().to_string());
234
235 // Strip the body out for the label.
236 let label : String = if let Some(body) = node.body() {
237 let body_range = body.syntax().range();
238 let label : String = node.syntax().children()
239 .filter(|child| !is_subrange(body_range, child.range()))
240 .map(|node| node.text().to_string())
241 .collect();
242 label
243 } else {
244 node.syntax().text().to_string()
245 };
246
247 let params = FnDescriptor::param_list(node);
248 let ret_type = node.ret_type().map(|r| r.syntax().text().to_string());
249
250 FnDescriptor {
251 name,
252 ret_type,
253 params,
254 label
255 }
256 }
257
258 fn param_list(node: ast::FnDef) -> Vec<String> {
259 let mut res = vec![];
260 if let Some(param_list) = node.param_list() {
261 if let Some(self_param) = param_list.self_param() {
262 res.push(self_param.syntax().text().to_string())
263 }
264
265 // Maybe use param.pat here? See if we can just extract the name?
266 //res.extend(param_list.params().map(|p| p.syntax().text().to_string()));
267 res.extend(param_list.params()
268 .filter_map(|p| p.pat())
269 .map(|pat| pat.syntax().text().to_string())
270 );
271 }
272 res
273 }
274} \ No newline at end of file