Zulip Chat Archive

Stream: general

Topic: Call for help: Loogle in VS Code


Joachim Breitner (Oct 14 2023 at 13:12):

The loogle website is nice, and the bot a real gimmick, but it seems clear that the best UX is one where you don’t have to leave the editor while proving things.

My vague vision for this could be a key combo or button that adds a new panel to the side or bottom, with a search field highlighted. You type your query, it shows results as you type, and once you are happy you press Enter or so (maybe ↓ first a few times if it’s not the first hit) and the name is inserted into the document (or copied to the clipboard for convenient insertion). Especially a keyboard-only flow could be quite efficient and pleasant here!

I don’t think I’m the right person to do VS Code extensions (or extend existing extensions), so this is a call for help: Anyone here keen on implementing this feature? Happy to assist, advise and (I guess mostly) cheer!

Initially it might be easiest to use the JSON-API on loogle.lean-lang.org directly, eventually though it should use the #find command and cache that comes with your local mathlib installation (once that’s the case); maybe some of the code from the loogle CLI tool needs to move to mathlib (or std? or a mathlib dependency?). But that can follow later.

Shreyas Srinivas (Oct 14 2023 at 13:19):

I can try

Shreyas Srinivas (Oct 14 2023 at 13:19):

The second part could be hard. Could we add a #loogle command?

Shreyas Srinivas (Oct 14 2023 at 13:22):

Then it might be easier

Yaël Dillies (Oct 14 2023 at 13:30):

Do I get a feed of all the things people looked for in their vscode? :grinning_face_with_smiling_eyes:

Eric Rodriguez (Oct 14 2023 at 13:32):

Shreyas Srinivas said:

The second part could be hard. Could we add a #loogle command?

We are hoping to get it with the #find command when that is merged

Shreyas Srinivas (Oct 14 2023 at 13:40):

Where's the documentation for the loogle JSON API?

Joachim Breitner (Oct 14 2023 at 13:45):

Loogle is just a wrapper around #find (as proposed in https://github.com/leanprover-community/mathlib4/pull/6363), so that would be there. Feel free to experiment with that branch!

Joachim Breitner (Oct 14 2023 at 13:47):

The JSON “API” is a GET to https://loogle.lean-lang.org/json?q=Real.sin,tsum and you get JSON back. Happy to adjust if you need something else of course.

Joachim Breitner (Oct 14 2023 at 13:48):

Ah, I even mention this in the README at https://github.com/nomeata/loogle#web-service, so guess that counts as documentation :-D

Shreyas Srinivas (Oct 14 2023 at 13:48):

A follow up:
Is the output always like this: https://loogle.lean-lang.org/json?q=List+a+-%3E+List+a
Are there other fields?

Developing something that simply fetches results from loogle is _relatively_ simple. Accessing the cache when one is created might require knowing how the cache stores its information and where.

Shreyas Srinivas (Oct 14 2023 at 13:49):

In the long run you probably want it to be integrated with autocomplete, so you get suggestions on the spot.

Joachim Breitner (Oct 14 2023 at 13:52):

It's either error and suggestions, or it's hits, header and count

Joachim Breitner (Oct 14 2023 at 13:53):

All the cache handling would be handled by #find (via lake cache get), I'd expect a VS Code GUI that uses the local command to not worry about that.

Shreyas Srinivas (Oct 14 2023 at 14:26):

Does #find return a json? If not it would be much simpler to just query the online API.

Joachim Breitner (Oct 14 2023 at 14:40):

That's what I think too: start with the online API, and think about integration with a local installation (using a CLI tool, or a command and the LSP, or a local server) later.

Joachim Breitner (Oct 14 2023 at 14:41):

#find the command logs stuff to the info view, so that's obviously not great. The loogle CLI tool can return JSON.

Patrick Massot (Oct 14 2023 at 15:15):

Joachim, are you familiar with how this interface works in Coq and Isabelle? I'm pretty sure I saw a search panel for Coq.

Shreyas Srinivas (Oct 14 2023 at 15:23):

