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

Definition generation on Requests and CSharp syntax formatting #35

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

galadril
Copy link

@galadril galadril commented Jul 12, 2024

  • Definition json generation on Requests
  • CSharp / Json Syntax Formatting (and a copy button for easy copying)
  • Copy buttons for Code / Definition

image

image

markheinis and others added 10 commits July 11, 2024 09:10
- Reordered `using` directives to place `System` at the top.
- Reformatted `Document` object initialization for clarity.
- Changed `StringField` to `TextField` for `request.body`, `response.body`, and `response.bodyAsJson` to handle large text data better.
Updated the following package versions in `WireMock.Net.Extensions.WireMockInspector.csproj`:
- `WireMock.Net.Abstractions` from `1.5.24` to `1.5.60`.

Updated the following package versions in `WireMockInspector.csproj`:
- `Avalonia` from `11.0.6` to `11.0.11`.
- `Avalonia.AvaloniaEdit` from `11.0.5` to `11.0.6`.
- `Avalonia.Controls.DataGrid` from `11.0.6` to `11.0.11`.
- `Avalonia.Desktop` from `11.0.6` to `11.0.11`.
- `Avalonia.Svg` from `11.0.0.9` to `11.0.0.18`.
- `Avalonia.Themes.Fluent` from `11.0.6` to `11.0.11`.
- Conditional package `Avalonia.Diagnostics` for `Debug` configuration from `11.0.6` to `11.0.11`.
- `Avalonia.ReactiveUI` from `11.0.6` to `11.0.11`.
- `AvaloniaEdit.TextMate` from `11.0.5` to `11.0.6`.
- `Fluid.Core` from `2.5.0` to `2.10.0`.
- `TextMateSharp.Grammars` from `1.0.56` to `1.0.58`.
- `WireMock.Net.RestClient` from `1.5.46` to `1.5.60`.

These updates ensure the projects use the latest features, improvements, and bug fixes provided by these packages.
The namespace of the `CSharpFormatter` class has been changed from
`WireMockInspector.ViewModels` to `WireMockInspector.CodeGenerators`.
This reorganization better categorizes the class under a namespace
that aligns with its functionality related to code generation.
- Added `FormatArray` method to `CSharpFormatter`.
- Removed `MappingCodeGenerator` class and its methods.
- Cleared `default_template.liquid` content.
- Changed `EndNode` class visibility to private in `GraphConverter`.
- Made several methods in `GraphConverter` private.
- Removed unused imports from `MainWindowViewModel`.
- Updated `SelectedTemplate` property initialization in `MainWindowViewModel`.
- Added `JsonGenerator` property to `MainWindowViewModel`.
- Added `CopyActualValue` command to `MappingCodeGeneratorViewModel`.
- Updated `OutputCode` property in `MappingCodeGeneratorViewModel`.
- Made formatting and visibility changes in `MatchDetailsViewModel`.
- Made `luceneVersion` constant private in `SearchHelper`.
- Updated XAML layouts in `MappingPage` and `RequestPage`.
- Added `Definition` tab in `RequestPage` for JSON generator options.
- Updated `MarkdownCode` language identifier to "csharp" in `MainWindowViewModel.cs` and `MappingCodeGeneratorViewModel.cs`.
- Refactored `CodeBlockViewer.cs` for better readability:
  - Restructured class to organize constructor and methods.
  - Updated `SetMarkdown` method to use `CSharpSyntaxHighlighter`.
  - Moved `DiffLineBackgroundRenderer` class to a separate file.
- Added `CSharpSyntaxHighlighter` class in `CSharpSyntaxHighlighter.cs`.
- Moved and refactored `DiffLineBackgroundRenderer` class to `DiffLineBackgroundRenderer.cs` for improved clarity and separation of concerns.
@galadril
Copy link
Author

Hope you like the changes @cezarypiatek ;)
I was also planning to create formatter/styler for xml responses later (guess other PR)

@cezarypiatek
Copy link
Collaborator

I took your words for granted that it solves the issu

@galadril
Copy link
Author

Ok thanks, so this PR is going to take you a bit more time ;)

