Skip to content

Commit 384b4f7

Browse files
committed
Added --stdin-filepath argument to command
1 parent d58a3fa commit 384b4f7

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/Commands/CommandRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public async void VsTextViewCreated(IVsTextView textViewAdapter)
3535
ITextBufferUndoManager undoManager = UndoProvider.GetTextBufferUndoManager(view.TextBuffer);
3636
NodeProcess node = view.Properties.GetOrCreateSingletonProperty(() => new NodeProcess());
3737

38-
AddCommandFilter(textViewAdapter, new PrettierCommand(view, undoManager, node, doc.Encoding));
38+
AddCommandFilter(textViewAdapter, new PrettierCommand(view, undoManager, node, doc.Encoding, doc.FilePath));
3939

4040
if (!node.IsReadyToExecute())
4141
{

src/Commands/PrettierCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ internal sealed class PrettierCommand : BaseCommand
2121
private ITextBufferUndoManager _undoManager;
2222
private NodeProcess _node;
2323
private Encoding _encoding;
24+
private string _filePath;
2425

25-
public PrettierCommand(IWpfTextView view, ITextBufferUndoManager undoManager, NodeProcess node, Encoding encoding)
26+
public PrettierCommand(IWpfTextView view, ITextBufferUndoManager undoManager, NodeProcess node, Encoding encoding, string filePath)
2627
{
2728
_view = view;
2829
_undoManager = undoManager;
2930
_node = node;
3031
_encoding = encoding;
32+
_filePath = filePath;
3133
}
3234

3335
public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
@@ -48,7 +50,7 @@ public override int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt,
4850
private async Task<bool> MakePrettier()
4951
{
5052
string input = _view.TextBuffer.CurrentSnapshot.GetText();
51-
string output = await _node.ExecuteProcess(input, _encoding);
53+
string output = await _node.ExecuteProcess(input, _encoding, _filePath);
5254

5355
if (string.IsNullOrEmpty(output) || input == output)
5456
return false;

src/NodeProcess.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ public async Task<bool> EnsurePackageInstalled()
8080
}
8181
}
8282

83-
public async Task<string> ExecuteProcess(string input, Encoding encoding)
83+
public async Task<string> ExecuteProcess(string input, Encoding encoding, string filePath)
8484
{
8585
if (!await EnsurePackageInstalled())
8686
return null;
8787

88-
var start = new ProcessStartInfo("cmd", $"/c \"{_executable}\" --stdin")
88+
var command = $"/c \"\"{_executable}\" --stdin-filepath \"{filePath}\" --stdin\"";
89+
90+
var start = new ProcessStartInfo("cmd", command)
8991
{
9092
UseShellExecute = false,
9193
CreateNoWindow = true,

0 commit comments

Comments
 (0)