Where in coq? Which ide/extension?

Patrick Massot (Oct 14 2023 at 15:24):

I'm not sure, this was in 2017 during the two weeks I spent trying Coq before giving up and installing Lean.

Patrick Massot (Oct 14 2023 at 15:25):

It was either in CoqIDE that I tried myself of in emacs if it was when I looked at Assia using Coq.

Joachim Breitner (Oct 14 2023 at 15:28):

No, I'm rather ignorant here, hence the call for help.

Joachim Breitner (Oct 14 2023 at 15:28):

With Isabelle I remember that I found the GUI less useful than typing the command and using the info view, so I hope we can build something better :-)

Eric Wieser (Oct 14 2023 at 16:03):

I would guess you can have a command that opens a panel in the same style as Ctrl+P with the options populated by loogle

Eric Wieser (Oct 14 2023 at 16:05):

(By which I mean, https://code.visualstudio.com/api/ux-guidelines/quick-picks)

Eric Wieser (Oct 14 2023 at 16:08):

Though maybe a custom search sidebar makes more sense

Joachim Breitner (Oct 14 2023 at 16:12):

Quick pick might work well, although a sidebar would allow more interaction with the results, such as jump-to-definition. I'll let Shreyas surprise us

Eric Wieser (Oct 14 2023 at 16:17):

One advantage of a plain text editor is that presumably vscode can autocomplete the definition names

Marc Huisinga (Oct 14 2023 at 16:19):

Joachim Breitner said:

Quick pick might work well, although a sidebar would allow more interaction with the results, such as jump-to-definition. I'll let Shreyas surprise us

The disadvantage of sidebars is that you must switch away from your currently selected sidebar to use them. This is also why the future command menu is a title bar menu entry and not a sidebar. I'd personally prefer not using a sidebar for this.

Eric Wieser (Oct 14 2023 at 16:21):

I could imagine a sidebar being useful for having separate "name" and "identifier" search fields, so that users don't have to know the syntax

Joachim Breitner (Oct 14 2023 at 16:50):

The use case “I roughly know what I am looking for and want to insert it” might benefit from a quick pick, while “I need to do some serious sleuthing, and will look at types and docstrings of results and may have to refine my search a lot” more by a sidebar. Or both from the same somehow.

A structured query entry is also a good idea! (Ideally as long as it doesn't slow down the experienced user)

Shreyas Srinivas (Oct 14 2023 at 17:00):

You need both.

  1. I am using quick pick because adding too many sidebars makes life painful, especially if someone wants to open documentation sidebars (or other windows with PDFs for example).
  2. I think the solution to your second requirement is to add a link to loogle from the documentation viewer. It would naturally include the search bar on the loogle webpage

Shreyas Srinivas (Nov 05 2023 at 09:19):

I realized that this might be the better thread to post it. "Loogle Lean" is now available on the marketplace. Please check it out and let me know if you like the UI. The shortcut is Ctrl+Shift+L.

By default selecting a hit will insert it at your cursor position if you are working in an editor. If not, it will copy the definition to your clipboard.

Joachim Breitner (Nov 05 2023 at 09:31):

I'm on the road this weekend, so i can't play with it yet, but sounds great already! Please all test it and give Shreyas good feedback.

Henrik Böving (Nov 05 2023 at 10:30):

Just to make sure I'm not going to duplicate work: has someone here already started implementing this as a neovim telescope plugin?

Shreyas Srinivas (Nov 05 2023 at 11:53):

@Henrik Böving : I only put this up 12 hours ago. I am not sure loogle returns enough information yet for the previewer to be useful.

Julian Berman (Nov 05 2023 at 13:39):

Henrik Böving said:

Just to make sure I'm not going to duplicate work: has someone here already started implementing this as a neovim telescope plugin?

I have not yet though I certainly intended to both for Loogle and Moogle.

Shreyas Srinivas (Nov 05 2023 at 13:47):

If moogle has an API with docs, and they give permission, I can add moogle to my extension. Whom should I ask?

Julian Berman (Nov 05 2023 at 14:01):

In the Moogle thread I believe Jesse Michael Han mentioned there is (internal) efforts already to bring Moogle to VSCode. But Jesse I presume would be the one to talk to if you wanted to inquire about helping!

Joachim Breitner (Nov 06 2023 at 10:32):

@Shreyas Srinivas , could you add a nice User-agent to the request, possibly even with version information? It will be informative to see with which tools people use the loogle api. (Right now I think it is node-fetch.)

Shreyas Srinivas (Nov 06 2023 at 10:35):

I'll try to do it in the evening. At work right now.

Joachim Breitner (Nov 06 2023 at 10:36):

No rush!

Joachim Breitner (Nov 06 2023 at 11:12):

Just upgraded VS Code to give it a try. Very cool already!

I noticed that after issuing a search, it’s not possible (or not obvious how) to go back to the query and refine it. This might be the more relevant use case than filtering the results locally? Or somehow both ought to be possible. Maybe ↑ should go back to the query?
Related, I’d expect Shift-Ctrl-L and then ↑ to cycle through previous queries. I’m sure you thought about this before, so just supporting that feature request :)

Shreyas Srinivas (Nov 06 2023 at 11:29):

There is a back button

Shreyas Srinivas (Nov 06 2023 at 11:29):

But query history is a good idea. I'll try to incorporate it

Shreyas Srinivas (Nov 06 2023 at 11:30):

Also if you get suggestions and choose a suggestion the results for that suggestion show up

Joachim Breitner (Nov 06 2023 at 11:31):

Indeed, the back button goes back to “Loogle Search”, but with an empty search field.

Shreyas Srinivas (Nov 06 2023 at 11:35):

Okay I see what you mean

Eric Rodriguez (Nov 06 2023 at 11:39):

Whenever I press enter, nothing seems to happen - where should I be seeing the output?

Eric Rodriguez (Nov 06 2023 at 11:39):

Also, it'd be nice to have support for the same keyboard shortcuts that Lean4 has (eg \N -> blackboard bold N)

Shreyas Srinivas (Nov 06 2023 at 11:40):

Did you press enter in the filter hits input?

Eric Rodriguez (Nov 06 2023 at 11:41):

Oh, I think first one is just from me being impatient. PEBCAK :)