- Removed `HttpStatusCodeToDescriptionConverter`, `RequestMethodToColorConverter`, and `ResponseCodeToColorConverter` from `WireMockInspector.ViewModels`.
- Re-added the above converters in `WireMockInspector.Converters` for better modularity.
- Updated namespace references in XAML files from `viewModels` to `converters`.
- Introduced `XmlSyntaxHighlighter` in `WireMockInspector.Views.Transformer` for XML syntax highlighting.
- Enhanced `CodeBlockViewer.cs` to support XML highlighting, improving readability.
- Adjusted XAML files to use the new converter namespace, ensuring UI consistency.
This commit represents a significant refactoring and enhancement of the converter usage within the WireMockInspector application. Key changes include the relocation of converter classes (`EnumItemsConverter`, `GraphConverter`, `StringListConverter`, `StringMatchConverter`) from the `WireMockInspector.ViewModels` namespace to a new `WireMockInspector.Converters` namespace, improving modularity and clarity. New converter classes have been added, encapsulating the conversion logic for better reusability. Updates in various XAML files reflect these namespace changes, ensuring correct converter references in data-binding expressions. Additionally, unused `using` directives have been cleaned up, and a new `SettingsWrapperTemplateSelector` class has been introduced to enhance dynamic UI generation capabilities. These changes collectively aim to improve the maintainability and functionality of the application's UI data presentation.
- Adopted target-typed `new` expressions across various files for cleaner instantiation.
- Enhanced graph drawing in `GraphConverter.cs` with streamlined object creation.
- Simplified `XmlDocument` object instantiation in multiple files for conciseness.
- Updated singleton patterns in converters and formatters to modern C# practices.
- Improved XML content formatting in markdown with `.TryToReformat()` in `MainWindowViewModel.cs`.
- Refined syntax highlighting in `CSharpSyntaxHighlighter.cs`, `JsonSyntaxHighlighter.cs`, and `XmlSyntaxHighlighter.cs` with updated regex patterns and object instantiation.
- Added `XmlFormatter.cs` for better XML handling, including escaping, pretty-printing, and conversion utilities.
- Adjusted `Fluid.Core` package version in `WireMockInspector.csproj` for compatibility or feature requirements.
@galadril
Copy link
Author

Added also XML Syntax formatting and styling
image

this.TextArea.TextView.LineTransformers.Add(new DiffLineBackgroundRenderer(md.oldTextLines));
if (md.lang == "csharp")
{
this.TextArea.TextView.LineTransformers.Add(new CSharpSyntaxHighlighter());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Syntax highliting should be handled automatically by Avalonia.Edit and I'm pretty sure it was working correctly so far (for json and csharp). Why did you implemented custom syntax highlighers?

Copy link
Author

Choose a reason for hiding this comment

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

Actually it was just all white, i didnt saw any syntax highliting.

@cezarypiatek
Copy link
Collaborator

cezarypiatek commented Jul 14, 2024

Hope you like the changes @cezarypiatek ;) I was also planning to create formatter/styler for xml responses later (guess other PR)

Ignore my last comment, I was checking it on mobile and I thought it was in different thread (previous pr).
This PR is quite large and I need some time to review what actually was changed.....

@cezarypiatek
Copy link
Collaborator

cezarypiatek commented Jul 16, 2024

  1. You mixed refactors with new features which makes it really hard to follow what actually was changed. Please avoid such practice in the future.
  2. JsonCodeGenerator could be simply implemented by providing only a custom liquid template
  3. Syntax highliting should my handled by Avalonia.Edit. If it doesn't work for you then probabaly something was broken during dependency update made in previous PR. More info about syntax hightliting in Avalonia.Edit https://github.com/AvaloniaUI/AvaloniaEdit?tab=readme-ov-file#how-to-set-up-textmate-theme-and-syntax-highlighting-for-my-project

I will try to fix those things later and integrated your changes.

@galadril
Copy link
Author

galadril commented Jul 16, 2024

ok thanks

Btw JsonCodeGenerator does have a bit different code then the other CodeGenerator

Mainly on (re)formatting and escaping

@cezarypiatek
Copy link
Collaborator

Ok, you added a dedicated json escaping function and a default template selector. It could be incorporated in the original implementation. The only thing that I don't understand is the code below, could you explain what's the purpose od that replace?

Regex.Replace(result, @",(?=\s*[]}])", "");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants