Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer from type statements #164

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions extractor/src/doc_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
tags::{validate_tags, Tag},
};
use full_moon::{
ast::{self, punctuated::Punctuated, Stmt},
ast::{self, luau::{TypeDeclaration, TypeInfo}, punctuated::Punctuated, Stmt},
node::Node,
};

Expand Down Expand Up @@ -40,6 +40,7 @@ enum DocEntryKind {
Type {
within: String,
name: String,
type_info: Option<TypeInfo>,
},
Class {
name: String,
Expand Down Expand Up @@ -101,12 +102,14 @@ fn get_explicit_kind(tags: &[Tag]) -> Result<Option<DocEntryKind>, Diagnostic> {
return Ok(Some(DocEntryKind::Type {
name: type_tag.name.as_str().to_owned(),
within: get_within_tag(tags, tag)?,
type_info: None,
}))
}
Tag::Interface(interface_tag) => {
return Ok(Some(DocEntryKind::Type {
name: interface_tag.name.as_str().to_owned(),
within: get_within_tag(tags, tag)?,
type_info: None,
}))
}
_ => (),
Expand Down Expand Up @@ -146,6 +149,26 @@ where
Ok(())
}

fn parse_type_declaration(
declaration: &TypeDeclaration,
doc_comment: &DocComment,
within_tag: Option<&crate::tags::WithinTag<'_>>
) -> Result<DocEntryKind, Diagnostic> {
let name = declaration.type_name().token().to_string();

let within = if let Some(within) = within_tag {
within.name.as_str().to_owned()
} else {
return Err(doc_comment.diagnostic("Type requires @within tag"));
};

Ok(DocEntryKind::Type {
name,
within,
type_info: Some(declaration.type_definition().to_owned()),
})
}

fn determine_kind(
doc_comment: &DocComment,
stmt: Option<&Stmt>,
Expand Down Expand Up @@ -307,6 +330,14 @@ fn determine_kind(
_ => Err(doc_comment.diagnostic("Expression must be a function")),
}
}
Some(Stmt::TypeDeclaration(declaration)) => {
parse_type_declaration(declaration, doc_comment, within_tag)
}
Some(Stmt::ExportedTypeDeclaration(export_declaration)) => {
let declaration = export_declaration.type_declaration();

parse_type_declaration(declaration, doc_comment, within_tag)
}

_ => Err(doc_comment
.diagnostic("Explicitly specify a kind tag, like @function, @prop, or @class.")),
Expand Down Expand Up @@ -445,14 +476,17 @@ impl<'a> DocEntry<'a> {
})?),
all_tags,
),
DocEntryKind::Type { within, name } => (
DocEntry::Type(TypeDocEntry::parse(DocEntryParseArguments {
within: Some(within),
name,
desc,
tags,
source: doc_comment,
})?),
DocEntryKind::Type { within, name , type_info} => (
DocEntry::Type(TypeDocEntry::parse(
DocEntryParseArguments {
within: Some(within),
name,
desc,
tags,
source: doc_comment,
},
type_info,
)?),
all_tags,
),
DocEntryKind::Class { name } => (
Expand Down
Loading
Loading