cleanup getting docs for symbol

This commit is contained in:
faldor20 2024-03-12 00:13:57 +10:00
parent 321baf86d1
commit ee264981b6
No known key found for this signature in database
GPG key ID: F2216079B890CD57
2 changed files with 12 additions and 19 deletions

View file

@ -17,6 +17,14 @@ pub struct ModuleDocumentation {
pub scope: Scope,
pub exposed_symbols: VecSet<Symbol>,
}
impl ModuleDocumentation {
pub fn get_doc_for_symbol(&self, symb: &Symbol) -> Option<String> {
self.entries.iter().find_map(|doc| match doc {
DocEntry::DocDef(DocDef { symbol, docs, .. }) if symbol == symb => docs.clone(),
_ => None,
})
}
}
#[derive(Debug, Clone)]
pub enum DocEntry {

View file

@ -1,5 +1,4 @@
use log::{debug, info};
use roc_load::docs::DocDef;
use std::collections::HashMap;
use bumpalo::Bump;
@ -170,30 +169,16 @@ impl AnalyzedDocument {
declarations,
module_id,
interns,
abilities,
modules_info,
..
} = self.module()?;
let (region, var) = roc_can::traverse::find_closest_type_at(pos, declarations)?;
let docs = roc_can::traverse::find_closest_symbol_at(pos, declarations, abilities)
.and_then(|symb| {
let symb = symb.implementation_symbol();
modules_info
.docs
.get(module_id)?
.entries
.iter()
.find_map(|doc| match doc {
roc_load::docs::DocEntry::DocDef(DocDef { symbol, docs, .. })
if symbol == &symb =>
{
docs.clone()
}
_ => None,
})
});
//TODO:Can this be integrated into find closest type? is it even worth it?
let docs = self
.symbol_at(position)
.and_then(|symb| modules_info.docs.get(module_id)?.get_doc_for_symbol(&symb));
let type_str = format_var_type(var, &mut subs.clone(), module_id, interns);