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

LSP-based infoview #30

Merged
merged 31 commits into from
Jul 14, 2021
Merged

LSP-based infoview #30

merged 31 commits into from
Jul 14, 2021

Conversation

Vtec234
Copy link
Member

@Vtec234 Vtec234 commented Jun 25, 2021

This PR splits the infoview into a separate NPM package independent of VSCode, and based on a more general editor<->infoview API based on LSP. Changes include:

  • The new infoview API tries to provide more general functionality, basing most of it on LSP requests and the ability to listen in on incoming/outgoing LSP notifications from within the infoview. This is intended to allow using custom requests from widget code.
    • This is not as nice to implement on the VSCode extension side as one might like. See here for why. This may be fixable in upstream vscode-jsonrpc.
    • I expect the new API to be more easily implementable in any other text editor capable of displaying a webpage.
  • Fixes in various edge cases. For example, we now delete pins when the corresponding file is closed as the server cannot produce goal states for them any more.
  • We handle more stuff in the infoview. For example, pins are synced there without going through the extension by subscribing to textDocument/didChange.
  • Outsourced tachyons CSS and codicons to NPM packages. I took the artistic liberty of changing the codicon for copy-to-comment to "quote" (see it here) as I couldn't find the current one (and maybe "quote" is a little clearer?).
  • Some refactoring, primarily on info.tsx. UI code is difficult, but I tried to separate the concerns of pausing and fetching goals into different and maybe reusable components.
  • The repository is now organised into a "monorepo" containing two packages. We use Lerna to manage them.
  • Probably other things I forgot.

I apologise for making the development a bit hard to follow. I made commits to a separate repo before copying the files here. They can be browsed.

There are quite a lot of changes, and while I tried testing all functionality I expect there to be some breakage. Still to be fixed:

  • Re-send diagnostics to infoview on startup
  • Implement "copy-to-comment" (now a general "make text edit" API)

