mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
module docs
This commit is contained in:
parent
0b56882785
commit
0c463555f4
4 changed files with 26 additions and 5 deletions
|
@ -22,6 +22,7 @@ pub struct ModuleDocumentation {
|
||||||
pub enum DocEntry {
|
pub enum DocEntry {
|
||||||
DocDef(DocDef),
|
DocDef(DocDef),
|
||||||
DetachedDoc(String),
|
DetachedDoc(String),
|
||||||
|
ModuleDoc(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -179,7 +180,7 @@ fn generate_entry_docs(
|
||||||
if let Some(docs) = comments_or_new_lines_to_docs(header_comments) {
|
if let Some(docs) = comments_or_new_lines_to_docs(header_comments) {
|
||||||
println!("<<docs:\n {:#?}\n docs>>", docs);
|
println!("<<docs:\n {:#?}\n docs>>", docs);
|
||||||
|
|
||||||
acc.push(DetachedDoc(docs));
|
acc.push(DocEntry::ModuleDoc(docs));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut before_comments_or_new_lines: Option<&[CommentOrNewline]> = None;
|
let mut before_comments_or_new_lines: Option<&[CommentOrNewline]> = None;
|
||||||
|
|
|
@ -253,6 +253,7 @@ impl AnalyzedDocument {
|
||||||
declarations,
|
declarations,
|
||||||
exposed_imports,
|
exposed_imports,
|
||||||
imports,
|
imports,
|
||||||
|
docs_by_module,
|
||||||
modules_info,
|
modules_info,
|
||||||
..
|
..
|
||||||
} = self.module()?;
|
} = self.module()?;
|
||||||
|
@ -273,6 +274,7 @@ impl AnalyzedDocument {
|
||||||
interns,
|
interns,
|
||||||
imports,
|
imports,
|
||||||
modules_info,
|
modules_info,
|
||||||
|
docs_by_module,
|
||||||
true,
|
true,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
|
@ -298,6 +300,7 @@ impl AnalyzedDocument {
|
||||||
interns,
|
interns,
|
||||||
imports,
|
imports,
|
||||||
modules_info,
|
modules_info,
|
||||||
|
docs_by_module,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
Some(completions)
|
Some(completions)
|
||||||
|
|
|
@ -8,7 +8,8 @@ use roc_can::{
|
||||||
pattern::{ListPatterns, Pattern, RecordDestruct, TupleDestruct},
|
pattern::{ListPatterns, Pattern, RecordDestruct, TupleDestruct},
|
||||||
traverse::{walk_decl, walk_def, walk_expr, DeclarationInfo, Visitor},
|
traverse::{walk_decl, walk_def, walk_expr, DeclarationInfo, Visitor},
|
||||||
};
|
};
|
||||||
use roc_collections::MutMap;
|
use roc_collections::{MutMap, VecMap};
|
||||||
|
use roc_load::docs::ModuleDocumentation;
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
use roc_region::all::{Loc, Position, Region};
|
use roc_region::all::{Loc, Position, Region};
|
||||||
use roc_types::{
|
use roc_types::{
|
||||||
|
@ -326,6 +327,7 @@ pub(super) fn get_module_completion_items(
|
||||||
interns: &Interns,
|
interns: &Interns,
|
||||||
imported_modules: &HashMap<ModuleId, Arc<Vec<(Symbol, Variable)>>>,
|
imported_modules: &HashMap<ModuleId, Arc<Vec<(Symbol, Variable)>>>,
|
||||||
modules_info: &ModulesInfo,
|
modules_info: &ModulesInfo,
|
||||||
|
docs: &VecMap<ModuleId, ModuleDocumentation>,
|
||||||
just_modules: bool,
|
just_modules: bool,
|
||||||
) -> Vec<CompletionItem> {
|
) -> Vec<CompletionItem> {
|
||||||
let module_completions = imported_modules
|
let module_completions = imported_modules
|
||||||
|
@ -333,6 +335,7 @@ pub(super) fn get_module_completion_items(
|
||||||
.flat_map(|(mod_id, exposed_symbols)| {
|
.flat_map(|(mod_id, exposed_symbols)| {
|
||||||
let mod_name = mod_id.to_ident_str(interns).to_string();
|
let mod_name = mod_id.to_ident_str(interns).to_string();
|
||||||
|
|
||||||
|
//Completion for modules themselves
|
||||||
if mod_name.starts_with(&prefix) {
|
if mod_name.starts_with(&prefix) {
|
||||||
let item = CompletionItem {
|
let item = CompletionItem {
|
||||||
label: mod_name.clone(),
|
label: mod_name.clone(),
|
||||||
|
@ -342,12 +345,13 @@ pub(super) fn get_module_completion_items(
|
||||||
mod_id,
|
mod_id,
|
||||||
interns,
|
interns,
|
||||||
exposed_symbols,
|
exposed_symbols,
|
||||||
|
docs.get(mod_id),
|
||||||
modules_info,
|
modules_info,
|
||||||
)),
|
)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
vec![item]
|
vec![item]
|
||||||
//Complete dot completions
|
//Complete dot completions for module exports
|
||||||
} else if prefix.starts_with(&(mod_name + ".")) {
|
} else if prefix.starts_with(&(mod_name + ".")) {
|
||||||
get_module_exposed_completion(exposed_symbols, modules_info, mod_id, interns)
|
get_module_exposed_completion(exposed_symbols, modules_info, mod_id, interns)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use roc_load::docs::ModuleDocumentation;
|
||||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||||
|
|
||||||
use roc_types::subs::Variable;
|
use roc_types::subs::Variable;
|
||||||
|
@ -33,18 +34,30 @@ fn md_doc(val: String) -> Documentation {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
///Generates a nicely formatted block of text for the completionitem documentation field
|
///Generates a nicely formatted block of text for the completionitem documentation field
|
||||||
|
|
||||||
pub(super) fn module_documentation(
|
pub(super) fn module_documentation(
|
||||||
description_type: DescriptionsType,
|
description_type: DescriptionsType,
|
||||||
module_id: &ModuleId,
|
module_id: &ModuleId,
|
||||||
interns: &Interns,
|
interns: &Interns,
|
||||||
exposed: &[(Symbol, Variable)],
|
exposed: &[(Symbol, Variable)],
|
||||||
|
module_docs: Option<&ModuleDocumentation>,
|
||||||
modules_info: &ModulesInfo,
|
modules_info: &ModulesInfo,
|
||||||
) -> Documentation {
|
) -> Documentation {
|
||||||
let exposed_string =
|
let exposed_string =
|
||||||
module_exposed_list(module_id, interns, modules_info, exposed).unwrap_or_default();
|
module_exposed_list(module_id, interns, modules_info, exposed).unwrap_or_default();
|
||||||
|
let module_doc = module_docs
|
||||||
|
.and_then(|docs| {
|
||||||
|
docs.entries.first().and_then(|first_doc| match first_doc {
|
||||||
|
roc_load::docs::DocEntry::ModuleDoc(str) => Some(str.clone()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
match description_type {
|
match description_type {
|
||||||
DescriptionsType::Exposes => md_doc(format!("```roc\n{0}\n```", exposed_string)),
|
DescriptionsType::Exposes => md_doc(format!(
|
||||||
|
"{0}```roc\n{1}\n```",
|
||||||
|
module_doc + "\n",
|
||||||
|
exposed_string
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue