Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kind information to the index #328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

sorawee
Copy link
Contributor

@sorawee sorawee commented May 27, 2022

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`

sorawee added a commit to sorawee/racket that referenced this pull request May 27, 2022
sorawee added a commit to sorawee/racket2-rfcs that referenced this pull request May 27, 2022
This depends on racket/scribble#328
and will be effectively used by racket/racket#4263
@samth
Copy link
Sponsor Member

samth commented May 27, 2022

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

@samth
Copy link
Sponsor Member

samth commented May 27, 2022

How does this fit with the index function?

@sorawee
Copy link
Contributor Author

sorawee commented May 27, 2022

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
Copy link
Contributor Author

sorawee commented May 27, 2022

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
Copy link
Contributor Author

sorawee commented May 27, 2022

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
Copy link
Sponsor Member

samth commented May 27, 2022

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

@sorawee
Copy link
Contributor Author

sorawee commented May 27, 2022

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
Copy link
Contributor Author

sorawee commented May 27, 2022

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
Copy link
Contributor Author

sorawee commented May 28, 2022

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
Copy link
Sponsor Member

samth commented May 28, 2022

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
Copy link
Contributor Author

sorawee commented Jun 17, 2022

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).

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 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`
@racket-discourse-github-bot

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

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.

None yet

3 participants