Support doc query - #85
Conversation
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
|
That's a good idea to include the source line
This made me thing that "endLine" could probably also be useful. I imagine, an LLM would want to read the actual definition of some symbol, in that case it could issue a "read" command with the begin and end lines to read only a slice of a file. |
There was a problem hiding this comment.
Does --query work only with --format json?
If so, then you essentially give only two options:
- "--query --format json"
- "--format html" and no
--query(or is it permitted and ignored?)
Thus you could simplify the API to accept either --query and then output json or no --query and output HTML and require --out, and you don't need the --format parameter.
Additionally, I am not sure --query is needed. If you output all available symbols in JSON format to stdout, and especially in JSONL (i.e., just a stream of json objects, rather than a JSON array), then the consumer can use a plethora of standard tools to filter/query/transform the json on-the-fly. For example they could use jq to select the symbol of interest and discard the rest.
Having your own query means you have to implement and explain the query language, and if it is even slightly non-trivial it means headache for the users to learn it and use correctly.
| is just an ordinary symbol query. A query may omit positional source files; in | ||
| that case it searches the loaded SAST libraries, including stdlib unless | ||
| `--no-stdlib` is set and any `--lib` paths. | ||
|
|
There was a problem hiding this comment.
This is a bit of a ranaway sentence. If I understood it correctly, here is how I would make it easier to read:
| is just an ordinary symbol query. A query may omit positional source files; in | |
| that case it searches the loaded SAST libraries, including stdlib unless | |
| `--no-stdlib` is set and any `--lib` paths. | |
| is just an ordinary symbol query. A query may omit positional source files; in | |
| that case it searches any `--lib` paths and the loaded SAST libraries (including stdlib unless | |
| `--no-stdlib` is set). | |
But correct me if I misunderstood it.
| Without `--query`, JSON output contains the public API surface from the | ||
| positional source files. With `--query`, selectors are comma-separated and may | ||
| name symbols or source files with `file:<path>`. | ||
| Symbol selectors are resolved from the language default scope; for example `~` |
There was a problem hiding this comment.
what is ~ symbol? It looks like some kind of special symbol. Is it actually a Jo operator ~? If so, it is a confusing example for the documentation.
There was a problem hiding this comment.
Yes, it's a little confusing, I'll remove it. ~ is defined in standard library:
val x = 3 ~ "a"
val y = "a" ~ 4 ~ 6
val a ~ b = x
val c ~ h ~ w = y
| | Selector | Meaning | | ||
| |----------|---------| | ||
| | `<symbol>` | Symbol resolved from the language default scope. Aggregate symbols are emitted structurally with their members. | | ||
| | `file:<path>` | Queryable symbols whose source file matches the path. | |
There was a problem hiding this comment.
Do you have a use case in mind for the file:<path> selector? Can't the same be achieved by providing just the <path> as the compilation target?
I would err on the simplicity side adding things only if they have a use case.
| println(" --out <dir> Output directory (default: docs)") | ||
| println(" --title <name> Project title for documentation") | ||
| println(" --format <html|json> Output format (default: html)") | ||
| println(" --query <selectors> JSON selectors, e.g. jo.py,file:src/API.jo") |
There was a problem hiding this comment.
does jo.py refer to some jo symbol , or to a python file?
There was a problem hiding this comment.
jo.py is a symbolic selector, file:src/API.jo is a file selector.
There was a problem hiding this comment.
I think using a symbolic selector that resembles a file with a classic extension together with a file selector is confusing, especially for people that are not aware that jo.py exists in the jo library.
This is a good point, given that The only case where Currently, it kind of works as you mentioned: if
The reason why In addition, without --query, it's not clear how to support a simple use case like the following: |
Sure, but it invites confusion. As a language designer you should know that a better designed language makes something inexpressible rather than simply forbidden at compile or at runtime. CLI is a form of a language, so making unwanted things inexpressible also plays in its favor.
Indeed it is large by default, but there is always
Here is how I would do that in shell (note that I cannot avoid jo compile --doc --query jo.List | jq '.. | objects | select(.name == "jo.List.map")'Or, what is more likely, I (or LLM) would invoke As an aside,
BTW should jo/docs/usage/commands/doc.md also mention this new mode? |
Yes, we can go even further here to decouple the
I think For normal compilation, standard library is indispensable.
This is painful, I never remember the syntax of
This is a bug, I'll investigate.
|
|
My use case: retriever all the symbols defined in a file and their doc string (#84 ). Does this implementation support it? |
Luckily we have LLMs for that now.
You can implement a separate I think adding a query language before anyone asks for it is premature, but I do not insist, as long as it does not get in the way. |
I am speaking only about documentation extraction. |
If the namespace of the file is know, it can be done by querying the namespace symbol. Otherwise, query with the file name |
|
I think "query language" is not an accurate characterization: it's just an input format. If a user or LLM wants to know the interface of String, it simply queries I'm not sure how to tell whether something is "premature" or not. But as principled design we never take a requirement at its surface value and for information-retrival interface, narrowing/querying is essential IMHO. |
Here is how I tried to do it: |
Then you can add an equivalent for docs. e.g. |
That won't work, because without standard library, it is impossible generate docs. |
Fix #84 : Support doc query
Summary
Support query symbol information from command line:
It outputs
[ { "name": "jo.List.map", "kind": "def", "signature": "def map[S](f: T => S receives none): List[S] receives none", "source": { "file": "lib/List.jo", "line": 162 }, "visibility": "public", "flags": ["loaded", "fun", "method"], "annotations": [], "doc": "Apply `f` to each element and return the resulting list." } ]It is also possible to filter by file name:
Only symbols defined in the specified will be included.
Checklist
tests/pos/ortests/warn/How to sign off commits
Use
git commit -sto add theSigned-off-byline automatically:To add a sign-off to the last commit retroactively:
To add sign-off to the last 3 commits:
Security impact
No
Compatibility impact
No