Shreyas Srinivas (Nov 06 2023 at 11:43):

Okay, i'll add Unicode support to the list of TODOs

Shreyas Srinivas (Nov 06 2023 at 11:45):

Does the API support this? I never tried it on the loogle webpage.

Eric Rodriguez (Nov 06 2023 at 11:49):

Loogle is just a wrapper around a native Lean command so I'd be surprised if it didn't

Shreyas Srinivas (Nov 06 2023 at 12:04):

That's not my worry. I hope the unicode stuff isn't garbled by URL encoding of requests

Joachim Breitner (Nov 06 2023 at 12:08):

Should work fine, and if not we can fix it :-)

Shreyas Srinivas (Nov 06 2023 at 12:27):

Eric Rodriguez said:

Oh, I think first one is just from me being impatient. PEBCAK :)

I think this issue is worth fixing. Users should know that the search is happening until the results arrive. The search bar shouldn't just disappear.

Eric Rodriguez (Nov 06 2023 at 14:58):

it'd also be nice if there'd be some way to keep results persistently! i'd be happy to help, been meaning to learn VSCode extensions for a bit - how could I contribute?

Shreyas Srinivas (Nov 06 2023 at 15:27):

For storage of key value pairs there is a vscode api class called Memento: https://code.visualstudio.com/api/references/vscode-api#Memento

Inside an extension a memento object is provided by the extension context. By configuring it and using the memento object it provides, you can add storage to the workspace.

The easiest way to get into vscode extension development is the Getting Started page. Following this you can play with the examples in the repository linked here. In the extension API docs, each UI item and contribution point links to an example in this repository.

I need to check if I have enabled PRs on the repository. I'll do this later in the evening and get back.

Shreyas Srinivas (Nov 06 2023 at 22:16):

