zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
48.6k stars 2.9k forks source link

Support providing non-plaintext documents as Assistant contexts #18462

Open noamross opened 3 weeks ago

noamross commented 3 weeks ago

Check for existing issues

Describe the feature

It would be very helpful to be able to add common document files (e.g., PDFs, Word documents) to the assistant pane with /file contexts, as often there is documentation or other relevant information in them.

This could be partially supported with #17600, as one could run commands to extract plain text for documents (e.g., /terminal extract_text.sh myfile1.pdf myfile2.docx)

gwtaylor commented 1 week ago

I was going to open the same feature request, and I'm glad you beat me to it! For some context: I am a professor, and while I do write some code, the majority of development I am doing inside Zed is writing-related tasks, e.g. as Markdown, LaTex, or Plain Text. Often the context I want to include in the assistant pane with file is a PDF document (e.g. scientific papers). Let me share the workarounds I use now in case it is helpful to others:

notpeter commented 1 week ago

I was thinking about exactly this the other day, but you could implement this as a Slash Command Extension if you had a local endpoint that would take a https/file url as a parameter and return plaintext. It would be relatively trivial to whip up a Flask service which took a url as a parameter, fetched the file, spawned pdftotext and generated a response.

If you could do the file processing entirely in pure rust (no external commands, no filesystem, no C libs) it could compile to wasm so you could even skip the local server altogether. I did a poor mans version of this for cleaning up the plaintext of RFC text files for my RFC extension: notpeter/rfc-zed. It's nothing fancy, but it would a decent starting point if you wanted to build this. See rfc.rs.

gwtaylor commented 1 week ago

Thank you! Slash command extension is a great way to implement it and the RFC extension you shared is an excellent starting point.