Skip to content

Commit 552ff4c

Browse files
Call Format Document after run
1 parent 63a2e6f commit 552ff4c

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Road map
22

3+
- [x] Call *FormatDocument* command after run
34
- [ ] Document code in comments
45
- [ ] Move strings to resource file
56

‎src/Commands/PrettierCommand.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Runtime.InteropServices;
99
using System.Threading.Tasks;
10+
using EnvDTE;
1011

1112
namespace JavaScriptPrettier
1213
{
@@ -52,6 +53,10 @@ private async Task<bool> MakePrettier()
5253
{
5354
edit.Replace(0, _view.TextBuffer.CurrentSnapshot.Length, output);
5455
edit.Apply();
56+
57+
var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
58+
dte.ExecuteCommand("Edit.FormatDocument");
59+
5560
undo.Complete();
5661
}
5762

@@ -69,7 +74,7 @@ public override int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prg
6974
}
7075
else
7176
{
72-
SetText(pCmdText, "Make Prettier (installing npm module...)");
77+
SetText(pCmdText, "Make Prettier (installing npm modules...)");
7378
prgCmds[0].cmdf = (uint)OLECMDF.OLECMDF_SUPPORTED;
7479
}
7580

‎src/Constants.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class Constants
44
{
55
public static string[] FileExtensions = { ".js", ".jsx", ".es6" };
66

7-
public const string NpmPackageName = "prettier";
8-
public const string NpmPackageVersion = "0.17.1";
7+
public const string NpmPackages = "prettier@0.17.1";
98
}
109
}

‎src/NodeProcess.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JavaScriptPrettier
88
{
99
internal class NodeProcess
1010
{
11-
private static string _installDir = Path.Combine(Path.GetTempPath(), Vsix.Name, Constants.NpmPackageVersion);
11+
private static string _installDir = Path.Combine(Path.GetTempPath(), Vsix.Name, Constants.NpmPackages.GetHashCode().ToString());
1212
private static string _executable = Path.Combine(_installDir, "node_modules\\.bin\\prettier.cmd");
1313

1414
public static bool IsInstalling
@@ -39,7 +39,7 @@ public static async Task<bool> EnsurePackageInstalled()
3939
if (!Directory.Exists(_installDir))
4040
Directory.CreateDirectory(_installDir);
4141

42-
var start = new ProcessStartInfo("cmd", $"/c npm install {Constants.NpmPackageName}@{Constants.NpmPackageVersion}")
42+
var start = new ProcessStartInfo("cmd", $"/c npm install {Constants.NpmPackages}")
4343
{
4444
WorkingDirectory = _installDir,
4545
UseShellExecute = false,

0 commit comments

Comments
 (0)