@Joachim Breitner and @Eric Rodriguez : Version 0.06 has landed.

  1. Queries are now carried around and editable as requested.
  2. User agent added : vscode <version> loogle-lean <version>
  3. I should have mentioned this before, Alt + ← triggers the back button

Shreyas Srinivas (Nov 06 2023 at 22:17):

For the next version I want to add histories and reorganize the code a bit, before it gets too big.

Shreyas Srinivas (Nov 06 2023 at 22:27):

I also fixed the issue where the search bar disappears too soon and well before the results arrive.

Shreyas Srinivas (Nov 07 2023 at 00:56):

Released 0.0.7 with some polishing:

  1. In 0.0.6, retaining the term for filtering often filtered out all results giving the appearance of 0 hits even though there were some. So now if you want to modify the query, it shows up only in the query input.
  2. Added better place holders. Shows number of hits.
  3. Added a loading icon to reassure users that loogle is doing its thing when there are 200 hits (for example on the term Nat).

Shreyas Srinivas (Nov 07 2023 at 00:59):

I have been giving these updates here so that people who give me feedback are on the right version and know what's up. The changelog is also up to date, so from this point I will only post about serious updates, or updates in response to specific requests or feedback.

Shreyas Srinivas (Nov 07 2023 at 01:14):

Also a word about unicode: Copying and pasting in unicode actually works. It is the ability to modify inputs like \N in-place that is missing. I have to learn how the extension handles this in the first place. I'd be grateful for any help.

Joachim Breitner (Nov 07 2023 at 09:58):

I'd encourage you to keep posting here what's happening. It's a good way to advertise the extension, also to new users. And people can mute a topic.

Shreyas Srinivas (Nov 07 2023 at 10:00):

Okay. In that case I'll keep posting here. I was afraid the messages were reaching spam proportions.

Shreyas Srinivas (Nov 07 2023 at 10:02):

Fwiw, I think the extension may be ready for trial use by a broader audience than I initially suggested. I welcome volunteers.

Shreyas Srinivas (Nov 07 2023 at 10:37):

Here's the link for all new volunteers : https://marketplace.visualstudio.com/items?itemName=ShreyasSrinivas.loogle-lean

Shreyas Srinivas (Nov 08 2023 at 22:06):

@Marc Huisinga : Are there plans to bring mathlib4_docs into the doc view of the extension. Currently I am redirecting users to the webpage on an external browser. I'd like to open the docs within vscode, but it makes no sense for me to implement it separately if there are plans to have it in the extension already. (related: Is it just a webview opening a URL?)

Shreyas Srinivas (Nov 20 2023 at 22:08):

Version 0.08:

  • Fixes a few code inconsistencies.
  • The documentation link now takes you directly to the definition on the mathlib4_docs page, as originally intended.

Credits to @Eric Rodriguezfor this version.

Marc Huisinga (Nov 28 2023 at 10:53):

Shreyas Srinivas said:

Marc Huisinga : Are there plans to bring mathlib4_docs into the doc view of the extension. Currently I am redirecting users to the webpage on an external browser. I'd like to open the docs within vscode, but it makes no sense for me to implement it separately if there are plans to have it in the extension already. (related: Is it just a webview opening a URL?)

I looked into this. The DocView doesn't seem to be able to render mathlib4_docs, but VS Code's own SimpleBrowser does. In the future, I'd like to refactor the DocView entirely to use SimpleBrowser, which is when I'll also add the Mathlib docs to the DocView.

Shreyas Srinivas (Nov 28 2023 at 15:22):

If this very far in the future, then it probably makes sense for me to try to open mathlib4_docs in SimpleBrowser from the loogle extension for now.

Shreyas Srinivas (Nov 28 2023 at 15:22):

If it is a couple of weeks in the future, then maybe it doesn't

Marc Huisinga (Nov 28 2023 at 15:23):

I think it's OK to use SimpleBrowser for now. Since this is what I intend to refactor it for eventually anyways, you can then just change the command it calls and it should be exactly the same.


Last updated: Dec 20 2023 at 11:08 UTC