8000 Auto-save codeAction changes to __package.rb files by jez · Pull Request #7214 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Auto-save codeAction changes to __package.rb files #7214

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

Merged
merged 8 commits into from
Aug 9, 2023
Merged

Conversation

jez
Copy link
Collaborator
@jez jez commented Aug 9, 2023

Implementation

We have some options here. Another option would be to implement something like
"save all files that weren't open before we applied the WorkspaceEdit," but
that's a little tricky, because we'd have to compute the list of open files on
the server side--by the time the WorkspaceEdit has applied, VS Code will already
have the files open, so we can't do it purely in the client.

In any case, this isn't a trapdoor decision--we can always decide to change our
minds and expand this feature if people start to ask for it.

Motivation

Requested by a user

Test plan

I only tested this manually.

Screen.Recording.2023-08-08.at.4.50.53.PM.mov

It's not particularly easy to test these changes in a meaningful way on the
server, because we don't have a concept of "edited but not saved files" in our
test harness.

It's possible that this is something we could write a VS Code test for? I'm not
super familiar with how one might work. @damolina-stripe, do you have thoughts
on whether/how to test the client-side portions of this change?

Client changes in non-VS Code editors

I found this comment from a maintainer of the LSP spec to be useful. The idea seems to be that clients should control maintaining a registry of commands, mapping to their implementations. Servers can kick-start this registry using the executeCommandProvider capability on initialization if it's desired to offload the implementation of a command to the server.

In our case, the thing we want relies entirely on the client, so we can't have this command implemented on the server.

I did confirm that at least in Neovim's built-in language client, they support declaring a string -> callback function registry, which is basically the same as the API VS Code gives us with registerCommand. I'm guessing that means that other language clients will be able to implement this as well.

jez added 4 commits August 8, 2023 10:11
We have some options here. Another option would be to implement
something like "save all files that weren't open before we applied the
WorkspaceEdit," but that's a little tricky, because we'd have to compute
the list of open files on the server side--by the time the WorkspaceEdit
has applied, VS Code will already have the files open, so we can't do it
purely in the client.

In any case, this isn't a trapdoor decision--we can always decide to
change our minds and expand this feature if people start to ask for it.
@jez jez requested a review from a team as a code owner August 9, 2023 04:24
@jez jez requested review from neilparikh and damolina-stripe and removed request for a team August 9, 2023 04:24
@jez
Copy link
Collaborator Author
jez commented Aug 9, 2023

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_OPtucaQdie9lH1
https://go/builds/bui_OPtvlGTGBkKyto
https://go/builds/bui_OPtvs9Sisg0zbO

@damolina-stripe
Copy link
Collaborator
damolina-stripe commented Aug 9, 2023

@jez It is possible to mock the WorkspaceEdit when writing a test against the command. There are a a couple examples in our internal codebase I can point you at.

One concern with this new command, is that "Save all __package.rb" files seems like a maybe too-specific general use command. If the only goal is to call it internally here

(action->command = make_unique<Command>("Save package files", "sorbet.savePackageFiles");

Then maybe defining as an internal command would be better - just don't define it in the package.json, the commandId is available for API calls still and activation should not be an issue since the extension would have to already be active for the command to be needed (in theory you can prefix the Id with _ to denote a private command, but not sure if being called from its own LSP still qualifies it as a private command).

jez added 2 commits August 9, 2023 10:12
This prevents it from being shown in the command picker, but still lets
it be called from the extension.

This reduces the public surface area of the extension. We can always
make this public later if it's something we want. But starting with it
private makes it easier for us to change our minds and either expand or
limit the scope of how this command works.
@jez jez force-pushed the jez-autosave-package branch from 73440e0 to cf06a06 Compare August 9, 2023 18:00
@@ -7,6 +7,7 @@ import { setLogLevel } from "./commands/setLogLevel";
import { showSorbetActions } from "./commands/showSorbetActions";
import { showSorbetConfigurationPicker } from "./commands/showSorbetConfigurationPicker";
import { toggleUntypedCodeHighlighting } from "./commands/toggleUntypedCodeHighlighting";
import { savePackageFiles } from "./commands/savePackageFiles";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: project file imports are sorted by import path, can this be moved to line 6?

@jez jez enabled auto-merge (squash) August 9, 2023 18:17
@jez jez merged commit 4bef842 into master Aug 9, 2023
@jez jez deleted the jez-autosave-package branch August 9, 2023 18:33
ilyailya pushed a commit that referenced this pull request Sep 6, 2023
* no-op: Operate on FileRef more

* no-op: Mark some generated code as const

* Server changes

We have some options here. Another option would be to implement
something like "save all files that weren't open before we applied the
WorkspaceEdit," but that's a little tricky, because we'd have to compute
the list of open files on the server side--by the time the WorkspaceEdit
has applied, VS Code will already have the files open, so we can't do it
purely in the client.

In any case, this isn't a trapdoor decision--we can always decide to
change our minds and expand this feature if people start to ask for it.

* Client changes

* Don't register as a command in package.json

This prevents it from being shown in the command picker, but still lets
it be called from the extension.

This reduces the public surface area of the extension. We can always
make this public later if it's something we want. But starting with it
private makes it easier for us to change our minds and either expand or
limit the scope of how this command works.

* Move log to trace level

* Another warning -> trace log

* sort
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.

2 participants
0