Skip to content

Add Save() and IsSaved/IsModified to FileContext API #258

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

Closed
nightroman opened this issue Jun 18, 2016 · 13 comments
Closed

Add Save() and IsSaved/IsModified to FileContext API #258

nightroman opened this issue Jun 18, 2016 · 13 comments
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement).

Comments

@nightroman
Copy link

Is there any method to save a file opened in the editor? Ideally, to save if it
is modified. If there is a way to check the modified state then I am just
looking for a way to save.

The context. I am working on Invoke-TaskFromVSCode, similar to Invoke-TaskFromISE.
The script with tasks should be saved before invoking the current task from it.

In ISE it looks like

$file = $psISE.CurrentFile
if (!$file.IsSaved) {
    $file.Save()
}
@nightroman
Copy link
Author

Here is the current Invoke-TaskFromVSCode.ps1. For now it requires a user to save the current build script manually before invoking a task. It would be very useful to make this saving automatic.

@daviwil daviwil added this to the 0.7.0 milestone Jun 18, 2016
@daviwil daviwil added the Issue-Enhancement A feature request (enhancement). label Jun 18, 2016
@daviwil
Copy link
Contributor

daviwil commented Jun 18, 2016

Hey Roman, I can definitely add a 'Save' function and I believe I should be able to add an 'IsModified' field to show whether the file hasn't yet been saved. I will try to get this in for the 0.7.0 release which should be out in the second half of July once I'm back from vacation.

@daviwil daviwil changed the title How to ensure a file is saved? Add Save() and IsSaved/IsModified to FileContext API Jun 18, 2016
@daviwil daviwil modified the milestones: 0.7.0, 0.8.0 Sep 2, 2016
@daviwil daviwil modified the milestones: 0.8.0, 0.9.0 Nov 29, 2016
@daviwil daviwil modified the milestones: 0.9.0, 0.10.0 Jan 18, 2017
@daviwil daviwil modified the milestones: 0.10.0, April 2017 Mar 14, 2017
@nightroman
Copy link
Author

@daviwil

When can we expect this little, useful, and long awaited piece of API?
I am not trying to push, just asking for some sort of planning.

@daviwil
Copy link
Contributor

daviwil commented Apr 12, 2017

In the next feature update! $psEditor coverage is the short term priority now.

@daviwil daviwil modified the milestones: June 2017, Backlog Oct 27, 2017
@nightroman
Copy link
Author

This little feature would be very useful. Is it still on the radars?

I would use it right away for Invoke-TaskFromVSCode and make some Invoke-Build users a little bit happier.

@TylerLeonhardt
Copy link
Member

@nightroman it's on my radar now 😃 I'll look into this.

@TylerLeonhardt
Copy link
Member

@daviwil + @rkeithhill: It looks like $psEditor doesn't have a concept of $psEditor.CurrentFile. Is there another way to do it at the moment (via Window or Workspace) or would the addition of such a property (CurrentFile) need to happen as well as giving the FileContext API a Save() and IsSaved/IsModified?

@TylerLeonhardt
Copy link
Member

Ah. $psEditor.GetEditorContext().CurrentFile is the way to do it. 👍

@TylerLeonhardt
Copy link
Member

I have half of this in a PR so far:
PowerShell/vscode-powershell#1139
#590

I need to think about the IsModified method a bit more.

@nightroman
Copy link
Author

nightroman commented Dec 29, 2017

@tylerl0706 Thank you!

I need to think about the IsModified method a bit more.

If Save does not actually save to disk if the file is not modified then it's not a big deal for now.
But IsModified is useful on its own, indeed (though not in my scenario if Save is "smart").

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Dec 29, 2017

If Save does not actually save to disk if the file is not modified then it's not a big deal for now.

From a PSES perspective, it doesn't actually save to disk at all. It simply sends the "editor/saveFile" event to the editor - in our case, vscode. VSCode then handles the saving using the extensions API.

I can add an additional check to see if the file is dirty before it actually calls the VSCode save function.

Would that do what you need in the short term?

I'm still thinking on IsModified and agree that it's useful on its own 😄

@nightroman
Copy link
Author

I can add an additional check to see if the file is dirty before it actually calls the VSCode save function.

Yes, this will do the trick in the short term.

@nightroman
Copy link
Author

I see it working great in 1.6.0. Thank you so much!
I will update my Invoke-TaskFromVSCode.ps1 shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extension Terminal Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

3 participants