Skip to content

Commit

Permalink
add support for @doc (hidden)
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Jan 28, 2025
1 parent 3ca906b commit 0cb41ab
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
8 changes: 6 additions & 2 deletions examples/class/inline-doc.ck
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ class Foo
{ }

// add inline documentation for variable
@doc "this here is a variable called Foo"
@doc "this here is a variable called varFoo"
5 => int varFoo;

// add inline documentation for variable
@doc "this here is a static variable called Bar"
@doc "this here is a static variable called varBar"
10 => static int varBar;

// add inline documentation for variable (but hide it)
@doc "(hidden) this variable is documented but hidden from ckdoc"
15 => static int varBarHidden;
}

// print runtime info about Foo...
Expand Down
6 changes: 6 additions & 0 deletions src/core/chuck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "chuck_symbol.h"
#include "chuck_vm.h"
#include "ugen_xxx.h"
#include "ulib_doc.h" // for CKDoc::shouldSkip()
#include "util_string.h"

#include <limits.h>
Expand Down Expand Up @@ -10881,6 +10882,9 @@ void Chuck_Type::apropos_funcs( std::string & output,
Chuck_Func * theFunc = *f;
// check for NULL
if( theFunc == NULL ) continue;
// check if should skip | 1.5.4.5 (ge)
if( CKDoc::shouldSkip(theFunc) ) continue;

// see if name appeared before
if( func_names.count(theFunc->name) )
{
Expand Down Expand Up @@ -11071,6 +11075,8 @@ void Chuck_Type::apropos_vars( std::string & output, const std::string & PREFIX,
if( value->name[0] == '@' ) continue;
// see if value is a function
if( value->func_ref ) continue;
// check if should skip | 1.5.4.5 (ge)
if( CKDoc::shouldSkip(value) ) continue;

// check for static declaration
if( value->is_static ) {
Expand Down
49 changes: 46 additions & 3 deletions src/core/ulib_doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,8 @@ string CKDoc::genType( Chuck_Type * type, t_CKBOOL clearOutput )
// value is a function
if( isa( value->type, value->type->env()->ckt_function ) )
continue;
// check if should skip | 1.5.4.5 (ge)
if( CKDoc::shouldSkip(value) ) continue;

// static or instance?
if( value->is_static ) svars.push_back( value );
Expand All @@ -1714,10 +1716,12 @@ string CKDoc::genType( Chuck_Type * type, t_CKBOOL clearOutput )
Chuck_Func * func = *f;

// check
if(func == NULL) continue;
if( func == NULL ) continue;
// check if should skip | 1.5.4.5 (ge)
if( CKDoc::shouldSkip(func) ) continue;

// if already seen (overloaded?)
if( func_names.count(func->name) )
continue;
if( func_names.count(func->name) ) continue;
// first one
func_names[func->name] = 1;
// static or instance?
Expand Down Expand Up @@ -1888,6 +1892,45 @@ string CKDoc::genType( Chuck_Type * type, t_CKBOOL clearOutput )



#define CKDOC_HIDDEN_STRING "(hidden)"
//-----------------------------------------------------------------------------
// name: shouldSkip()
// desc: whether to skip an entry in the final output | 1.5.4.5 (ge) added
//-----------------------------------------------------------------------------
t_CKBOOL CKDoc::shouldSkip( const std::string & docStr )
{
return docStr.find( CKDOC_HIDDEN_STRING ) != std::string::npos;
}




//-----------------------------------------------------------------------------
// name: shouldSkip()
// desc: whether to skip a function in the final output | 1.5.4.5 (ge) added
//-----------------------------------------------------------------------------
t_CKBOOL CKDoc::shouldSkip( const Chuck_Func * func )
{
if( !func ) return TRUE;
return func->doc.find( CKDOC_HIDDEN_STRING ) != std::string::npos;
}




//-----------------------------------------------------------------------------
// name: shouldSkip()
// desc: whether to skip an entry in the final output | 1.5.4.5 (ge) added
//-----------------------------------------------------------------------------
t_CKBOOL CKDoc::shouldSkip( const Chuck_Value * var )
{
if( !var ) return TRUE;
return var->doc.find( CKDOC_HIDDEN_STRING ) != std::string::npos;
}




//-----------------------------------------------------------------------------
// name: outputToDir()
// desc: generate everything as files into the output directory
Expand Down
10 changes: 10 additions & 0 deletions src/core/ulib_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ DLL_QUERY ckdoc_query( Chuck_DL_Query * QUERY );
// forward reference
struct Chuck_VM;
struct Chuck_Type;
struct ChucK_Func;
struct Chuck_Value;
struct CKDocGroup;
class CKDocHTMLOutput;

Expand Down Expand Up @@ -193,6 +195,14 @@ class CKDoc
// generate documentation for a single Type
std::string genType( Chuck_Type * type, t_CKBOOL clearOutput = TRUE );

public:
// whether to skip an entry in the final output | 1.5.4.5 (ge) added
static t_CKBOOL shouldSkip( const std::string & docStr );
// whether to skip a function in the final output | 1.5.4.5 (ge) added
static t_CKBOOL shouldSkip( const Chuck_Func * func );
// whether to skip an entry in the final output | 1.5.4.5 (ge) added
static t_CKBOOL shouldSkip( const Chuck_Value * var );

public:
// sort functions and variables | 1.5.2.5 (@kellyyyyyyyyyyyyyyyy @azaday) added
t_CKBOOL m_sort_entries;
Expand Down
4 changes: 4 additions & 0 deletions src/test/01-Basic/273-doc-describe.ck
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Foo
// add inline documentation for variable
@doc "this here is a static variable called Bar"
10 => static int varBar;

// add inline documentation for variable (but hide it)
@doc "(hidden) this variable is documented but hidden from ckdoc"
15 => static int varBarHidden;
}

// print runtime info about Foo...
Expand Down

0 comments on commit 0cb41ab

Please sign in to comment.