Bug 54822 - Web Inspector: generate protocol documentation based on IDL.
Summary: Web Inspector: generate protocol documentation based on IDL.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-20 04:41 PST by Pavel Feldman
Modified: 2011-02-21 05:35 PST (History)
10 users (show)

See Also:


Attachments
Patch (15.18 KB, patch)
2011-02-20 04:45 PST, Pavel Feldman
yurys: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Feldman 2011-02-20 04:41:56 PST
IDL is the best source of the protocol information as of today. We should gen some docs out of it. Patch to follow, it generates something like: https://sites.google.com/site/webinspectorprotocol/
Comment 1 Pavel Feldman 2011-02-20 04:45:10 PST
Created attachment 83092 [details]
Patch
Comment 2 Alexander Pavlov (apavlov) 2011-02-20 06:20:36 PST
Comment on attachment 83092 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=83092&action=review

> Source/WebCore/inspector/CodeGeneratorInspector.pm:528
> +    push(@lines, "    seq: number,");

should be <number> for consistency
Comment 3 Ilya Tikhonovsky 2011-02-20 07:54:35 PST
Comment on attachment 83092 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=83092&action=review

> Source/WebCore/inspector/CodeGeneratorInspector.pm:394
> +{
> +    my $interface = shift;
> +    my $function = shift;
> +
> +    my $functionName = $function->signature->name;
> +    my $domain = $interface->name;
> +
> +    my @argsFiltered = grep($_->direction eq "out", @{$function->parameters});
> +
> +    my @lines;
> +    push(@lines, "<h4>" . $interface->name . "." . ${functionName} . "</h4>");
> +    my $doc = $function->signature->extendedAttributes->{"doc"};
> +    if ($doc) {
> +        push(@lines, $doc);
> +    }
> +
> +    push(@lines, "<pre style='background: lightGrey; padding: 10px'>");
> +    push(@lines, "{");
> +    push(@lines, "    seq: &lt;number&gt;,");
> +    push(@lines, "    type: \"event\",");
> +    push(@lines, "    domain: \"$domain\",");
> +    if (scalar(@argsFiltered)) {
> +        push(@lines, "    event: \"${functionName}\",");
> +        push(@lines, "    data: {");
> +        my @parameters;
> +        foreach my $parameter (@argsFiltered) {
> +            push(@parameters, "        " . parameterDocLine($parameter));
> +        }
> +        push(@lines, join(",\n", @parameters));
> +        push(@lines, "    }");
> +    } else {
> +        push(@lines, "    event: \"${functionName}\"");
> +    }
> +    push(@lines, "}");
> +    push(@lines, "</pre>");
> +    push(@documentationLines, @lines);
> +}

Please use inline text. It is significantly increasing readability.

> Source/WebCore/inspector/CodeGeneratorInspector.pm:546
> +

ditto
Comment 4 Pavel Feldman 2011-02-20 09:37:48 PST
> > +}
> 
> Please use inline text. It is significantly increasing readability.
> 
> > Source/WebCore/inspector/CodeGeneratorInspector.pm:546
> > +
> 
> ditto

I tried that, but it made readability worse. Reason is that there are several conditions / loops that don't work well in combination with text chunks.
Comment 5 Patrick Mueller 2011-02-20 10:34:27 PST
I generate "protocol docs" for weine as well - I have some of my own IDL as well as (obviously) reuse Inspector.idl.  Rather than generate HTML, I generate JSON.  I then have some JS code which generates HTML for the protocol doc.  I reuse the same JSON in weinre as well - to generate proxies, etc.

Current version, which I think matches the current IDL, is here:

    https://github.com/pmuellr/weinre/blob/develop/weinre.build/scripts/simple-idl2json.py
Comment 6 Pavel Feldman 2011-02-20 11:12:49 PST
(In reply to comment #5)
> I generate "protocol docs" for weine as well - I have some of my own IDL as well as (obviously) reuse Inspector.idl.  Rather than generate HTML, I generate JSON.  I then have some JS code which generates HTML for the protocol doc.  I reuse the same JSON in weinre as well - to generate proxies, etc.
> 
> Current version, which I think matches the current IDL, is here:
> 
>     https://github.com/pmuellr/weinre/blob/develop/weinre.build/scripts/simple-idl2json.py

IDL is extremely limited in terms of markup for documentation generation. I'd much rather have JSON as a source for both generated code and the documentation. We only use IDL for historical reasons + IDLParser is a part of the build on all ports. If we figure out how to run JavaScript in the build, we will be able to use JSON source.
Comment 7 Yury Semikhatsky 2011-02-21 02:57:14 PST
Comment on attachment 83092 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=83092&action=review

>> Source/WebCore/inspector/CodeGeneratorInspector.pm:394
>> +}
> 
> Please use inline text. It is significantly increasing readability.

I second this comment.

> Source/WebCore/inspector/CodeGeneratorInspector.pm:521
> +        push(@lines, "    command: \"${functionName}\"");

This line can be pulled out  of the if block.
Comment 8 Pavel Feldman 2011-02-21 03:03:40 PST
Committed r79204: <http://trac.webkit.org/changeset/79204>
Comment 9 Patrick Mueller 2011-02-21 05:35:15 PST
(In reply to comment #6)
> IDL is extremely limited in terms of markup for documentation 
> generation. I'd much rather have JSON as a source for both 
> generated code and the documentation. We only use IDL for 
> historical reasons + IDLParser is a part of the build on all ports.

I'm somewhat surprised to find that I actually like the IDL format.  
It's fairly concise, and turns out to be easy to parse.  I especially
like the trick of denoting call back parms as "out" parameters.

Although I love JSON as a transportable data structure format, I
really dislike writing it, and even reading it is kinda distasteful 
(this will change when there's a nice JSON viewer in all my "IDEs").

But it wouldn't be the end of the world for me if we switched to JSON.

> If we figure out how to run JavaScript in the build, we will be 
> able to use JSON source.

Well, WebKit nightlies build "jsc" (or they used to, or they can).  
Perhaps v8-based builds could be convinced to build a similar CLI, and 
we could parameterize the name of the executable.

But really, a lot of languages can read JSON.  Can't remember which
version of Python shipped JSON built-in, or the lowest level of Python
the night build requires.  But it turns out, for Python, JSON 
structures are also legal Python literals, so you can just eval() them 
anyway.

There's no reason to wait for a JavaScript interpreter if you want to
switch from IDL to JSON.  And if you're writing something new, I vote
for Python over Perl.