Skip to content
Open
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
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ These changes have not been released to the Visual Studio marketplace, but (if c
- [ ] Features

- [ ] Fixes
- [x] [#854](https://github.com/codecadwallader/codemaid/pull/854) - Translate new resource to Chinese, simplify build outputs and fix for prompt to clean external files when another dialog is already open - thanks [heku](https://github.com/heku)!
- [x] [#877](https://github.com/codecadwallader/codemaid/pull/877) - Recognize WebForms in VS2022 (API change)
- [x] [#882](https://github.com/codecadwallader/codemaid/pull/882) - Fixed multiple bugs on file headers update - thanks [lflender](https://github.com/lflender)!
- [x] [#885](https://github.com/codecadwallader/codemaid/pull/885) - Recognize Razor in VS2022 (API change)
- [x] [#905](https://github.com/codecadwallader/codemaid/pull/905) - Fix issue causing keyword modifiers to be swapped - thanks [BlythMeister](https://github.com/BlythMeister)!
- [x] [#929](https://github.com/codecadwallader/codemaid/pull/929) - Add some UI padding

## Previous Releases

Expand All @@ -26,7 +32,6 @@ These are the changes to each version that has been released to the Visual Studi
- [x] Fixes
- [x] [#800](https://github.com/codecadwallader/codemaid/pull/800) - Reorganizing: Fix dialog showing literal newline characters


## 11.2

**2021-01-02**
Expand Down Expand Up @@ -80,7 +85,7 @@ These are the changes to each version that has been released to the Visual Studi
- [x] [#519](https://github.com/codecadwallader/codemaid/pull/519) - Simplify the code by removing unnecessary guids - thanks [heku](https://github.com/heku)!
- [x] [#525](https://github.com/codecadwallader/codemaid/pull/525) - Make all features switchable - thanks [heku](https://github.com/heku)!
- [x] [#545](https://github.com/codecadwallader/codemaid/pull/545) - Ignore comment lines starting with certain prefixes - thanks [willemduncan](https://github.com/willemduncan)!

- [x] Fixes
- [x] [#479](https://github.com/codecadwallader/codemaid/pull/479) - Update XAML Styler integration mappings - thanks [grochocki](https://github.com/grochocki)!
- [x] [#496](https://github.com/codecadwallader/codemaid/pull/496) - Fix the .NET Framework minimum required version (which is v4.6)
Expand Down Expand Up @@ -181,4 +186,4 @@ These are the changes to each version that has been released to the Visual Studi
- [x] #193 - Added undo transaction to insert region command (thanks Matthias Reitinger!)
- [x] Remove multithread operations performance option that was root of problems like #212

### CHANGELOG started with v0.9.1, see [Blog](http://www.codemaid.net/news/) for deeper history
### CHANGELOG started with v0.9.1, see [Blog](http://www.codemaid.net/news/) for deeper history
3 changes: 3 additions & 0 deletions CodeMaid.UnitTests/CodeMaid.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>17.0.0</Version>
</PackageReference>
Expand Down
10 changes: 5 additions & 5 deletions CodeMaid.UnitTests/Helpers/FileHeaderHelperTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
using SteveCadwallader.CodeMaid.Helpers;
using System;
Expand Down Expand Up @@ -152,8 +152,8 @@ public void GetHeaderLengthMultiSingleLine(string tag, string text)
Assert.IsTrue(headerLength == expectedLength, $"Expecting {expectedLength}, found {headerLength}");
}

[TestCase("//", "using System;\r\n// header\r\n", 11)]
[TestCase("//", "using System;\r\n// header I\r\n// header II\r\n", 26)]
[TestCase("//", "using System;\r\n// header\r\nnamespace ", 11)]
[TestCase("//", "using System;\r\n// header I\r\n// header II\r\nnamespace ", 26)]
public void GetHeaderLengthMultiSingleLineSkipUsings(string tag, string text, int expectedLength)
{
var headerLength = FileHeaderHelper.GetHeaderLength(text, tag, true);
Expand All @@ -174,7 +174,7 @@ public void GetHeaderLengthMultiSingleLineWithCode(string tag, string text, int

[TestCase("//", "using System;\r\n\r\n// header \r\nnamespace System.Windows;\r\npublic class Test\r\n", 13)]
[TestCase("//", "using EnvDTE;\r\nusing System;\r\nusing SteveCadwallader.CodeMaid.Helpers;\r\n\r\n\r\n// header \r\n// more header \r\nnamespace SteveCadwallader.CodeMaid;\r\n", 29)]
[TestCase("//", "using System;\r\n\r\n// header \r\n[assembly: AssemblyTitle(\"SteveCadwallader.CodeMaid.UnitTests\")]\r\n", 13)]
[TestCase("//", "using System;\r\n\r\n// header \r\n[assembly: AssemblyTitle(\"SteveCadwallader.CodeMaid.UnitTests\")]\r\nnamespace ", 13)]
public void GetHeaderLengthMultiSingleLineWithCodeSkipUsings(string tag, string text, int expectedLength)
{
var headerLength = FileHeaderHelper.GetHeaderLength(text, tag, true);
Expand All @@ -193,7 +193,7 @@ public void GetHeaderLengthMultiSingleLineWithEmptyLines(string tag, string text
Assert.IsTrue(headerLength == expectedLength, $"Expecting {expectedLength}, found {headerLength}");
}

[TestCase("//", "using System;\r\n\r\n\r\n// header \r\n// header\r\nnamespace\r\n//not header\r\n public class Test\r\n", 23)]
[TestCase("//", "using System;\r\n\r\n\r\n// header \r\n// header\r\nnamespace \r\n//not header\r\n public class Test\r\n", 23)]
[TestCase("//", "using EnvDTE;\r\nusing System;\r\nusing SteveCadwallader.CodeMaid.Helpers;\r\n// header \r\n// more header \r\n namespace System.Text;\r\n{\r\n", 29)]
public void GetHeaderLengthMultiSingleLineWithEmptyLinesSkipUsings(string tag, string text, int expectedLength)
{
Expand Down
11 changes: 2 additions & 9 deletions CodeMaid.VS2022/CodeMaid.VS2022.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -723,21 +723,14 @@
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>17.0.0-previews-2-31512-422</Version>
<ExcludeAssets>runtime</ExcludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>17.0.3177-preview3</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="System.Collections.Immutable">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="..\CodeMaidShared\CodeMaidShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions CodeMaid.VS2022/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<Tags>build, code, c#, beautify, cleanup, cleaning, digging, reorganizing, formatting</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 19.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.7.2,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,19.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
Expand Down
11 changes: 2 additions & 9 deletions CodeMaid/CodeMaid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,14 @@
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>16.10.31321.278</Version>
<ExcludeAssets>runtime</ExcludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>16.11.35</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="System.Collections.Immutable">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="..\CodeMaidShared\CodeMaidShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
2 changes: 2 additions & 0 deletions CodeMaidShared/CodeMaidShared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Helpers\TextDocumentHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\TypeFormatHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\UIHierarchyHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\UIThread.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\UndoTransactionHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\Commands\AboutCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Integration\Commands\BaseCommand.cs" />
Expand Down Expand Up @@ -158,6 +159,7 @@
<AutoGen>True</AutoGen>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UI\Bindable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\Converters\BooleanAndConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\Converters\BooleanInverseConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\Converters\BooleanToVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\Converters\CodeItemParentHighestComplexityConverter.cs" />
Expand Down
4 changes: 2 additions & 2 deletions CodeMaidShared/Helpers/CodeElementHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ internal static string GetPropertyDeclaration(CodeProperty codeProperty)
? codeProperty.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter)
: codeProperty.StartPoint;

return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"\{");
return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"[\{;]");
}

/// <summary>
Expand All @@ -197,7 +197,7 @@ internal static string GetStructDeclaration(CodeStruct codeStruct)
// Get the start point after the attributes.
var startPoint = codeStruct.GetStartPoint(vsCMPart.vsCMPartHeader);

return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"\{");
return TextDocumentHelper.GetTextToFirstMatch(startPoint, @"[\{;]");
}
}
}
69 changes: 52 additions & 17 deletions CodeMaidShared/Helpers/CodeLanguageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,62 @@ internal static CodeLanguage GetCodeLanguage(string language)
{
switch (language)
{
case "Basic": return CodeLanguage.VisualBasic;
case "CSharp": return CodeLanguage.CSharp;
case "Basic":
return CodeLanguage.VisualBasic;

case "CSharp":
return CodeLanguage.CSharp;

case "C/C++":
case "C/C++ (VisualGDB)": return CodeLanguage.CPlusPlus;
case "CSS": return CodeLanguage.CSS;
case "F#": return CodeLanguage.FSharp;
case "C/C++ (VisualGDB)":
return CodeLanguage.CPlusPlus;

case "CSS":
return CodeLanguage.CSS;

case "F#":
return CodeLanguage.FSharp;

case "HTML":
case "HTMLX": return CodeLanguage.HTML;
case "HTMLX":
case "Razor":
case "WebForms":
return CodeLanguage.HTML;

case "JavaScript":
case "JScript":
case "Node.js": return CodeLanguage.JavaScript;
case "JSON": return CodeLanguage.JSON;
case "LESS": return CodeLanguage.LESS;
case "PHP": return CodeLanguage.PHP;
case "PowerShell": return CodeLanguage.PowerShell;
case "R": return CodeLanguage.R;
case "SCSS": return CodeLanguage.SCSS;
case "TypeScript": return CodeLanguage.TypeScript;
case "XAML": return CodeLanguage.XAML;
case "XML": return CodeLanguage.XML;
default: return CodeLanguage.Unknown;
case "Node.js":
return CodeLanguage.JavaScript;

case "JSON":
return CodeLanguage.JSON;

case "LESS":
return CodeLanguage.LESS;

case "PHP":
return CodeLanguage.PHP;

case "PowerShell":
return CodeLanguage.PowerShell;

case "R":
return CodeLanguage.R;

case "SCSS":
return CodeLanguage.SCSS;

case "TypeScript":
return CodeLanguage.TypeScript;

case "XAML":
return CodeLanguage.XAML;

case "XML":
return CodeLanguage.XML;

default:
return CodeLanguage.Unknown;
}
}
}
Expand Down
37 changes: 33 additions & 4 deletions CodeMaidShared/Helpers/FileHeaderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using EnvDTE;
using EnvDTE;
using SteveCadwallader.CodeMaid.Properties;
using SteveCadwallader.CodeMaid.UI.Enumerations;
using System;
Expand Down Expand Up @@ -182,6 +182,12 @@ private static int GetHeaderLength(string text, string commentSyntax)
header.AddRange(GetLinesStartingWith(commentSyntax, lines, header.Count));

var nbChar = 0;

if (header.Count() == 0)
{
return 0;
}

header.ToList().ForEach(x => nbChar += x.Length + 1);

return nbChar;
Expand Down Expand Up @@ -218,6 +224,12 @@ private static int GetHeaderLength(string text, string commentSyntaxStart, strin
}

var nbChar = 0;

if (header.Count() == 0)
{
return 0;
}

header.ToList().ForEach(x => nbChar += x.Length + 1);

return nbChar;
Expand All @@ -234,7 +246,7 @@ private static int GetHeaderLengthSkipUsings(string text, string commentSyntax)
var nbChar = 0;
header.ToList().ForEach(x => nbChar += x.Length + 1);

return nbChar + 1;
return nbChar == 0 ? 0 : nbChar + 1;
}

private static int GetHeaderLengthSkipUsings(string text, string commentSyntaxStart, string commentSyntaxEnd)
Expand All @@ -251,6 +263,12 @@ private static int GetHeaderLengthSkipUsings(string text, string commentSyntaxSt

var header = text.Substring(startIndex, endIndex - startIndex);
var nbNewLines = Regex.Matches(header, Environment.NewLine).Count;

if (header.Length == 0 && nbNewLines == 0)
{
return 0;
}

return header.Length + commentSyntaxEnd.Length - nbNewLines + 1;
}

Expand Down Expand Up @@ -307,13 +325,24 @@ private static string SkipUsings(string document)
var startIndex = 0;
var lastUsingIndex = 0;

while (startIndex < namespaceIndex && startIndex++ != -1)
while (startIndex < namespaceIndex)
{
lastUsingIndex = startIndex;
startIndex = document.IndexOf("using ", startIndex);

if (startIndex++ == -1)
{
break;
}
}

var afterUsingIndex = 0;

if (lastUsingIndex > 0)
{
afterUsingIndex = document.IndexOf($"{Environment.NewLine}", lastUsingIndex) + 1;
}

var afterUsingIndex = document.IndexOf($"{Environment.NewLine}", lastUsingIndex) + 1;
return document.Substring(afterUsingIndex).TrimStart();
}

Expand Down
Loading