Skip to content

Commit

Permalink
Merge branch 'master' into multitarget
Browse files Browse the repository at this point in the history
  • Loading branch information
grochocki authored Dec 15, 2023
2 parents b52e4b3 + 9d3ba15 commit acee86d
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 82 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ XAML Styler is a visual studio extension that formats XAML source code based on

[![VS2019](https://img.shields.io/visual-studio-marketplace/v/TeamXavalon.XAMLStyler.svg?label=Visual%20Studio%202019)](https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler)

[![VSMAC](https://img.shields.io/badge/Visual%20Studio%20for%20Mac%202019-v2.0.1-blue.svg)](https://github.com/Xavalon/XamlStyler/files/7992390/Xavalon.XamlStyler_2.0.1.zip)

[![JetBrains IntelliJ Plugins](https://img.shields.io/jetbrains/plugin/v/14932-xaml-styler?label=JetBrains%20Rider)](https://plugins.jetbrains.com/plugin/14932-xaml-styler)

[![NuGet](https://img.shields.io/nuget/v/XamlStyler.Console.svg?label=XAML%20Styler%20Console)](https://www.nuget.org/packages/XamlStyler.Console)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
gradleOptions: '-Xmx3072m'
options: '-PPluginVersion=$(pluginVersion)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkVersionOption: '1.17'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
Expand Down
24 changes: 24 additions & 0 deletions src/XamlStyler.Console/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// © Xavalon. All rights reserved.

namespace Xavalon.XamlStyler.Console
{
public sealed class Logger
{
private readonly System.IO.TextWriter writer;
private readonly LogLevel level;

public Logger(System.IO.TextWriter writer, LogLevel level)
{
this.writer = writer;
this.level = level;
}

public void Log(string line, LogLevel level = LogLevel.Default)
{
if (level <= this.level)
{
this.writer.WriteLine(line);
}
}
}
}
4 changes: 4 additions & 0 deletions src/XamlStyler.Console/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public sealed partial class CommandLineOptions
[Option('p', "passive", Default = false, HelpText = "Check files follow proper formatting without making any modifications. Returns error status if files fail the check.")]
public bool IsPassive { get; set; }

[Option("write-to-stdout", Default = false,
HelpText = "Instead of modifying the file, write to stdout. In this mode, logs are printed to stderr. Must specify exactly one file. Cannot be compbined with --passive.")]
public bool WriteToStdout { get; set; }

[Option('l', "loglevel", Default = LogLevel.Default,
HelpText = "Levels in order of increasing detail: None, Minimal, Default, Verbose, Debug")]
public LogLevel LogLevel { get; set; }
Expand Down
69 changes: 46 additions & 23 deletions src/XamlStyler.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,62 @@ public static int Main(string[] args)

result.WithNotParsed(_ =>
{
System.Console.WriteLine(writer.ToString());
System.Console.Error.WriteLine(writer.ToString());
Environment.Exit(1);
})
.WithParsed(options =>
{
if (options.LogLevel >= LogLevel.Debug)
{
System.Console.WriteLine($"File Parameter: '{options.File}'");
System.Console.WriteLine($"File Count: {options.File?.Count ?? -1}");
System.Console.WriteLine($"File Directory: '{options.Directory}'");
}

bool isFileOptionSpecified = (options.File?.Count ?? 0) != 0;
bool isDirectoryOptionSpecified = !String.IsNullOrEmpty(options.Directory);
Logger logger = new Logger(options.WriteToStdout ? System.Console.Error : System.Console.Out, options.LogLevel);

if (isFileOptionSpecified ^ isDirectoryOptionSpecified)
{
var xamlStylerConsole = new XamlStylerConsole(options);
xamlStylerConsole.Process(isFileOptionSpecified ? ProcessType.File : ProcessType.Directory);
}
else
ProcessType processType;
if (!CheckOptions(options, logger, out processType))
{
string errorString = (isFileOptionSpecified && isDirectoryOptionSpecified)
? "Cannot specify both file(s) and directory"
: "Must specify file(s) or directory";

System.Console.WriteLine($"\nError: {errorString}\n");

Environment.Exit(1);
}

var xamlStylerConsole = new XamlStylerConsole(options, logger);
xamlStylerConsole.Process(processType);
});

return 0;
}

private static bool CheckOptions(CommandLineOptions options, Logger logger, out ProcessType processType)
{
logger.Log($"File Parameter: '{options.File}'", LogLevel.Debug);
logger.Log($"File Count: {options.File?.Count ?? -1}", LogLevel.Debug);
logger.Log($"File Directory: '{options.Directory}'", LogLevel.Debug);

bool result = true;

int numFilesSpecified = options.File?.Count ?? 0;
bool isFileOptionSpecified = numFilesSpecified != 0;
bool isDirectoryOptionSpecified = !String.IsNullOrEmpty(options.Directory);
if (isFileOptionSpecified && isDirectoryOptionSpecified)
{
System.Console.Error.WriteLine($"\nError: Cannot specify both file(s) and directory\n");
result = false;
}
else if (!isFileOptionSpecified && !isDirectoryOptionSpecified)
{
System.Console.Error.WriteLine($"\nError: Must specify file(s) or directory\n");
result = false;
}

if (options.WriteToStdout && (isDirectoryOptionSpecified || numFilesSpecified != 1))
{
System.Console.Error.WriteLine($"\nError: When using --write-to-stdout you must specify exactly one file\n");
result = false;
}

if (options.WriteToStdout && options.IsPassive)
{
System.Console.Error.WriteLine($"\nError: Cannot specify both --passive and --write-to-stdout\n");
result = false;
}

processType = isFileOptionSpecified ? ProcessType.File : ProcessType.Directory;
return result;
}
}
}
}
27 changes: 20 additions & 7 deletions src/XamlStyler.Console/XamlStylerConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ namespace Xavalon.XamlStyler.Console
public sealed class XamlStylerConsole
{
private readonly CommandLineOptions options;
private readonly Logger logger;
private readonly StylerService stylerService;

public XamlStylerConsole(CommandLineOptions options)
public XamlStylerConsole(CommandLineOptions options, Logger logger)
{
this.options = options;
this.logger = logger;

IStylerOptions stylerOptions = new StylerOptions();

Expand Down Expand Up @@ -263,6 +265,20 @@ private bool TryProcessFile(string file)
return false;
}
}
else if (this.options.WriteToStdout)
{
var prevEncoding = System.Console.OutputEncoding;
try
{
System.Console.OutputEncoding = encoding;
System.Console.Write(encoding.GetString(encoding.GetPreamble()));
System.Console.Write(formattedOutput);
}
finally
{
System.Console.OutputEncoding = prevEncoding;
}
}
else
{
this.Log($"\nFormatted Output:\n\n{formattedOutput}\n", LogLevel.Insanity);
Expand Down Expand Up @@ -332,12 +348,9 @@ private string GetConfigurationFromPath(string path)
return null;
}

private void Log(string value, LogLevel logLevel = LogLevel.Default)
private void Log(string line, LogLevel logLevel = LogLevel.Default)
{
if (logLevel <= this.options.LogLevel)
{
System.Console.WriteLine(value);
}
this.logger.Log(line, logLevel);
}
}
}
}
6 changes: 3 additions & 3 deletions src/XamlStyler.Extension.Rider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
id 'java'

// RIDER: May need updating with new Rider releases
id 'org.jetbrains.kotlin.jvm' version '1.7.22'
id 'org.jetbrains.kotlin.jvm' version '1.9.10'
id 'com.jetbrains.rdgen' version '2023.2.0'

// RIDER: Will probably need updating with new Rider releases, use latest version number from https://github.com/JetBrains/gradle-intellij-plugin/releases
id 'org.jetbrains.intellij' version '1.13.3'
id 'org.jetbrains.intellij' version '1.16.1'
}

