Skip to content

Commit 8b046c2

Browse files
Merge pull request #15 from jesperbjensen/configuration-and-parser-hinting
Configuration and parser hinting
2 parents 9673e99 + 384b4f7 commit 8b046c2

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
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: 5 additions & 6 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;
@@ -58,10 +60,7 @@ private async Task<bool> MakePrettier()
5860
{
5961
edit.Replace(0, _view.TextBuffer.CurrentSnapshot.Length, output);
6062
edit.Apply();
61-
62-
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
63-
dte.ExecuteCommand("Edit.FormatDocument");
64-
63+
6564
undo.Complete();
6665
}
6766

src/NodeProcess.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JavaScriptPrettier
88
{
99
internal class NodeProcess
1010
{
11-
public const string Packages = "prettier@1.4.2";
11+
public const string Packages = "prettier@1.8.2";
1212

1313
private static string _installDir = Path.Combine(Path.GetTempPath(), Vsix.Name, Packages.GetHashCode().ToString());
1414
private static string _executable = Path.Combine(_installDir, "node_modules\\.bin\\prettier.cmd");
@@ -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)