mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 12:46:43 +00:00
feat: check variable type annotations in docstring (#681)
* feat: check variable type annotations in docstring * dev: rollback playground changes * dev: refactor a bit
This commit is contained in:
parent
4aeb3747bc
commit
c17e0c787e
22 changed files with 312 additions and 107 deletions
|
|
@ -59,6 +59,8 @@ impl From<(PathBuf, PackageSpec)> for PackageInfo {
|
|||
pub enum DocStringKind {
|
||||
/// A docstring for a function.
|
||||
Function,
|
||||
/// A docstring for a variable.
|
||||
Variable,
|
||||
}
|
||||
|
||||
/// Docs about a symbol.
|
||||
|
|
@ -428,7 +430,7 @@ pub(crate) fn convert_docs(world: &LspWorld, content: &str) -> StrResult<EcoStri
|
|||
fn identify_docs(kind: &str, content: &str) -> StrResult<Docs> {
|
||||
match kind {
|
||||
"function" => identify_func_docs(content).map(Docs::Function),
|
||||
"variable" => identify_tidy_var_docs(content).map(Docs::Variable),
|
||||
"variable" => identify_var_docs(content).map(Docs::Variable),
|
||||
"module" => identify_tidy_module_docs(content).map(Docs::Module),
|
||||
_ => Err(eco_format!("unknown kind {kind}")),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ pub fn identify_func_docs(converted: &str) -> StrResult<TidyFuncDocs> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn identify_tidy_var_docs(converted: &str) -> StrResult<TidyVarDocs> {
|
||||
pub fn identify_var_docs(converted: &str) -> StrResult<TidyVarDocs> {
|
||||
let lines = converted.lines().collect::<Vec<_>>();
|
||||
|
||||
let mut return_ty = None;
|
||||
|
|
@ -232,7 +232,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn var(s: &str) -> String {
|
||||
let f = super::identify_tidy_var_docs(s).unwrap();
|
||||
let f = super::identify_var_docs(s).unwrap();
|
||||
let mut res = format!(">> docs:\n{}\n<< docs", f.docs);
|
||||
if let Some(t) = f.return_ty {
|
||||
res.push_str(&format!("\n>>return\n{t}\n<<return"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue