jazzy icon indicating copy to clipboard operation
jazzy copied to clipboard

ObjC enum cases can have wrong doc comment

Open herzi opened this issue 7 years ago • 12 comments

I have an enum type with 90%+ if the enum values being very self-explanatory, so I only documented the important ones like this:

/// This is a good type.
typedef NS_ENUM(NSInteger, MyEnum) {
    // This is completely self-explanatory and thus, won't get a doc-comment.
    MyEnumFirst,
    /// This is a very special second value.
    MyEnumSecond,
    // This one, again, is self-explanatory.
    MyEnumThird
};

This leads to the following doc-comments in generated HTML:

  • MyEnum: This is a good type.
  • MyEnumFirst: Undocumented.
  • MyEnumSecond: This is a very special second value.
  • MyEnumThird: This is a very special second value.

Now I have to add /// Undocumented. to MyEnumThird in order to obtain the expected behavior.

(Jazzy 0.7.0 installed with gem.)

herzi avatar Jul 12 '16 15:07 herzi

Even I have experience the same. Is there a quick fix by changing the documentation.

/// Account level
typedef NS_ENUM(NSInteger, AccountLevel) {
    /// Low
    AccountLevelLow = 0,
    /// Medium
    AccountLevelMedium,
    /// High
    AccountLevelHigh,
};

it produces wried documentation. Is there any mistake in above comments? I tried both C enums & Objective C enums but both have same results.

shahdhiren avatar Jun 15 '17 11:06 shahdhiren

@shahdhiren what are you seeing wrong with jazzy's rendering of the code above? It looks OK to me I think (latest jazzy 0.8.2)?

The problem covered by this issue - undocumented enum cases get the previous doc comment - is a libclang bug/feature, best to work around it as you've done.

johnfairh avatar Jun 17 '17 13:06 johnfairh

Please see below Enum file that I have. It contains 3 enums where 2 enums are documented fully whereas 1 enum is partially documented.

/// Level
typedef NS_ENUM(NSInteger, Level) {
    /// Low
    Low = 0,
    /// Medium
    Medium,
    /// High
    High,
};

///Status
typedef NS_ENUM(NSInteger, Status) {
    /// INDETERMINATE
    INDETERMINATE = -1,
    /// REGISTERED
    REGISTERED = 0,
    /// VERIFIED
    VERIFIED = 1,
    /// ENROLLED
    ENROLLED = 2,
};

/// Types
typedef NS_ENUM(NSInteger, Types) {
    Type1,
    Type2,
    Type3,
    Type4,
};

Note I am testing on latest Jazzy v0.9.4 (1 Nov release)

shahdhiren avatar Dec 11 '18 08:12 shahdhiren

Also, one observation is that enums are considered as Functions in objective c and hence in documentation I can see below thing as Link instead of actual enum name:

screen shot 2018-12-11 at 1 45 51 pm

shahdhiren avatar Dec 11 '18 08:12 shahdhiren

@shahdhiren as I tried to say above, the issue whereby undocumented C enum cases get the previous doc comment is a libclang bug/feature that you need to work around.

NS_ENUM showing up as a function means that Foundation has not been imported properly by your build incantation meaning the compiler does not know that NS_ENUM is not a function.

johnfairh avatar Dec 22 '18 18:12 johnfairh

NS_ENUM still being showed as functions, even though Foundation is imported.

@import Foundation;

rodmaz avatar Feb 07 '20 18:02 rodmaz

If you post your code then I can take a look, but as far as I know this really does mean that foundation is not being imported properly at build time.

eg, Xcode 11.3/11.4b with test.h:

@import Foundation;

/// Types
typedef NS_ENUM(NSInteger, Types) {
    Type1,
    Type2,
};

...and jazzy --objc --umbrella-header test.h gives:

Screenshot 2020-02-07 at 18 39 44

johnfairh avatar Feb 07 '20 19:02 johnfairh

@johnfairh Not what I am seeing here.

@import Foundation;

