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

Add $psEditor.GetEditorContext().CurrentFile.SaveAs("Name") support #650

Merged
merged 1 commit into from
Apr 18, 2018

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Apr 6, 2018

Adds a SaveAs() method to the FileContext object, which sends a message to language client to save the current file as something else, at a path relative to the current file.

One note: there's a small amount of validation, just to not let you overwrite a file (since VSCode won't). The question is: should we do more validation, or none and instead get VSCode to send us back a success/failure message?

See vscode-powershell #1261 for the client side of this feature.

@rjmholt rjmholt changed the title Add $psEditor.GetEditorContext()CurrentFile.SaveAs("Name") support Add $psEditor.GetEditorContext().CurrentFile.SaveAs("Name") support Apr 6, 2018
@@ -206,6 +206,11 @@ public Task CloseFile(string filePath)
}

public Task SaveFile(string filePath)
{
return SaveFile(filePath, null);
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we could write a test for this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have tests for the editor method tasks? I thought I'd route through the methods on the mocks, but can happily add to tests.

Copy link
Member

Choose a reason for hiding this comment

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

The only reason I was wondering was because this change was in a test file (test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs).

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 actually know :/

Copy link
Member

Choose a reason for hiding this comment

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

looks like it's just mocks. No actual tests.


if (File.Exists(absolutePath))
{
throw new IOException(String.Format("The file '{0}' already exists", absolutePath));
Copy link
Member

Choose a reason for hiding this comment

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

Does this crash pses or does it just throw an error in the PSIC? (hoping for the second)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the second on the basis that it's a method on the $psEditor variable rather than in PSES itself (because I remember asking myself the same thing), but will check.

Copy link
Member

Choose a reason for hiding this comment

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

makes sense :)

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM 🎉nice work 👍

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM, just one small concern

RequestType<string, EditorCommandResponse, object, object>.Create("editor/saveFile");
RequestType<SaveFileDetails, EditorCommandResponse, object, object> Type =
RequestType<SaveFileDetails, EditorCommandResponse, object, object>.Create("editor/saveFile");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this be a breaking change? I doubt anyone is using this request directly, but it's worth noting IMessageSender is part of the public API as it's available from $psEditor.Components

Copy link
Member

Choose a reason for hiding this comment

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

Good point. This will be a part of a 1.7.0 release so we'll just have to be explicit and say that there's a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

unless there's a way to be backcompat friendly?

Copy link
Contributor Author

@rjmholt rjmholt Apr 17, 2018

Choose a reason for hiding this comment

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

Good point -- we really should start thinking of the API itself as the contract, not the VSCode behaviour. (Especially since I want to start working on a small vim client).

I'll change it back for the next 1.x release and then we can change it back again for 2.0. Does that sound reasonable?

(We don't really need to change it for 2.0 -- was just going for a consistent minimal API)

Copy link
Member

Choose a reason for hiding this comment

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

breaking changes this small aren't bad. We just need to make sure we let people know in the release notes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah ok -- I think that's fair. Especially after all the people asking for SaveAs().

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah definitely not a big deal. I highly doubt there is a single person using that request directly with IMessageSender right now. Just something we should really keep an eye on as PSES is just starting to see some adoption by other folks.

I could see SaveAs being a separate request if you wanted to be sure we don't mess anyone up, but I'm not sure how much refactoring that'd be. Probably not worth it.

Copy link
Contributor Author

@rjmholt rjmholt Apr 17, 2018

Choose a reason for hiding this comment

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

Yeah, I was thinking about setting it back to use a different request type, but now @tylerl0706 has convinced me that it's more effort than it's worth. But definitely agree that we need to keep the API stable.

I remember looking at the Save() API and thinking whether SaveAs() should be implemented independently and deciding that it makes sense (in a world without downstream developers) as just an additional field.

In general though, one thing I think might be worth doing is changing any API calls that we might want to extend which use a primitive (e.g. string) body to using an object body with a field, just so that we can conceivably add a new field and break the API "less"...

Copy link
Member

Choose a reason for hiding this comment

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

That last paragraph is awesome. Reminds me of graphQL in a lot of ways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shudder

@TylerLeonhardt TylerLeonhardt merged commit 4716b7f into PowerShell:master Apr 18, 2018
@rjmholt rjmholt deleted the filecontext-saveas branch December 12, 2018 06:02
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.

3 participants