Add per-query JSON output for identifier, function, and file queries#81
Add per-query JSON output for identifier, function, and file queries#81Darsh-14 wants to merge 1 commit into
Conversation
|
@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? |
dspinellis
left a comment
There was a problem hiding this comment.
I like the approach. Please address the whitespace issue (see example in a comment), and resubmit a squashed commit.
| if (!query.is_valid()) | ||
| return 0; | ||
| if (!query.is_valid()) | ||
| return 0; |
There was a problem hiding this comment.
For historical reasons CScout employs tabs for indentation. Please refrain from changing them into spaces.
|
Thanks! Please squash the commits into a single one. |
|
@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. |
|
@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? |
dspinellis
left a comment
There was a problem hiding this comment.
Thanks! Please see comments.
| multiset <Fileid, FileQuery::specified_order> sorted_files; | ||
|
|
||
| html_head(of, "xfilequery", (qname && *qname) ? qname : "File Query Results"); | ||
| if (!plain_text) |
There was a problem hiding this comment.
Consider adding the guard in html_head.
| html_tail(of); | ||
| if (!plain_text) { | ||
| html_file_end(of); | ||
| pager.end(); |
There was a problem hiding this comment.
Without a pager the plain text results can be excessive. Consider providing the results in JSON format together with paging information.
| "<th>Pre-cpp Value</th>" | ||
| "<th>Post-cpp Value</th>" | ||
| "</tr>\n"); | ||
| "<th>Metric</th>" |
There was a problem hiding this comment.
I welcome these formatting fixes. Please submit them in a separate PR.
|
@dspinellis Thank you for the detailed feedback. I will work on the changes in the following order:
I will update this PR accordingly. |
|
@dspinellis I have addressed all the suggested review comments and implemented the changes as follows:
Happy to keep contributing and thanks for your feedback again. |
|
Please also address the merge conflicts and squash the commits into a single one for the particular change. |
Yes Sir, I'm on it. I'll get it resolved asap |
@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. |
|
@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. |
Fixes #35
Adds a
json=1URL 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
get_display_name()overloads forIdPropElemandCallused in JSON serialisationjson_outputparameter todisplay_sorted(); emits a paginated JSON object withtotal,page_size,skip, andresultsfieldsxfilequery_page: JSON branch withtotalcounted after project filtering (not raw set size)xiquery_page: guardhtml_head/html_tailand section headers with!json_outputxfunquery_page: guardhtml_head/html_tail, section headers, anddisplay_sorted_function_metricswith!json_outputidentifier_page: JSON output forid.html?json=1: name, unused flag, xfile flag, occurrences, attributes, projects, locationsfunction_page: JSON output forfun.html?json=1: name, type, call/caller counts, declaration and definition locations, metricsiquery_page,funquery_page, andfilequery_pageformsUsage
From a browser: check the JSON output checkbox on any query form.
From a script or editor plugin:
Response:
{"total": 42, "page_size": 100, "skip": 0, "results": ["foo", "bar"]}For identifier details:
Testing
Tested on the CScout test workspace (
src/makecs.cs). JSON mode returns structured output with no HTML. Default HTML behaviour is unchanged.