/// AureaLogLevel
typedef NS_ENUM(NSUInteger, AureaLogLevel) {
    /**
     No logging enabled.
     */
    AureaLogLevelOff = 0,
    
    /**
     Log level *Error*.
     */
    AureaLogLevelError,
    
    /**
     Log level *Warn*.
     */
    AureaLogLevelWarn,
    
    /**
     Log level *Info*.
     */
    AureaLogLevelInfo,
    
    /**
     Log level *Debug*.
     */
    AureaLogLevelDebug,
    
    /**
     Log level *Verbose*.
     */
    AureaLogLevelVerbose
};
Screen Shot 2020-02-11 at 12 41 39

I am getting however the following warnings, which may ring a bell:

using sysroot for 'MacOSX' but targeting 'iPhone' [-Wincompatible-sysroot]

xxxxx/Headers/AureaManager.h:23:9: fatal error: module 'UIKit' not found

Found conflicting type declarations with the same name, which may indicate a build issue or a bug in Jazzy: constant NSString, constant NSString, constant NSString, constant NSString, constant NSString, constant NSString

Found conflicting type declarations with the same name, which may indicate a build issue or a bug in Jazzy: function NS_ENUM, function NS_ENUM, function NS_ENUM, function NS_ENUM

Found conflicting type declarations with the same name, which may indicate a build issue or a bug in Jazzy: unexposed , unexposed , unexposed , unexposed 

rodmaz avatar Feb 11 '20 15:02 rodmaz

Ok good, so those first two are compiler errors (from clang) resulting in foundation not being pulled in, causing the enum problem & the last three errors (from jazzy). You'll need to work through fixing the compiler errors. I'm not an objc developer but I guess you're missing --sdk iphonesimulator or something, just by reading what it says?

johnfairh avatar Feb 11 '20 16:02 johnfairh

SDK (--sdk iphoneos) was indeed missing. Thanks. However the problems continue:

Headers/AureaManager.h:23:9: fatal error: could not build module 'UIKit'

Found conflicting type declarations with the same name, which may indicate a build issue or a bug in Jazzy: constant NSString, constant NSString, constant NSString, constant NSString, constant NSString, constant NSString

Found conflicting type declarations with the same name, which may indicate a build issue or a bug in Jazzy: function NS_ENUM, function NS_ENUM, function NS_ENUM, function NS_ENUM

Found conflicting type declarations with the same name, which may indicate a build issue or a bug in Jazzy: unexposed , unexposed , unexposed , unexposed 

This is really messy as those examples in README.md also show some cryptic configuration w/o any explanation what these parameters mean (eg. AFNetworking does such...) and some do not even seem to work.

I just tried to add this parameter below:

--xcodebuild-arguments '-project,AureaFramework.xcodeproj,-scheme,AureaFramework' 

And now I got an error:


Showing Recent Messages
Unrecognized arguments: -project, -schem

/Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/lib/jazzy/executable.rb:36:in `execute_command': /Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/bin/sourcekitten ["doc", "-project", "AureaFramework.xcodeproj", "-scheme", "AureaFramework"] (RuntimeError)



Unrecognized arguments: -project, -schem

	from /Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/lib/jazzy/sourcekitten.rb:266:in `run_sourcekitten'

	from /Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/lib/jazzy/doc_builder.rb:78:in `block in build'

	from /Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/lib/jazzy/doc_builder.rb:76:in `chdir'

	from /Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/lib/jazzy/doc_builder.rb:76:in `build'

	from /Library/Ruby/Gems/2.6.0/gems/jazzy-0.13.1/bin/jazzy:15:in `<top (required)>'

	from /usr/local/bin/jazzy:23:in `load'

	from /usr/local/bin/jazzy:23:in `<main>'

rodmaz avatar Feb 11 '20 17:02 rodmaz

Try --sdk iphonesimulator (if I do --sdk iphoneos I get your problem!)

The objc side uses libclang, not xcodebuild, so trying to pass stuff like -scheme won't work.

johnfairh avatar Feb 11 '20 17:02 johnfairh

Bingo! Now it works fine. Thanks a lot!

rodmaz avatar Feb 11 '20 17:02 rodmaz