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

💡 Alternative Design Idea #6

Open
zicklag opened this issue May 20, 2021 · 5 comments
Open

💡 Alternative Design Idea #6

zicklag opened this issue May 20, 2021 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@zicklag
Copy link
Contributor

zicklag commented May 20, 2021

So I just had an idea that I might try out, but I figured I'd run by you to see what you think.

What if we just used rustdoc to generate the HTML file for the lib.rs file, and then parsed the HTML to modify the links to point to docs.rs. We might not even have to convert it to markdown because markdown does allow HTML inside it, as long as it doesn't do anything spooky.

Then we are depending on the reliability of rustdoc to actually generate the documentation and the links, knowing things like what's a struct, what's a method, and producing the proper struct.MyStruct.html style links instead of us having to use the search feature to find items.

@msrd0
Copy link
Owner

msrd0 commented May 20, 2021

and then parsed the HTML to modify the links to point to docs.rs

I was thinking about several solutions on how to get more reliable doc links. Using rustdoc might be one, but afaik rustdoc's output is not stable (I believe someone suggested rustdoc to output stuff in JSON format, but I don't think that's been implemented yet). Another idea I had was to utilize rust-analyzer to resolve all links, since it can probably tell us if the referenced item is a struct, enum, module etc. This is especially problematic for re-exports, as links like https://docs.rs/gotham/0.6.0/gotham/?search=gotham%3A%3Ahyper%3A%3AStatusCode are valid in rust, but not in rustdoc.

We might not even have to convert it to markdown because markdown does allow HTML inside it, as long as it doesn't do anything spooky.

I intially wanted to make the generated markdown file to contain mostly html, given that it's easier to place a closing tag than it is to insert newlines with correct indentation. However, some markdown renderers (I use grip for previewing) did not render markdown if it was not at least two lines away from any html tags in the same file. That's why I decided that it's a bad idea to output HTML by default, as it might mess with templates that use markdown syntax.

@zicklag
Copy link
Contributor Author

zicklag commented May 20, 2021

Using rustdoc might be one, but afaik rustdoc's output is not stable (I believe someone suggested rustdoc to output stuff in JSON format, but I don't think that's been implemented yet).

Ah, bummer that's a good point.

Another idea I had was to utilize rust-analyzer to resolve all links, since it can probably tell us if the referenced item is a struct, enum, module etc.

That sounds like a good idea. The IDE get's all of the information we need so it has to be able to provide what we're looking for. I think it's just a simple JSON RPC over stdout/stdin to use the rust-analyzer binary, too.

@msrd0
Copy link
Owner

msrd0 commented May 20, 2021

Do you want to work on this? I haven't looked into using rust-analyzer at all, it was just an idea I had once.

@zicklag
Copy link
Contributor Author

zicklag commented May 20, 2021

I might check it out, but not guarantees yet. I'll look at it and see if it might be simple.

@zicklag
Copy link
Contributor Author

zicklag commented May 22, 2021

I just verified that rust-analyzer is indeed a valid language server protocol ( LSP ) server which uses a JSON RPC over stdin and stdout. We should be able to interact with it simply by running the rust-analyzer command off of the system and sending/receiving JSON from it. I haven't tried it yet, but I think that we'd be able to use the workspace/symbol request and use the symbolKind field to get the info we need to construct accurate docs.rs links.

@msrd0 msrd0 added this to the 0.1.0 milestone Jun 18, 2021
@msrd0 msrd0 added the help wanted Extra attention is needed label Sep 1, 2021
@msrd0 msrd0 modified the milestones: 0.1.0, 0.2.0 May 19, 2022
@msrd0 msrd0 removed this from the 0.2.0 milestone Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants