Skip to content

add Save to FileContext API #590

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 1 commit into from
Jan 3, 2018

Conversation

TylerLeonhardt
Copy link
Member

This is the PSES portion of this change. See the PSES portion here: PowerShell/vscode-powershell#1139

Please let me know if I'm missing something.

To test this, you can use:

$psEditor.GetEditorContext().CurrentFile.Save()

in the Integrated Console.

Copy link
Contributor

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

LGTM but this is way more @daviwil area.

/// <param name="filePath">The path of the file to be saved.</param>
/// <returns>A Task that can be tracked for completion.</returns>
Task SaveFile(string filePath);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would adding to this interface be a breaking change? I know we have at least two new implementations of PSES since this interface was last changed. Should new features be added as additional interfaces, something like IEditorSaveOperations?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.. but I think if we were going to make a new interface, I'd want it to be IEditorFileOperations and it would contain NewFile, OpenFile, CloseFile, SaveFile`, ya know? And that would surely warrant a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know, nobody is using these interfaces outside of PSES itself. Adding a method to an interface wouldn't be a breaking change so I think a new interface shouldn't be necessary for this.

/// </summary>
public void Save()
{
this.editorOperations.SaveFile(this.scriptFile.FilePath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you pass ClientFilePath here instead of FilePath you should be able to avoid resolving the path when it gets to VSCode. The InsertText method is a good example for both sides.

Copy link
Member Author

@TylerLeonhardt TylerLeonhardt Dec 29, 2017

Choose a reason for hiding this comment

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

@SeeminglyScience + @daviwil: So I tried passing in ClientFilePath. It prefaced it with file://.

This is not ideal because for openFile and closeFile here:
https://github.com/PowerShell/vscode-powershell/blob/master/src/features/ExtensionCommands.ts#L362-L409

We have VSCode already resolving the paths.

So I think we should either continue resolving the paths via VSCode, or modify openFile and closeFile to expect a ClientFilePath as well. That way, we are consistent.

Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tylerl0706 Ah I'd keep it as is then. In general I think it's better to have PSES do the work, but it's probably not worth changing the others.

/// <param name="filePath">The path of the file to be saved.</param>
/// <returns>A Task that can be tracked for completion.</returns>
Task SaveFile(string filePath);

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know, nobody is using these interfaces outside of PSES itself. Adding a method to an interface wouldn't be a breaking change so I think a new interface shouldn't be necessary for this.

@TylerLeonhardt
Copy link
Member Author

Thanks all!

@TylerLeonhardt TylerLeonhardt merged commit 0f63e5c into PowerShell:master Jan 3, 2018
@TylerLeonhardt TylerLeonhardt deleted the add-save branch January 3, 2018 06:02
@rkeithhill
Copy link
Contributor

rkeithhill commented Jan 4, 2018

@tylerl0706 I think we missed a file here because I don't see the SaveFile command e.g.:
image

I think SaveFile needs to be implemented here:

#region Public Methods
/// <summary>
/// Creates a new file in the editor
/// </summary>
public void NewFile()
{
this.editorOperations.NewFile().Wait();
}
/// <summary>
/// Opens a file in the workspace. If the file is already open
/// its buffer will be made active.
/// </summary>
/// <param name="filePath">The path to the file to be opened.</param>
public void OpenFile(string filePath)
{
this.editorOperations.OpenFile(filePath).Wait();
}
#endregion

BTW CloseFile() is missing as well. Hmm, maybe I'm not looking in the right place for this new SaveFile method.

UPDATE: nevermind. Figured it out - $psEditor.GetEditorContext().CurrentFile.Save().

TylerLeonhardt pushed a commit to TylerLeonhardt/PowerShellEditorServices that referenced this pull request Feb 26, 2019
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