Skip to content
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

Updates to VS extensions #579

Merged
merged 5 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Src/CSharpier.VisualStudio/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Local Testing
- I have run into cases of the extension not working. Uninstalling both csharpier and
csharpier 2019 from the test instance and restarting seems to fix it. Maybe it happens because both seem to
to installed?
to installed? Turning off the 2019 build for debug seems to have helped

Publishing
- Update version in BOTH files at CSharpier.VisualStudio[2019]/source.extension.vsixmanifest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<MinimumVisualStudioVersion>17.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.0.1" Language="en-US" Publisher="CSharpier" />
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.2.0" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.0.1" Language="en-US" Publisher="CSharpier" />
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.2.0" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier 2019</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
<Compile Include="$(MSBuildThisFileDirectory)CSharpierPackage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CSharpierProcessPipeMultipleFiles.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CSharpierProcessSingleFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CSharpierService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CSharpierProcessProvider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CustomPathInstaller.cs" />
<Compile Include="$(MSBuildThisFileDirectory)FormattingService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ICSharpierProcess.cs" />
<Compile Include="$(MSBuildThisFileDirectory)InfoBarService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)InstallerService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Logger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NullCSharpierProcess.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProcessHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ReformatWithCSharpier.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ReformatWithCSharpierOnSave.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public class CSharpierOptionsPage : DialogPage
[DisplayName("Reformat with CSharpier on Save")]
[Description("Reformat with CSharpier on Save")]
public bool RunOnSave { get; set; }

[Category("CSharpier")]
[DisplayName("Log Debug Messages")]
[Description("Log Debug Messages")]
public bool LogDebugMessages { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Threading;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;
Expand All @@ -21,24 +22,23 @@ protected override async Task InitializeAsync(
IProgress<ServiceProgressData> progress
)
{
var outputPane = await this.GetServiceAsync<IVsOutputWindow>();
var logger = new Logger(outputPane);
logger.Info("Starting");
await Logger.InitializeAsync(this);
Logger.Instance.Info("Starting");

await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

await InfoBarService.InitializeAsync(this);
await ReformatWithCSharpierOnSave.InitializeAsync(this);
await ReformatWithCSharpier.InitializeAsync(this);
await InstallerService.InitializeAsync(this);

var csharpierService = new CSharpierService(logger);
var formattingService = new FormattingService(logger, csharpierService);

var csharpierOptionsPage = this.GetDialogPage<CSharpierOptionsPage>();
await ReformatWithCSharpierOnSave.InitializeAsync(
this,
formattingService,
csharpierOptionsPage
);
await ReformatWithCSharpier.InitializeAsync(this, formattingService);
var dte = await this.GetServiceAsync(typeof(DTE)) as DTE;
if (dte.ActiveDocument != null)
{
CSharpierProcessProvider
.GetInstance(this)
.FindAndWarmProcess(dte.ActiveDocument.FullName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Text;
using System.Threading;
using Thread = System.Threading.Thread;
using Process = System.Diagnostics.Process;

namespace CSharpier.VisualStudio
Expand All @@ -21,10 +20,7 @@ public CSharpierProcessPipeMultipleFiles(string csharpierPath, Logger logger)
{
this.logger = logger;

var processStartInfo = new ProcessStartInfo(
"dotnet",
csharpierPath + " --pipe-multiple-files"
)
var processStartInfo = new ProcessStartInfo(csharpierPath, " --pipe-multiple-files")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this is fine, since VS doesn't run on platforms other than windows.

{
RedirectStandardInput = true,
RedirectStandardOutput = true,
Expand All @@ -34,13 +30,17 @@ public CSharpierProcessPipeMultipleFiles(string csharpierPath, Logger logger)
UseShellExecute = false,
CreateNoWindow = true
};
processStartInfo.EnvironmentVariables["DOTNET_NOLOGO"] = "1";
this.process = new Process { StartInfo = processStartInfo };
this.process.Start();
this.standardIn = new StreamWriter(
this.process.StandardInput.BaseStream,
Encoding.UTF8
);

this.logger.Debug("Warm CSharpier with initial format");
// warm by formatting a file twice, the 3rd time is when it gets really fast
this.FormatFile("public class ClassName { }", "Test.cs");
this.FormatFile("public class ClassName { }", "Test.cs");
}

Expand All @@ -49,9 +49,6 @@ public string FormatFile(string content, string filePath)
this.output.Clear();
this.errorOutput.Clear();

this.logger.Info("Formatting " + filePath);
var stopwatch = Stopwatch.StartNew();

this.standardIn.Write(filePath);
this.standardIn.Write('\u0003');
this.standardIn.Write(content);
Expand All @@ -70,17 +67,16 @@ public string FormatFile(string content, string filePath)
if (string.IsNullOrEmpty(result))
{
this.logger.Info("File is ignored by .csharpierignore");
return null;
return string.Empty;
}
else
{
this.logger.Info("Formatted in " + stopwatch.ElapsedMilliseconds + "ms");
return this.output.ToString();
}
}

this.logger.Info("Got error output: " + errorResult);
return null;
return string.Empty;
}

private void ReadOutput(object state)
Expand Down Expand Up @@ -119,12 +115,17 @@ AutoResetEvent autoResetEvent
}
catch (Exception e)
{
this.logger.Log(e);
this.logger.Error(e);
}
finally
{
autoResetEvent.Set();
}
}

public void Dispose()
{
this.process.Kill();
}
}
}
Loading