ext {
Expand All @@ -25,7 +25,7 @@ repositories {
}

wrapper {
gradleVersion = '7.6'
gradleVersion = '8.5'
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
Expand Down
2 changes: 1 addition & 1 deletion src/XamlStyler.Extension.Rider/dotnet/Plugin.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<!-- RIDER: To be updated with new Rider release -->
<SdkVersion>2023.1.0</SdkVersion>

<SdkVersion>2023.3.0</SdkVersion>
<Title>XAML Styler</Title>
<Description>XAML Styler is an extension that formats XAML source code based on a set of styling rules. This tool can help you/your team maintain a better XAML coding style as well as a much better XAML readability.</Description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public StringListViewModel(
{
myLifetime = lifetime;
mySource = source;
myEntryChanged = new GroupingEventHost(lifetime, false).CreateEvent(lifetime,
myEntryChanged = new GroupingEventHosts(lifetime)[Rgc.Invariant].CreateEvent(lifetime,
"StringListViewModel.EntryChangedGrouped",
TimeSpan.FromMilliseconds(100),
OnEntryChanged);
Expand All @@ -30,8 +30,8 @@ public StringListViewModel(
.Select(entry => new StringListEntry(lifetime, myEntryChanged.Incoming, entry.Trim()))
.ToList();

Entries = new ListEvents<StringListEntry>(lifetime, "StringListViewModel.Entries", entries, false);
SelectedEntry = new Property<StringListEntry>(lifetime, "StringListViewModel.SelectedEntry");
Entries = new ListEvents<StringListEntry>("StringListViewModel.Entries", entries, false);
SelectedEntry = new Property<StringListEntry>("StringListViewModel.SelectedEntry");
}

public ListEvents<StringListEntry> Entries { get; }
Expand Down Expand Up @@ -71,7 +71,7 @@ public StringListEntry(
[NotNull] ISimpleSignal entryChanged,
string value)
{
Value = new Property<string>(lifetime, "StringListEntry.Value", value);
Value = new Property<string>("StringListEntry.Value", value);
Value.Change.Advise_NoAcknowledgement(lifetime, entryChanged.Fire);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public XamlStylerOptionsPage(
// Configuration
AddHeader("Configuration");
AddText("External configuration file:");
var configPath = new Property<FileSystemPath>(lifetime, "XamlStylerOptionsPage::configPath");
var configPath = new Property<FileSystemPath>("XamlStylerOptionsPage::configPath");
OptionsSettingsSmartContext.SetBinding(lifetime, (XamlStylerSettings k) => k.ConfigPath, configPath);
AddFileChooserOption(configPath, "External configuration file", FileSystemPath.Empty, null, commonFileDialogs, null, false, "", null, null, null, null);
AddBoolOption((XamlStylerSettings x) => x.SearchToDriveRoot, "Search to drive root");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public RiderXamlStylerHost(
if (rdSolutionModel != null)
{
var rdXamlStylerModel = rdSolutionModel.GetXamlStylerModel();
rdXamlStylerModel.PerformReformat.Set(PerformReformatHandler);
rdXamlStylerModel.PerformReformat.SetAsync(PerformReformatHandler);
}
}

private RdTask<RdXamlStylerFormattingResult> PerformReformatHandler(
private Task<RdXamlStylerFormattingResult> PerformReformatHandler(
Lifetime requestLifetime,
RdXamlStylerFormattingRequest request)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override Action<ITextControl> ExecutePsiTransaction(
[NotNull] IProgressIndicator progress)
{
// Fetch settings
var lifetime = solution.GetLifetime();
var lifetime = solution.GetSolutionLifetimes().MaximumLifetime;
var settings = solution.GetSettingsStore().SettingsStore.BindToContextLive(lifetime, ContextRange.Smart(solution.ToDataContext()));
var stylerOptions = StylerOptionsFactory.FromSettings(
settings,
Expand Down
2 changes: 1 addition & 1 deletion src/XamlStyler.Extension.Rider/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ BuildConfiguration=Release
# 2021.2 (stable versions)
#
# RIDER: To be updated with new Rider release
ProductVersion=2023.1
ProductVersion=2023.3
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Pro">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
</Dependencies>
Expand Down
Loading

0 comments on commit acee86d

Please sign in to comment.