Add TypeProc::main_value method

This commit is contained in:
Tad Hardesty 2019-07-14 20:18:21 -07:00
parent c0963bb31a
commit 1fb53dc003
4 changed files with 15 additions and 8 deletions

View file

@ -255,7 +255,7 @@ fn main() -> Result<(), Box<std::error::Error>> {
}
for (name, proc) in ty.get().procs.iter() {
let proc_value = proc.value.last().unwrap();
let proc_value = proc.main_value();
if !proc_value.docs.is_empty() {
let block = DocBlock::parse(&proc_value.docs.text());
parsed_type.procs.insert(name, Proc {

View file

@ -103,6 +103,13 @@ pub struct TypeProc {
pub declaration: Option<ProcDeclaration>,
}
impl TypeProc {
#[inline]
pub fn main_value(&self) -> &ProcValue {
self.value.last().expect("TypeProc::value is empty")
}
}
// ----------------------------------------------------------------------------
// Types

View file

@ -227,7 +227,7 @@ impl<'a, W: io::ResponseWrite> Engine<'a, W> {
let mut completion = format!("{}(", name);
let mut sep = "";
for param in proc.value.last().unwrap().parameters.iter() {
for param in proc.main_value().parameters.iter() {
for each in param.var_type.type_path.iter() {
let _ = write!(completion, "{}{}", sep, each);
sep = "/";

View file

@ -934,7 +934,7 @@ handle_method_call! {
} else {
&current.path
};
let proc_value = proc.value.last().unwrap();
let proc_value = proc.main_value();
let mut message = format!("[{}]({}) \n{}(", path, self.location_link(proc_value.location)?, last);
let mut first = true;
for each in proc_value.parameters.iter() {
@ -1003,7 +1003,7 @@ handle_method_call! {
}
while let Some(ty) = next {
if let Some(proc) = ty.procs.get(proc_name) {
results.push(self.convert_location(proc.value.last().unwrap().location, &[&ty.path, "/proc/", proc_name])?);
results.push(self.convert_location(proc.main_value().location, &[&ty.path, "/proc/", proc_name])?);
break;
}
next = ty.parent_type();
@ -1028,7 +1028,7 @@ handle_method_call! {
let mut next = ty.or(Some(self.objtree.root()));
while let Some(ty) = next {
if let Some(proc) = ty.procs.get(proc_name) {
results.push(self.convert_location(proc.value.last().unwrap().location, &[&ty.path, "/proc/", proc_name])?);
results.push(self.convert_location(proc.main_value().location, &[&ty.path, "/proc/", proc_name])?);
break;
}
next = ty.parent_type();
@ -1053,7 +1053,7 @@ handle_method_call! {
let mut next = self.find_scoped_type(&iter, priors);
while let Some(ty) = next {
if let Some(proc) = ty.procs.get(proc_name) {
results.push(self.convert_location(proc.value.last().unwrap().location, &[&ty.path, "/proc/", proc_name])?);
results.push(self.convert_location(proc.main_value().location, &[&ty.path, "/proc/", proc_name])?);
break;
}
next = ignore_root(ty.parent_type());
@ -1080,7 +1080,7 @@ handle_method_call! {
let mut next = ty.parent_type();
while let Some(ty) = next {
if let Some(proc) = ty.procs.get(proc_name) {
results.push(self.convert_location(proc.value.last().unwrap().location, &[&ty.path, "/proc/", proc_name])?);
results.push(self.convert_location(proc.main_value().location, &[&ty.path, "/proc/", proc_name])?);
break;
}
next = ty.parent_type();
@ -1398,7 +1398,7 @@ handle_method_call! {
let mut params = Vec::new();
let mut label = format!("{}/{}(", ty.path, proc_name);
let mut sep = "";
for param in proc.value.last().unwrap().parameters.iter() {
for param in proc.main_value().parameters.iter() {
for each in param.var_type.type_path.iter() {
let _ = write!(label, "{}{}", sep, each);
sep = "/";