README.md Outdated Show resolved Hide resolved
lean4-infoview/src/infoview/index.css Show resolved Hide resolved
lean4-infoview/src/infoview/goal.tsx Outdated Show resolved Hide resolved
lean4-infoview/src/infoview/goal.tsx Outdated Show resolved Hide resolved
lean4-infoview/src/infoview/infos.tsx Outdated Show resolved Hide resolved
vscode-lean4/src/infoview.ts Outdated Show resolved Hide resolved
vscode-lean4/src/leanclient.ts Outdated Show resolved Hide resolved
vscode-lean4/src/rpc.ts Outdated Show resolved Hide resolved
vscode-lean4/src/rpc.ts Show resolved Hide resolved
lean4-infoview/src/infoview/messages.tsx Outdated Show resolved Hide resolved
@@ -163,9 +160,6 @@ export class LeanClient implements Disposable {
}
},
}
this.setProgress(Object.assign({}, ...workspace.textDocuments
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this changes the semantics slightly in that yellow bars only appear when the server actually begins compiling the header. I think this is nice, as visually indicates things are working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have extremely strong feelings about this, but it was very much intentional. When opening a Lean file, I'm interested in whether there are errors or not. The progress bars allow me to distinguish the states of "no errors because Lean hasn't compiled this part yet" and "no errors because the proof is fine".

This is the same reason why I said that the fileProgress notification should be sent before processing is started (in leanprover/lean4#503). The important information is not that Lean is still running, but that it is not finished yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. The only real difference is that with this change, if the server fails to start the gutters won't appear, whereas before they'd be there even though nothing is actually being processed. You still know that the lack of errors is due to server failure because there will be the "server failed to start" popup. IMO this way it's clearer when things have failed, and when things are actually compiling (where we do send server notifs before starting compilation as you note), and you can still clearly tell why there are no errors. But if you still disagree, I'm happy to revert this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if this only happens with a dead server then it's a non-issue. In that case you already get a lot of errors anyhow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there are also no gutters between exec lean --server and "lean --worker sends progress @ 0". This is a few ms right now, but I suppose it could be a problem with a bad plugin which takes long to initialize. We could show progress then.

@Vtec234 Vtec234 marked this pull request as ready for review June 29, 2021 02:13
/** Apply edits to the workspace. */
applyEdits(edits: TextDocumentEdit[]): Promise<void>
/** Insert text into a document. When `pos` is not present, write at the current cursor location. */
insertText(text: string, kind: TextInsertKind, pos?: TextDocumentPositionParams): Promise<void>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly the range of things which can be done with TextEdit without knowing the file contents (and for now we don't really need to track them in the infoview) is quite small, so reinstated this API.

@gebner
Copy link
Member

gebner commented Jun 29, 2021

I've tried it out a bit now. Some comments:

  • The LICENSE file should go back into the root directory.
  • The release.sh script should also go back into the root directory, and run npm run build after npm i. (Ideally, there'd be a github action which uploads the release when a tag is pushed, but we can do that another time.)
  • There's quite a bit of flickering when you move the cursor through a file (it switches between "No info found." and something else). This might be related to https://leanprover.zulipchat.com/#narrow/stream/147302-lean4-dev/topic/Auto.20completion/near/233509746 and eafe2e1
  • I'm not sure what I think about the grayed-out identifiers. Graying out the hypothesis name foo✝ in foo✝ : Nat is a positive change in my eyes (since you can easily spot the accessible hypotheses). But graying them out in the rest of the term looks very distracting (since it's the only highlighting so it sticks out like a sore thumb).
  • The pinned info shows Loading... for a short time every time you type something.
  • Copy-to-comment produces an extra newline.
  • vscode now uses 230% CPU (with 4 processes)

@Kha
Copy link
Member

Kha commented Jun 29, 2021

* But graying them out in the rest of the term looks very distracting (since it's the only highlighting so it sticks out like a sore thumb).

In Emacs I quickly got used to it, and I believe @leodemoura liked them as well. I haven't seen this PR in action yet though, it might be a case of color schemes. Here is what it looks like in Emacs for me currently:
image

@leodemoura
Copy link
Member

* But graying them out in the rest of the term looks very distracting (since it's the only highlighting so it sticks out like a sore thumb).

In Emacs I quickly got used to it, and I believe @leodemoura liked them as well. I haven't seen this PR in action yet though, it might be a case of color schemes. Here is what it looks like in Emacs for me currently:
image

I get something very similar on my machine, and yes I like it too :)

@gebner
Copy link
Member

gebner commented Jun 29, 2021

It's a much lighter gray here:

dead_highlighting

With #777 as the gray color for the light theme it looks better for me.

@Vtec234
Copy link
Member Author

Vtec234 commented Jun 29, 2021

The LICENSE file should go back into the root directory.
vscode now uses 230% CPU (with 4 processes)

fixed

The release.sh script should also go back into the root directory, and run npm run build after npm i. (Ideally, there'd be a github action which uploads the release when a tag is pushed, but we can do that another time.)

I made an attempt at how this should work but cannot test it without the PAT, so feel free to change things. Note the slightly weird --scope=lean4 because the extension package is named lean4. Ideally we'd rename it to something like @lean4/vscode-extension but not necessary if it would cause trouble with the extension marketplace.

@Vtec234
Copy link
Member Author

Vtec234 commented Jun 29, 2021

Copy-to-comment produces an extra newline

This is also the current behaviour, but I removed the newline.

There's quite a bit of flickering when you move the cursor through a file

The pinned info shows Loading... for a short time every time you type something.

I removed the Loading... indicator, I think it is nicer this way. In particular we still get a gold font on the status line when things are loading so no information is lost.

@gebner
Copy link
Member

gebner commented Jun 29, 2021

Copy-to-comment produces an extra newline

This is also the current behaviour, but I removed the newline.

Oops, I didn't notice that. You're right of course.

There's quite a bit of flickering when you move the cursor through a file

The pinned info shows Loading... for a short time every time you type something.

I removed the Loading... indicator, I think it is nicer this way. In particular we still get a gold font on the status line when things are loading so no information is lost.

I think that was a different bug. I mean the following:

#eval 1 + Nat.zero
  1. Put the cursor on Nat, and pin the info.
  2. Insert spaces before 1.
  • Every space increases the position of the pin by two!
  • On every keystroke, the expected type briefly disappears.
  1. After some spaces, the pin is beyond the end of the line.

@Vtec234
Copy link
Member Author

Vtec234 commented Jun 30, 2021

I fixed the type disappearing. As for the double-move, I also observed that before but can't anymore. I will wishfully think it disappeared along with one of the recent changes, but let me know if it's still buggy. Also the pin movement is still incorrect if you insert a newline before 1 and then immediately remove it, but that also seems broken in the current code so is no regression.

@gebner
Copy link
Member

gebner commented Jun 30, 2021

I still get the double-moves.

@Vtec234
Copy link
Member Author

Vtec234 commented Jun 30, 2021

Fixed now, hopefully. This was only observable on development builds because it was (intentionally, to catch this kind of bug) triggered by React.StrictMode.

@Vtec234
Copy link
Member Author

Vtec234 commented Jul 13, 2021

@gebner I've been test-driving this since the PR and it seems to work fine. I think it's good to go. Though I probably wouldn't release a new version until there are actually new features (WIP) using the LSP API.

@gebner
Copy link
Member

gebner commented Jul 14, 2021

Great! I'll make a release so that we get some free testing!

@gebner gebner merged commit 0dd38a7 into leanprover:master Jul 14, 2021
"version": "0.0.31",
"publisher": "leanprover",
"engines": {
"vscode": "^1.57.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vtec234 Do you remember why you had to bump the vscode minimum version requirement here? Does this PR use any new vscode feature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanna say it was something to do with the webview API, but I honestly don't remember, sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. We just run into an issue where the vscode-languageclient library has a hard requirement on the latest vscode version, and then I checked out the version requirement we had in package.json.

In any case, please don't bump this version unnecessarily. Old vscode versions won't install extensions that are not compatible with them.

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.

4 participants