racket / scribble

Other
197 stars 90 forks source link

Add kind information to the index #328

Open sorawee opened 2 years ago

sorawee commented 2 years ago

This PR creates a new index description exported-index-desc* that contain the kind information. This allows e.g. the search page to display or refine the query based on the information.

To maintain backward compatibility, the kind information is not added to any existing structs. Instead, a new index type is created.

The contract for the kind field is (listof string? (list/c 'code string?)). This rich encoding allows typesetting search results like https://docs.racket-lang.org/search/index.html?q=get-admin

Also bump the version, to be used for #:version in other info.rkt

Original PR description is preserved here:

This PR creates new index types that contain the kind information.
This allows e.g. the search page to display or refine the query
based on the information.

Only `form-index-desc`, `procedure-index-desc`, and `thing-index-desc`
are considered, because they are the only ones that currently
allow kind customization. Other indices are already too specific
(e.g. `mixin`, `struct`), so there seems to be no point to allow
customization in such cases. On the other hand, newer forms
that need the kind customization probably should just use
`thing-index-desc(*)`, similar to how the Rhombus documentation
is currently doing.

To maintain backward compatability, the kind information is not added to
any existing structs. Instead, new index types are created at the leaf
level of the index description hierarchy.

It's unclear what the contract of the kind information should be.
Currently, it is `string?`. Here are some other possibilities

- `(or/c string? #f)`: this allows the information to be left out.
  However, I think that anything indexed with form, proc, or thing
  should mandate the kind information, because they default to
  "syntax", "procedure", or "value", so they are already non-empty.
  If one wishes to leave the information out, they can use
  `exported-index-desc` directly (this is what the `syntax/parse`
  library does).

- `xexpr?`: this allows richer encoding. In particular,
  `method-index-desc` currently displays information like
  "get-admin (method of editor<%>)" on the search page.
  This "(method of editor<%>)" is ad-hoc inserted and
  "editor%" is typeseted differently than "method of".
  The idea of `xexpr?` is to make it general enough to typeset
  "(method of editor<%>)" under one single framework,
  without special-casing `method-index-desc` and also allow
  this flexible customization for non-methods.

  On the other hand, allowing `xexpr?` could introduce vulnerabilities
  like HTML injection. We could constrain it, but that seems
  like too much work. So I think continuing to
  special-casing `method-index-desc` might be better.

Therefore, I'm sticking with `string?` for now, until we figure out a
better solution. However, it should be noted that further modification
will risk breaking backward compatibility.

Also bump the version, to be used for `#:version` in other `info.rkt`
samth commented 2 years ago

How about (or/c string? (listof (or/c string? <something that indicates a link>)))?

samth commented 2 years ago

How does this fit with the index function?

sorawee commented 2 years ago

I didn't modify that at all, so they are completely unaffected.

An index-element consists of tag, plain-seq, entry-seq, and desc. This PR does not modify this structure, but it creates a new kind of desc to replace form-index-desc, procedure-index-desc, and thing-index-desc. Other descs like tech (produced by deftech), (part-index-desc) (produced by section), and #f (probably produced by index) are left untouched.

sorawee commented 2 years ago

How about (define kind/c (listof (or/c string? (list/c 'code string?))))?

I don't want to or/c with string? at the outermost level. It's already too complicated.

sorawee commented 2 years ago

Oh, another possibility is to create exported-index-desc* and replace all existing form-index-desc, procedure-index-desc, and thing-index-desc with exported-index-desc*. That way, we only need to create one more struct, not three.

samth commented 2 years ago

I think if we're now using the desc in more ways, we want to provide control over it from functions like index.

sorawee commented 2 years ago

Are you thinking about making the below search result show more information?

Screen Shot 2022-05-27 at 4 44 54 PM

I agree that could be helpful, but my opinion is that it is out of scope for this PR. This current PR is already large. I'd deal with index / deftech / section / etc. separately.

sorawee commented 2 years ago

By the way, I switched to exported-index-desc* as I mentioned above. I think it's an improvement, but it also lost some useful information (though this information is currently not utilized anyway). Let me know if you have a better idea.

sorawee commented 2 years ago

It is already the case that kind can be any content? according to the doc of defproc, so restricting it to string? or (listof (or/c string? (list/c 'code string?))) doesn't seem to be a good idea.

samth commented 2 years ago

I'm thinking that I'd like the new index entries I added for match (eg app) to mention match in the search results.

sorawee commented 2 years ago

Perhaps we want to keep track of three information:

  1. kind: this is a content? that will appear directly in the box.
  2. kind-detail: this is a content? that will appear as a search entry. The intention is that it is as detailed as kind, if not more.
  3. kind-id: probably a string, though a symbol could work as well. The intention is that this will be used programmatically for recognization.

For example, a method would have kind being "method", kind-detail being "method of dc%", and kind-id being "method" (or something similar to this).

By default, kind-detail is kind, and kind-id is (content->string kind).

racket-discourse-github-bot commented 1 year ago

This pull request has been mentioned on Racket Discussions. There might be relevant details there:

https://racket.discourse.group/t/rfc-hash-table-pattern-matching/1686/59