Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add per-query JSON output for identifier, function, and file queries#81

Open
Darsh-14 wants to merge 1 commit into
dspinellis:masterfrom
Darsh-14:master
Open

Add per-query JSON output for identifier, function, and file queries#81
Darsh-14 wants to merge 1 commit into
dspinellis:masterfrom
Darsh-14:master

Conversation

@Darsh-14
Copy link
Copy Markdown
Contributor

@Darsh-14 Darsh-14 commented Feb 26, 2026

Fixes #35

Adds a json=1 URL parameter to the identifier, function, and file query pages. When set, the server returns structured JSON instead of HTML. The existing HTML output path is unchanged.

Changes

  • Add get_display_name() overloads for IdPropElem and Call used in JSON serialisation
  • Add json_output parameter to display_sorted(); emits a paginated JSON object with total, page_size, skip, and results fields
  • xfilequery_page: JSON branch with total counted after project filtering (not raw set size)
  • xiquery_page: guard html_head/html_tail and section headers with !json_output
  • xfunquery_page: guard html_head/html_tail, section headers, and display_sorted_function_metrics with !json_output
  • identifier_page: JSON output for id.html?json=1 : name, unused flag, xfile flag, occurrences, attributes, projects, locations
  • function_page: JSON output for fun.html?json=1 : name, type, call/caller counts, declaration and definition locations, metrics
  • Add JSON output checkbox to iquery_page, funquery_page, and filequery_page forms

Usage

From a browser: check the JSON output checkbox on any query form.

From a script or editor plugin:

curl 'http://localhost:8081/xiquery.html?writable=1&match=Y&qi=1&json=1'

Response:

{"total": 42, "page_size": 100, "skip": 0, "results": ["foo", "bar"]}

For identifier details:

curl 'http://localhost:8081/id.html?id=0x<ptr>&json=1'

Testing

Tested on the CScout test workspace (src/makecs.cs). JSON mode returns structured output with no HTML. Default HTML behaviour is unchanged.

@Darsh-14 Darsh-14 changed the title Add plain text output option for identifier and function queries Add per-query plain text output for identifier and function queries Feb 26, 2026
@Darsh-14
Copy link
Copy Markdown
Contributor Author

Darsh-14 commented Feb 26, 2026

@dspinellis I followed the hint in the issue and added the plain text option as a checkbox next to the query title field in the identifier, function, and file query forms. Does this approach align with what you had in mind?

@Darsh-14 Darsh-14 changed the title Add per-query plain text output for identifier and function queries Add per-query plain text output for all queries-- identifier, file and function Feb 26, 2026
@Darsh-14 Darsh-14 changed the title Add per-query plain text output for all queries-- identifier, file and function Add per-query plain text output for identifier, function, and file queries Feb 26, 2026
Copy link
Copy Markdown
Owner

@dspinellis dspinellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach. Please address the whitespace issue (see example in a comment), and resubmit a squashed commit.

Comment thread src/cscout.cpp Outdated
if (!query.is_valid())
return 0;
if (!query.is_valid())
return 0;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For historical reasons CScout employs tabs for indentation. Please refrain from changing them into spaces.

@dspinellis
Copy link
Copy Markdown
Owner

Thanks! Please squash the commits into a single one.

@Darsh-14
Copy link
Copy Markdown
Contributor Author

Darsh-14 commented Mar 1, 2026

@dspinellis Thank you for pointing that out sir. I've fixed the indentation to use tabs consistently throughout all added code and squashed everything into a single commit. Happy to contributing more to this project.

@Darsh-14
Copy link
Copy Markdown
Contributor Author

Darsh-14 commented Mar 1, 2026

@dspinellis Since we have two different approaches for the plain text output, which one would you prefer to implement in the upcoming plugin project as well?

Copy link
Copy Markdown
Owner

@dspinellis dspinellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please see comments.

Comment thread src/cscout.cpp Outdated
multiset <Fileid, FileQuery::specified_order> sorted_files;

html_head(of, "xfilequery", (qname && *qname) ? qname : "File Query Results");
if (!plain_text)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the guard in html_head.

Comment thread src/cscout.cpp Outdated
html_tail(of);
if (!plain_text) {
html_file_end(of);
pager.end();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a pager the plain text results can be excessive. Consider providing the results in JSON format together with paging information.

Comment thread src/cscout.cpp Outdated
"<th>Pre-cpp Value</th>"
"<th>Post-cpp Value</th>"
"</tr>\n");
"<th>Metric</th>"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I welcome these formatting fixes. Please submit them in a separate PR.

@Darsh-14
Copy link
Copy Markdown
Contributor Author

@dspinellis Thank you for the detailed feedback.

I will work on the changes in the following order:

  1. Submit the formatting fixes as a separate PR
  2. Move the plain_text guard inside html_head
  3. Replace plain text output with JSON format
    including paging information

I will update this PR accordingly.

@Darsh-14
Copy link
Copy Markdown
Contributor Author

@dspinellis I have addressed all the suggested review comments and implemented the changes as follows:

  1. Moved the plain_text guard inside html_head.
    html_head now accepts a bool plain_text parameter
    with default false and returns early if true, removing
    the need for external guards.

  2. Replaced plain text output with JSON format including
    paging information. The json=1 parameter now returns
    structured JSON with total, page_size, skip, and
    results fields. Page navigation uses the existing
    skip parameter consistent with CScout's pager.

  3. Submitted the formatting fixes in a separate PR Fix indentation of table headers in function and file metric pages #88 .

Happy to keep contributing and thanks for your feedback again.

@dspinellis
Copy link
Copy Markdown
Owner

dspinellis commented Apr 5, 2026

Please also address the merge conflicts and squash the commits into a single one for the particular change.

@Darsh-14
Copy link
Copy Markdown
Contributor Author

Darsh-14 commented Apr 5, 2026

.

Yes Sir, I'm on it. I'll get it resolved asap

@Darsh-14
Copy link
Copy Markdown
Contributor Author

Darsh-14 commented Apr 6, 2026

Please also address the merge conflicts and squash the commits into a single one for the particular change.

@dspinellis I have resolved the merge conflicts sir and all the commits are cleanly squashed into one. Happy to make any further changes if needed.

@Darsh-14 Darsh-14 changed the title Add per-query plain text output for identifier, function, and file queries Add per-query JSON output for identifier, function, and file queries Apr 19, 2026
@Darsh-14
Copy link
Copy Markdown
Contributor Author

@dspinellis Hello sir, I pushed an updated version. Addressed the paging concern by returning JSON with total, page_size, and skip fields. Also fixed a bug where total was counted before project filtering. Squashed to a single commit. Would appreciate another look when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GUI query option to output results as plain text

2 participants