[m-rev.] for review: Add web browser-based term browsing in the debugger.

Peter Wang novalazy at gmail.com
Thu Aug 17 11:14:20 AEST 2017


On Thu, 17 Aug 2017 07:02:22 +1000, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
> 
> > +save_and_browse_browser_term_web(Term, OutStream, ErrStream, State, !IO) :-
> > +    get_mdb_dir(MaybeMdbDir, !IO),
> > +    (
> > +        MaybeMdbDir = yes(MdbDir),
> > +        MaybeBrowserCmd = State ^ web_browser_cmd,
> > +        (
> > +            MaybeBrowserCmd = yes(BrowserCmd),
> > +            io.get_temp_directory(TmpDir, !IO),
> > +            io.make_temp_file(TmpDir, "mdb", ".html", TmpResult, !IO),
> > +            (
> > +                TmpResult = ok(TmpFileName0),
> > +                ( if string.suffix(TmpFileName0, ".html") then
> > +                    TmpFileName = TmpFileName0
> > +                else
> > +                    % Work around io.make_temp_file ignoring suffix.
> > +                    io.remove_file(TmpFileName, _, !IO),
> > +                    TmpFileName = TmpFileName0 ++ ".html"
> > +                ),
> > 
> 
> The two paths in the last if-then-else differ in whether they leave
> around a file named TmpFileName. Is that OK?

Yes, but I meant to remove TmpFileName0.

> > +            MaybeBrowserCmd = no,
> > +            io.write_string(ErrStream, "mdb: You need to issue a " ++
> > +                "\"web_browser_cmd '<command>'\" command first.\n", !IO)
> 
> I would reword that as “mdb: You first need to specify the shell command that
> launches your preferred browser, by issuing an mdb command such as web_browser_cmd
> firefox” (with appropriate quoting).

Reworded.

> > +browser_term_to_html_flat_string(BrowserTerm, Str, Elided, !IO) :-
> > +    % Mimic portray_flat. We can afford larger sizes in a web browser due to
> > +    % proportional fonts and horizontal scrolling.
> > +    MaxTermSize = 120,
> > +    browser_term_size_left_from_max(BrowserTerm, MaxTermSize, RemainingSize),
> > +    ( if RemainingSize >= 0 then
> > +        portray_flat_write_browser_term(string.builder.handle, BrowserTerm,
> > +            string.builder.init, State),
> > +        Str = to_string(State),
> > +        Elided = no
> > +    else
> > +        io.get_stream_db(StreamDb, !IO),
> > +        BrowserDb = browser_db(StreamDb),
> > +        MaxSize = 10,
> > +        MaxDepth = 5,
> > +        browser_term_to_string(BrowserDb, BrowserTerm, MaxSize, MaxDepth, Str),
> > +        Elided = yes
> > +    ).
> > 
> 
> These seem awfully small limits for a browseable term. Printing small terms
> can be done perfectly well already; I, personally, would want to launch a browser
> only on terms too big to look at with the existing tools.

This predicate is only used to produce the single-line summary of each
sub-term when its node in the tree view is closed. The idea is to show
sub-terms in full on a single line when possible, to avoid expanding
them. We can change the numbers after we have more experience with the
term browser, if necessary.

BTW, we manage to hit some recursion limit in the browser's JavaScript
parser/interpreter if trying to browse very deeply nested data structures,
such as exist in the compiler. I will look into it when I can.

> > +% Helpers for writing out JavaScript values within an HTML <script> element.
> > +% We do not generate indented output because we may need to write large,
> > +% deeply nested terms quickly, and have the web browser parse the file as
> > +% quickly as possible.
> > 
> 
> “and WE WANT the web browser TO parse …”

Changed.

Thanks.

Peter


More information about the reviews mailing list