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
20 changes: 13 additions & 7 deletions src/XamlStyler.Extension.Rider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ repositories {

dependencies {
intellijPlatform {
rider(libs.versions.rider, false)
rider(libs.versions.rider.get()) {
useInstaller = false
}
jetbrainsRuntime()
}
}
Expand Down Expand Up @@ -61,7 +63,7 @@ sourceSets {

tasks {
wrapper {
gradleVersion = "8.10"
gradleVersion = "9.4.1"
distributionType = Wrapper.DistributionType.ALL
distributionUrl =
"https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
Expand All @@ -82,7 +84,8 @@ tasks {
outputs.upToDateWhen { false }
doLast {
copy {
from("${buildDir}/distributions/${rootProject.name}-${version}.zip")
val buildDirPath = layout.buildDirectory.get().asFile
from("${buildDirPath}/distributions/${rootProject.name}-${version}.zip")
into("${rootDir}/output")
}

Expand All @@ -92,10 +95,13 @@ tasks {
it.groupValues[1].replace(Regex("(?s)- "), "\u2022 ").replace(Regex("`"), "").replace(Regex(","), "%2C")
}.take(1).joinToString("")

exec {
executable("dotnet")
args("msbuild","/t:Pack","${DotnetSolution}","/p:Configuration=${BuildConfiguration}","/p:PackageOutputPath=${rootDir}/output","/p:PackageReleaseNotes=${changeNotes}","/p:PackageVersion=${version}")
}
providers.exec {
commandLine("dotnet", "msbuild", "/t:Pack", DotnetSolution,
"/p:Configuration=${BuildConfiguration}",
"/p:PackageOutputPath=${rootDir}/output",
"/p:PackageReleaseNotes=${changeNotes}",
"/p:PackageVersion=${version}")
}.result.get()
}
}

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
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<!-- RIDER: To be updated with new Rider release -->

<SdkVersion>2025.1.0</SdkVersion>
<SdkVersion>2026.1.0.1</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
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using JetBrains.Annotations;
using JetBrains.DataFlow;
using JetBrains.Lifetimes;
using JetBrains.Threading;
Expand All @@ -12,11 +11,9 @@ public class StringListViewModel
{
private readonly GroupingEvent myEntryChanged;
private readonly Lifetime myLifetime;
[NotNull] private readonly Property<string> mySource;
private readonly Property<string> mySource;

public StringListViewModel(
[NotNull] Lifetime lifetime,
[NotNull] Property<string> source)
public StringListViewModel(Lifetime lifetime, Property<string> source)
{
myLifetime = lifetime;
mySource = source;
Expand Down Expand Up @@ -61,15 +58,12 @@ private void OnEntryChanged()

mySource.Value = string.Join("\n", entries);
}

public class StringListEntry
{
public readonly IProperty<string> Value;

public StringListEntry(
[NotNull] Lifetime lifetime,
[NotNull] ISimpleSignal entryChanged,
string value)
public StringListEntry(Lifetime lifetime, ISimpleSignal entryChanged, string 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 @@ -34,8 +34,8 @@ public XamlStylerOptionsPage(
Lifetime lifetime,
OptionsPageContext optionsPageContext,
OptionsSettingsSmartContext optionsSettingsSmartContext,
[NotNull] IconHostBase iconHost,
[NotNull] ICommonFileDialogs commonFileDialogs)
IconHostBase iconHost,
ICommonFileDialogs commonFileDialogs)
: base(lifetime, optionsPageContext, optionsSettingsSmartContext)
{
_iconHost = iconHost;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using JetBrains.Annotations;
using JetBrains.Application.Parts;
using JetBrains.Application.Settings;
using JetBrains.DocumentManagers;
Expand All @@ -16,42 +15,33 @@ namespace Xavalon.XamlStyler.Extension.Rider.Rider
[SolutionComponent(Instantiation.ContainerAsyncPrimaryThread)]
public class RiderXamlStylerHost
{
[NotNull]
private readonly Lifetime _lifetime;

[NotNull]
private readonly SolutionModel _solutionModel;

[NotNull]
private readonly ISolution _solution;

[NotNull]
private readonly DocumentManager _documentManager;

public RiderXamlStylerHost(
[NotNull] Lifetime lifetime,
[NotNull] SolutionModel solutionModel,
[NotNull] ISolution solution,
[NotNull] DocumentManager documentManager
)
Lifetime lifetime,
SolutionModel solutionModel,
ISolution solution,
DocumentManager documentManager)
{
_lifetime = lifetime;
_solutionModel = solutionModel;
_solution = solution;
_documentManager = documentManager;

var rdSolutionModel = solutionModel.TryGetCurrentSolution();
if (rdSolutionModel != null)
{
var rdXamlStylerModel = rdSolutionModel.GetXamlStylerModel();
rdXamlStylerModel.PerformReformat.SetAsync(PerformReformatHandler);
}

if (rdSolutionModel == null) return;

var rdXamlStylerModel = rdSolutionModel.GetXamlStylerModel();
rdXamlStylerModel.PerformReformat.SetAsync(PerformReformatHandler);
}

private Task<RdXamlStylerFormattingResult> PerformReformatHandler(
Lifetime requestLifetime,
RdXamlStylerFormattingRequest request
)
RdXamlStylerFormattingRequest request)
{
return Task.Run(
() =>
Expand Down Expand Up @@ -86,15 +76,11 @@ RdXamlStylerFormattingRequest request
.StyleDocument(request.DocumentText)
.Replace("\r\n", "\n");

if (request.DocumentText == formattedText)
{
return new RdXamlStylerFormattingResult(true, false, "");
}
return new RdXamlStylerFormattingResult(true, true, formattedText);
return request.DocumentText == formattedText ? new RdXamlStylerFormattingResult(true, false, "") : new RdXamlStylerFormattingResult(true, true, formattedText);
},
requestLifetime
)
.ToRdTask();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace JetBrains.Rider.Model


/// <summary>
/// <p>Generated from: XamlStylerModel.kt:12</p>
/// <p>Generated from: XamlStylerModel.kt:11</p>
/// </summary>
public class XamlStylerModel : RdExtBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using JetBrains.Annotations;
using JetBrains.Application.Settings;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
Expand All @@ -16,81 +15,98 @@ public static class StylerOptionsFactory
{
public static IStylerOptions FromSettings(
IContextBoundSettingsStoreLive settings,
[CanBeNull] ISolution solution,
[CanBeNull] IProject project,
[CanBeNull] IPsiSourceFileWithLocation psiSourceFileWithLocation)
ISolution? solution,
IProject? project,
IPsiSourceFileWithLocation? psiSourceFileWithLocation)
{
return FromSettings(
settings: settings,
solution: solution,
projectPath: project?.ProjectFileLocation?.FullPath,
solution: solution,
projectPath: project?.ProjectFileLocation?.FullPath,
sourceFilePath: psiSourceFileWithLocation?.Location.FullPath);
}

public static IStylerOptions FromSettings(
IContextBoundSettingsStoreLive settings,
[CanBeNull] ISolution solution,
[CanBeNull] string projectPath,
[CanBeNull] string sourceFilePath)
ISolution? solution,
string? projectPath,
string? sourceFilePath)
{
// Normalize paths, because Rider may pass them in with differing separator chars
projectPath = NormalizePath(projectPath);
sourceFilePath = NormalizePath(sourceFilePath);
// Normalize paths, because Rider may pass them in with differing separator chars
projectPath = NormalizePath(projectPath);
sourceFilePath = NormalizePath(sourceFilePath);

// 1. Load global settings
IStylerOptions fallbackOptions = new StylerOptions();
IStylerOptions stylerOptions = new StylerOptions();

stylerOptions.IndentSize = settings.GetValue((XamlStylerSettings s) => s.IndentSize);
stylerOptions.IndentWithTabs = settings.GetValue((XamlStylerSettings s) => s.IndentWithTabs);

stylerOptions.AttributesTolerance = settings.GetValue((XamlStylerSettings s) => s.AttributesTolerance);
stylerOptions.KeepFirstAttributeOnSameLine = settings.GetValue((XamlStylerSettings s) => s.KeepFirstAttributeOnSameLine);
stylerOptions.MaxAttributeCharactersPerLine = settings.GetValue((XamlStylerSettings s) => s.MaxAttributeCharactersPerLine);
stylerOptions.KeepFirstAttributeOnSameLine =
settings.GetValue((XamlStylerSettings s) => s.KeepFirstAttributeOnSameLine);
stylerOptions.MaxAttributeCharactersPerLine =
settings.GetValue((XamlStylerSettings s) => s.MaxAttributeCharactersPerLine);
stylerOptions.MaxAttributesPerLine = settings.GetValue((XamlStylerSettings s) => s.MaxAttributesPerLine);
stylerOptions.NoNewLineElements = settings.GetValue((XamlStylerSettings s) => s.NoNewLineElements);
stylerOptions.PutAttributeOrderRuleGroupsOnSeparateLines = settings.GetValue((XamlStylerSettings s) => s.PutAttributeOrderRuleGroupsOnSeparateLines);
stylerOptions.PutAttributeOrderRuleGroupsOnSeparateLines = settings.GetValue((XamlStylerSettings s) =>
s.PutAttributeOrderRuleGroupsOnSeparateLines);
stylerOptions.AttributeIndentation = settings.GetValue((XamlStylerSettings s) => s.AttributeIndentation);
stylerOptions.AttributeIndentationStyle = settings.GetValue((XamlStylerSettings s) => s.AttributeIndentationStyle);
stylerOptions.RemoveDesignTimeReferences = settings.GetValue((XamlStylerSettings s) => s.RemoveDesignTimeReferences);
stylerOptions.EnableAttributeReordering = settings.GetValue((XamlStylerSettings s) => s.EnableAttributeReordering);
stylerOptions.AttributeOrderingRuleGroups = settings.GetValue((XamlStylerSettings s) => s.AttributeOrderingRuleGroups)?.SplitByNewLine();
if (stylerOptions.AttributeOrderingRuleGroups == null || stylerOptions.AttributeOrderingRuleGroups.Length == 0)
stylerOptions.AttributeIndentationStyle =
settings.GetValue((XamlStylerSettings s) => s.AttributeIndentationStyle);
stylerOptions.RemoveDesignTimeReferences =
settings.GetValue((XamlStylerSettings s) => s.RemoveDesignTimeReferences);
stylerOptions.EnableAttributeReordering =
settings.GetValue((XamlStylerSettings s) => s.EnableAttributeReordering);
stylerOptions.AttributeOrderingRuleGroups = settings
.GetValue((XamlStylerSettings s) => s.AttributeOrderingRuleGroups)?.SplitByNewLine();
if (stylerOptions.AttributeOrderingRuleGroups == null ||
stylerOptions.AttributeOrderingRuleGroups.Length == 0)
{
stylerOptions.AttributeOrderingRuleGroups = fallbackOptions.AttributeOrderingRuleGroups;
}

stylerOptions.FirstLineAttributes = settings.GetValue((XamlStylerSettings s) => s.FirstLineAttributes);
stylerOptions.OrderAttributesByName = settings.GetValue((XamlStylerSettings s) => s.OrderAttributesByName);
stylerOptions.PutEndingBracketOnNewLine = settings.GetValue((XamlStylerSettings s) => s.PutEndingBracketOnNewLine);
stylerOptions.RemoveEndingTagOfEmptyElement = settings.GetValue((XamlStylerSettings s) => s.RemoveEndingTagOfEmptyElement);
stylerOptions.SpaceBeforeClosingSlash = settings.GetValue((XamlStylerSettings s) => s.SpaceBeforeClosingSlash);
stylerOptions.RootElementLineBreakRule = settings.GetValue((XamlStylerSettings s) => s.RootElementLineBreakRule);
stylerOptions.PutEndingBracketOnNewLine =
settings.GetValue((XamlStylerSettings s) => s.PutEndingBracketOnNewLine);
stylerOptions.RemoveEndingTagOfEmptyElement =
settings.GetValue((XamlStylerSettings s) => s.RemoveEndingTagOfEmptyElement);
stylerOptions.SpaceBeforeClosingSlash =
settings.GetValue((XamlStylerSettings s) => s.SpaceBeforeClosingSlash);
stylerOptions.RootElementLineBreakRule =
settings.GetValue((XamlStylerSettings s) => s.RootElementLineBreakRule);
stylerOptions.ReorderVSM = settings.GetValue((XamlStylerSettings s) => s.ReorderVSM);
stylerOptions.ReorderGridChildren = settings.GetValue((XamlStylerSettings s) => s.ReorderGridChildren);
stylerOptions.ReorderCanvasChildren = settings.GetValue((XamlStylerSettings s) => s.ReorderCanvasChildren);
stylerOptions.ReorderSetters = settings.GetValue((XamlStylerSettings s) => s.ReorderSetters);
stylerOptions.FormatMarkupExtension = settings.GetValue((XamlStylerSettings s) => s.FormatMarkupExtension);
stylerOptions.NoNewLineMarkupExtensions = settings.GetValue((XamlStylerSettings s) => s.NoNewLineMarkupExtensions);
stylerOptions.NoNewLineMarkupExtensions =
settings.GetValue((XamlStylerSettings s) => s.NoNewLineMarkupExtensions);
stylerOptions.ThicknessStyle = settings.GetValue((XamlStylerSettings s) => s.ThicknessStyle);
stylerOptions.ThicknessAttributes = settings.GetValue((XamlStylerSettings s) => s.ThicknessAttributes);
stylerOptions.FormatOnSave = settings.GetValue((XamlStylerSettings s) => s.FormatOnSave);
stylerOptions.CommentSpaces = settings.GetValue((XamlStylerSettings s) => s.CommentSpaces);
stylerOptions.ConfigPath = settings.GetValue((XamlStylerSettings s) => s.ConfigPath)?.FullPath;
stylerOptions.SearchToDriveRoot = settings.GetValue((XamlStylerSettings s) => s.SearchToDriveRoot);
stylerOptions.SuppressProcessing = settings.GetValue((XamlStylerSettings s) => s.SuppressProcessing);

// 2. Try finding settings in our project/solution?
if (!string.IsNullOrEmpty(projectPath) || !string.IsNullOrEmpty(sourceFilePath))
{
var searchToDriveRoot = settings.GetValue((XamlStylerSettings s) => s.SearchToDriveRoot);

var highestRootPath = solution != null && !solution.IsTemporary
? (searchToDriveRoot ? Path.GetPathRoot(solution.SolutionFilePath.FullPath) : Path.GetDirectoryName(solution.SolutionFilePath.FullPath))
? (searchToDriveRoot
? Path.GetPathRoot(solution.SolutionFilePath.FullPath)
: Path.GetDirectoryName(solution.SolutionFilePath.FullPath))
: string.Empty;

var itemPath = sourceFilePath;

var configPath = (!string.IsNullOrEmpty(itemPath) && itemPath.StartsWith(highestRootPath, StringComparison.OrdinalIgnoreCase))

var configPath = (!string.IsNullOrEmpty(itemPath) &&
itemPath.StartsWith(highestRootPath, StringComparison.OrdinalIgnoreCase))
? GetConfigPathForProject(highestRootPath, itemPath)
: GetConfigPathForProject(projectPath ?? itemPath, itemPath);
if (!string.IsNullOrEmpty(configPath))
Expand All @@ -111,27 +127,29 @@ public static IStylerOptions FromSettings(
// Note: stylerOptions.UseVisualStudioIndentSize is hardcoded to "True", which means we'll always use IDE settings when in IDE context.
// To overcome this, we're ignoring the setting from XamlStyler settings files, and using the configuration in the IDE, so we can toggle this on/off.
var schema = Shell.Instance.GetComponent<ISettingsSchema>();
if (/*stylerOptions.UseVisualStudioIndentSize ||*/ settings.GetValue((XamlStylerSettings s) => s.UseIdeIndentSize))
if ( /*stylerOptions.UseVisualStudioIndentSize ||*/
settings.GetValue((XamlStylerSettings s) => s.UseIdeIndentSize))
{
stylerOptions.IndentSize = xamlFormatterSettings.INDENT_SIZE;
}

if (/*stylerOptions.UseVisualStudioIndentWithTabs ||*/ settings.GetValue((XamlStylerSettings s) => s.UseIdeIndentWithTabs))

if ( /*stylerOptions.UseVisualStudioIndentWithTabs ||*/
settings.GetValue((XamlStylerSettings s) => s.UseIdeIndentWithTabs))
{
stylerOptions.IndentWithTabs = xamlFormatterSettings.INDENT_STYLE == IndentStyle.Tab;
}
}

return stylerOptions;
}

private static string GetConfigPathForProject(string highestRootPath, string path)
{
if (path.IsNullOrEmpty())
{
return null;
}

var currentDirectory = Path.GetDirectoryName(path);
while (currentDirectory?.StartsWith(highestRootPath, StringComparison.InvariantCultureIgnoreCase) ?? false)
{
Expand All @@ -140,7 +158,7 @@ private static string GetConfigPathForProject(string highestRootPath, string pat
{
return configurationFilePath;
}

currentDirectory = Path.GetDirectoryName(currentDirectory);
}

Expand Down
Loading
Loading