### Install and Start Development Server Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.VSCode/CONTRIBUTING.md Install project dependencies and start the development server which watches for file changes and recompiles. ```bash npm install npm run start ``` -------------------------------- ### Install Husky.Net and set up pre-commit hook Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Pre-commit.md Commands to install Husky.Net and its pre-commit hook. This includes creating a tool manifest, installing the husky package, and running the husky install command. ```bash cd dotnet new tool-manifest dotnet tool install husky dotnet husky install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/belav/csharpier/blob/main/Src/Website/README.md Starts a local development server for live preview. Changes are reflected without a server restart. ```bash $ yarn start ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/belav/csharpier/blob/main/Src/Website/README.md Run this command to install project dependencies using Yarn. ```bash $ yarn ``` -------------------------------- ### Start CSharpier Server Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/CLI.md Use this command to start an HTTP server for faster file formatting, primarily for IDE plugins. It reduces overhead compared to formatting individual files. ```bash dotnet csharpier server ``` -------------------------------- ### Install CSharpier Locally Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Installation.md Install CSharpier as a local .NET tool. This ensures the project uses the correct version. Run these commands in the project directory. ```bash # if you don't yet have a .config/dotnet-tools.json file dotnet new tool-manifest dotnet tool install csharpier ``` -------------------------------- ### Install CSharpier Globally Source: https://github.com/belav/csharpier/blob/main/README.md Install CSharpier globally using the .NET CLI. This command makes the `csharpier` executable available system-wide. ```bash dotnet tool install csharpier -g ``` -------------------------------- ### Install CSharpier.MSBuild Package Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/MsBuild.md Use this command in the Package Manager Console to install the CSharpier.MSBuild NuGet package. ```powershell Install-Package CSharpier.MSBuild ``` -------------------------------- ### Install CSharpier CLI Tool Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/About.md Install CSharpier globally using the .NET CLI. This command makes the CSharpier formatter available on your system. ```bash dotnet tool install csharpier ``` -------------------------------- ### C# Code Formatting Example Source: https://github.com/belav/csharpier/blob/main/README.md Demonstrates the code formatting applied by CSharpier. The 'After' example shows how long method calls are reformatted for better readability. ```csharp public class ClassName { public void CallMethod() { this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } } ``` ```csharp public class ClassName { public void CallMethod() { this.LongUglyMethod( "1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); } } ``` -------------------------------- ### Install CSharpier to Custom Path Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/EditorsTroubleshooting.md Use this command to install a specific version of CSharpier to a custom tool path, often used by editor extensions to avoid conflicts with global installations. ```bash dotnet tool install csharpier --version [CSharpierVersion] --tool-path [PathFromStep2] ``` -------------------------------- ### WithStartProcessingInstructionToken for XmlProcessingInstructionSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Creates a new XmlProcessingInstructionSyntax with an updated start processing instruction token. ```csharp public XmlProcessingInstructionSyntax WithStartProcessingInstructionToken(SyntaxToken startProcessingInstructionToken) => Update(startProcessingInstructionToken, this.Name, this.TextTokens, this.EndProcessingInstructionToken); ``` -------------------------------- ### Install CSharpier VS Code Extension Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.VSCode/README.md Install the CSharpier extension directly within VS Code using the command palette. ```shell ext install csharpier.csharpier-vscode ``` -------------------------------- ### Install CSharpier as a Local Dotnet Tool in Devcontainers Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.VSCode/README.md Steps to install CSharpier as a local dotnet tool within a devcontainer environment, including creating a tool manifest and adding CSharpier. ```bash # if no .config/dotnet-tools.json file exists dotnet new tool-manifest # add csharpier to manifest dotnet tool install csharpier # rebuild container image ``` -------------------------------- ### Update CSharpier Locally Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Installation.md Update an existing local installation of CSharpier. Run this command from the directory where CSharpier was installed. ```bash dotnet tool update csharpier ``` -------------------------------- ### Code Formatting Example: Before Source: https://github.com/belav/csharpier/blob/main/Nuget/README.md Illustrates the C# code structure before applying CSharpier formatting. This example shows a class with a method containing a long method call with multiple arguments. ```csharp public class ClassName { public void CallMethod() { this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } } ``` -------------------------------- ### Add CSharpier.Core NuGet Package Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/API.md Install the CSharpier.Core package to enable programmatic code formatting. ```bash dotnet add package CSharpier.Core ``` -------------------------------- ### C# Code Formatting Example: Before Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/About.md Illustrates the formatting of a C# code snippet before applying CSharpier. ```csharp public class ClassName { public void CallMethod() { var shuffle = shuffle.Skip(26).LogQuery("Bottom Half").InterleaveSequenceWith(shuffle.Take(26).LogQuery("Top Half"), shuffle.Skip(26).LogQuery("Bottom Half")).LogQuery("Shuffle").ToArray(); } } ``` -------------------------------- ### Attach Husky to a project file Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Pre-commit.md Optionally, automate Husky installation for future developers by attaching it to a specific project file. This command helps in setting up the environment for new contributors. ```bash dotnet husky attach ``` -------------------------------- ### C# Code Formatting Example Source: https://github.com/belav/csharpier/blob/main/docs/About.md Demonstrates the difference in code formatting before and after applying CSharpier. The 'After' version shows improved readability through consistent indentation and line breaks. ```csharp public class ClassName { public void CallMethod() { var shuffle = shuffle.Skip(26).LogQuery("Bottom Half").InterleaveSequenceWith(shuffle.Take(26).LogQuery("Top Half"), shuffle.Skip(26).LogQuery("Bottom Half")).LogQuery("Shuffle").ToArray(); } } ``` ```csharp public class ClassName { public void CallMethod() { var shuffle = shuffle .Skip(26) .LogQuery("Bottom Half") .InterleaveSequenceWith( shuffle.Take(26).LogQuery("Top Half"), shuffle.Skip(26).LogQuery("Bottom Half") ) .LogQuery("Shuffle") .ToArray(); } } ``` -------------------------------- ### C# Code Formatting Example: After Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/About.md Shows the same C# code snippet after being formatted by CSharpier, demonstrating improved readability. ```csharp public class ClassName { public void CallMethod() { var shuffle = shuffle .Skip(26) .LogQuery("Bottom Half") .InterleaveSequenceWith( shuffle.Take(26).LogQuery("Top Half"), shuffle.Skip(26).LogQuery("Bottom Half") ) .LogQuery("Shuffle") .ToArray(); } } ``` -------------------------------- ### Format Project Files with CSharpier CLI Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/About.md Format all files in the current directory and its subdirectories using the CSharpier CLI. Ensure CSharpier is installed first. ```bash dotnet csharpier format . ``` -------------------------------- ### XmlElementStartTag Syntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents the start tag of an XML element. Provides methods to update and modify its components like tokens and attributes. ```csharp public SyntaxToken GreaterThanToken => new SyntaxToken(this, ((InternalSyntax.XmlElementStartTagSyntax)this.Green).greaterThanToken, GetChildPosition(3), GetChildIndex(3)); internal override SyntaxNode? GetNodeSlot(int index) => index switch { 1 => GetRed(ref this.name, 1)!, 2 => GetRed(ref this.attributes, 2)!, _ => null, }; internal override SyntaxNode? GetCachedSlot(int index) => index switch { 1 => this.name, 2 => this.attributes, _ => null, }; public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitXmlElementStartTag(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitXmlElementStartTag(this); public XmlElementStartTagSyntax Update(SyntaxToken lessThanToken, XmlNameSyntax name, SyntaxList attributes, SyntaxToken greaterThanToken) { if (lessThanToken != this.LessThanToken || name != this.Name || attributes != this.Attributes || greaterThanToken != this.GreaterThanToken) { var newNode = SyntaxFactory.XmlElementStartTag(lessThanToken, name, attributes, greaterThanToken); var annotations = GetAnnotations(); return annotations?.Length > 0 ? newNode.WithAnnotations(annotations) : newNode; } return this; } public XmlElementStartTagSyntax WithLessThanToken(SyntaxToken lessThanToken) => Update(lessThanToken, this.Name, this.Attributes, this.GreaterThanToken); public XmlElementStartTagSyntax WithName(XmlNameSyntax name) => Update(this.LessThanToken, name, this.Attributes, this.GreaterThanToken); public XmlElementStartTagSyntax WithAttributes(SyntaxList attributes) => Update(this.LessThanToken, this.Name, attributes, this.GreaterThanToken); public XmlElementStartTagSyntax WithGreaterThanToken(SyntaxToken greaterThanToken) => Update(this.LessThanToken, this.Name, this.Attributes, greaterThanToken); public XmlElementStartTagSyntax AddAttributes(params XmlAttributeSyntax[] items) => WithAttributes(this.Attributes.AddRange(items)); } ``` -------------------------------- ### JSON Configuration with Overrides Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Configuration.md Define formatting rules for specific file types using the 'overrides' array in a JSON configuration file. This example sets specific options for *.{csr,cst} files. ```json { "overrides": [ { "files": "*.{csr,cst}", "formatter": "csharp", "indentSize": 2, "useTabs": true, "printWidth": 10, "endOfLine": "LF" } ] } ``` -------------------------------- ### YAML Configuration with Overrides Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Configuration.md Define formatting rules for specific file types using the 'overrides' list in a YAML configuration file. This example sets specific options for *.{csr,cst} files. ```yaml overrides: - files: "*.{csr,cst}" formatter: "csharp" indentSize: 2 useTabs: true printWidth: 10 endOfLine: "LF" ``` -------------------------------- ### Code Formatting Example: After Source: https://github.com/belav/csharpier/blob/main/Nuget/README.md Shows the C# code after CSharpier formatting has been applied. Long method calls with multiple arguments are automatically reformatted for better readability. ```csharp public class ClassName { public void CallMethod() { this.LongUglyMethod( "1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); } } ``` -------------------------------- ### XmlElementStartTagSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents the starting tag of an XML element. It includes properties for the less than token, name, and attributes. ```APIDOC ## XmlElementStartTagSyntax ### Description Represents the starting tag of an XML element. It includes properties for the less than token, name, and attributes. ### Properties - `LessThanToken`: The '<' token that marks the beginning of the start tag. - `Name`: The name of the XML element. - `Attributes`: A SyntaxList of XML attributes associated with the start tag. ``` -------------------------------- ### XmlElementStartTagSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents the start tag of an XML element, such as ''. It includes tokens for '<', the element name, attributes, and '>'. ```APIDOC ## XmlElementStartTagSyntax ### Description Represents the start tag of an XML element, including the opening bracket, element name, attributes, and closing bracket. ### Methods - `GreaterThanToken`: Gets the closing '>' token of the start tag. - `GetNodeSlot(int index)`: Retrieves a child node at the specified index. - `GetCachedSlot(int index)`: Retrieves a cached child node at the specified index. - `Accept(CSharpSyntaxVisitor visitor)`: Accepts a visitor to traverse the syntax tree. - `Accept(CSharpSyntaxVisitor visitor)`: Accepts a visitor with a result type. - `Update(SyntaxToken lessThanToken, XmlNameSyntax name, SyntaxList attributes, SyntaxToken greaterThanToken)`: Creates a new instance of the node with updated children. - `WithLessThanToken(SyntaxToken lessThanToken)`: Creates a new instance with the LessThanToken replaced. - `WithName(XmlNameSyntax name)`: Creates a new instance with the Name replaced. - `WithAttributes(SyntaxList attributes)`: Creates a new instance with the Attributes replaced. - `WithGreaterThanToken(SyntaxToken greaterThanToken)`: Creates a new instance with the GreaterThanToken replaced. - `AddAttributes(params XmlAttributeSyntax[] items)`: Adds attributes to the existing list of attributes. ``` -------------------------------- ### Format from Stdin Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/CLI.md When no path is specified and input is read from stdin, ignore files are not considered, options are located relative to the current directory, and the file is assumed to be C# unless it starts with '<'. ```shell dotnet csharpier format ``` -------------------------------- ### Run CSharpier Check in CI/CD Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/ContinuousIntegration.md Execute dotnet tool restore and dotnet csharpier check . commands in your CI/CD pipeline to verify code formatting. This example shows a GitHub Actions workflow. ```bash dotnet tool restore dotnet csharpier check . ``` ```yaml name: Validate PR on: pull_request: branches: [ main ] jobs: check_formatting: runs-on: ubuntu-latest name: Check Formatting steps: - uses: actions/checkout@v2 - run: | dotnet tool restore dotnet csharpier check . ``` -------------------------------- ### Specify Server Port Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/CLI.md When starting the CSharpier server, you can specify a custom port using the `--server-port` option. If not provided, a random unused port will be assigned. ```bash dotnet csharpier server --server-port 1234 ``` -------------------------------- ### EditorConfig Configuration Source: https://github.com/belav/csharpier/blob/main/docs/Configuration.md Configure CSharpier using an .editorconfig file. This example sets options for .cs and .csx files, including non-configurable behaviors and standard formatting settings. ```ini [*.{cs,csx}] # Non-configurable behaviors charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true dotnet_sort_system_directives_first = true dotnet_separate_import_directive_groups = false # Configurable behaviors # end_of_line = lf - there is no 'auto' with an .editorconfig indent_style = space indent_size = 4 max_line_length = 100 [*.{config,csproj,props,slnx,targets,xaml,xml}] indent_style = space indent_size = 2 max_line_length = 100 ``` -------------------------------- ### EditorConfig for C# and C#X Files Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Configuration.md Configure CSharpier and other .NET formatting behaviors using an .editorconfig file. This example sets options for *.{cs,csx} files, including line endings, indentation, and line length. ```ini [*.{cs,csx}] # Non-configurable behaviors charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true dotnet_sort_system_directives_first = true dotnet_separate_import_directive_groups = false # Configurable behaviors # end_of_line = lf - there is no 'auto' with an .editorconfig indent_style = space indent_size = 4 max_line_length = 100 ``` -------------------------------- ### EditorConfig for Other File Types Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Configuration.md Configure CSharpier formatting for various file types using an .editorconfig file. This example sets indentation and line length for configuration, project, and markup files. ```ini [*.{config,csproj,props,slnx,targets,xaml,xml}] indent_style = space indent_size = 2 max_line_length = 100 ``` -------------------------------- ### Build Website for Production Source: https://github.com/belav/csharpier/blob/main/Src/Website/README.md Generates a production-ready build of the static website. ```bash $ yarn build ``` -------------------------------- ### Package and Publish Extension Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.VSCode/CONTRIBUTING.md Steps to update the version, package the extension, and publish it to the marketplace using vsce or ovsx. ```bash npx vsce package npx vsce publish -p ``` ```bash npx ovsx publish -p ``` -------------------------------- ### Configure .NET Tools Manifest Source: https://github.com/belav/csharpier/blob/main/docs/ContinuousIntegration.md Set up a .NET tool manifest file to specify the CSharpier version. Replace `[SpecificVersion]` with your current CSharpier version. ```json { "version": 1, "isRoot": true, "tools": { "csharpier": { "version": "[SpecificVersion]", "commands": [ "csharpier" ] } } } ``` -------------------------------- ### ParameterSyntax Identifier Property Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Gets the identifier token for a ParameterSyntax node. ```csharp /// Gets the identifier. public SyntaxToken Identifier => new SyntaxToken(this, ((InternalSyntax.ParameterSyntax)this.Green).identifier, GetChildPosition(3), GetChildIndex(3)); ``` -------------------------------- ### ParameterSyntax Type Property Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Gets the type of the parameter in a ParameterSyntax node. ```csharp public override TypeSyntax? Type => GetRed(ref this.type, 2); ``` -------------------------------- ### ParameterSyntax Modifiers Property Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Gets the modifier list for a ParameterSyntax node. ```csharp /// Gets the modifier list. public override SyntaxTokenList Modifiers { get { var slot = this.Green.GetSlot(1); return slot != null ? new SyntaxTokenList(this, slot, GetChildPosition(1), GetChildIndex(1)) : default; } } ``` -------------------------------- ### ParameterSyntax Default Property Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Gets the default value clause for a ParameterSyntax node. ```csharp public EqualsValueClauseSyntax? Default => GetRed(ref this.@default, 4); ``` -------------------------------- ### ParameterSyntax AttributeLists Property Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Gets the attribute declaration list for a ParameterSyntax node. ```csharp /// Gets the attribute declaration list. public override SyntaxList AttributeLists => new SyntaxList(GetRed(ref this.attributeLists, 0)); ``` -------------------------------- ### Update CSharpier Globally Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Installation.md Update an existing global installation of CSharpier. This command can be run from any location. ```bash dotnet tool update csharpier -g ``` -------------------------------- ### AccessorListSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents an accessor list in C# syntax, typically containing get or set accessors. ```APIDOC ## AccessorListSyntax ### Description Provides methods to update and manipulate an accessor list. ### Methods - `Update(SyntaxToken openBraceToken, SyntaxList accessors, SyntaxToken closeBraceToken)`: Updates the accessor list with new tokens and accessors. - `WithOpenBraceToken(SyntaxToken openBraceToken)`: Returns a new AccessorListSyntax with the specified open brace token. - `WithAccessors(SyntaxList accessors)`: Returns a new AccessorListSyntax with the specified accessors. - `WithCloseBraceToken(SyntaxToken closeBraceToken)`: Returns a new AccessorListSyntax with the specified close brace token. - `AddAccessors(params AccessorDeclarationSyntax[] items)`: Adds one or more accessor declarations to the list. ``` -------------------------------- ### Basic YAML Configuration Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Configuration.md Use this YAML configuration in a .csharpierrc file to set formatting preferences like line width, tab usage, and indentation size. ```yaml printWidth: 100 useTabs: false indentSize: 4 endOfLine: auto ``` -------------------------------- ### Constructor Initializer Syntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Details the structure and manipulation of constructor initializer syntax, including 'this' or 'base' keywords and argument lists. ```APIDOC ## ConstructorInitializerSyntax ### Description Represents a constructor initializer, which can be a 'this' or 'base' initializer. ### Properties - **ColonToken** (SyntaxToken): Gets the colon token that precedes the initializer. - **ThisOrBaseKeyword** (SyntaxToken): Gets the 'this' or 'base' keyword. - **ArgumentList** (ArgumentListSyntax): Gets the argument list associated with the initializer. ### Methods #### Update Updates the constructor initializer with new tokens and argument list. - **Parameters** - `colonToken` (SyntaxToken): The new colon token. - `thisOrBaseKeyword` (SyntaxToken): The new 'this' or 'base' keyword. - `argumentList` (ArgumentListSyntax): The new argument list. #### WithColonToken Updates the colon token of the constructor initializer. - **Parameters** - `colonToken` (SyntaxToken): The new colon token. ``` -------------------------------- ### Format Directory Contents Source: https://github.com/belav/csharpier/blob/main/README.md Format the contents of the current directory and its children using the `csharpier format` command. This is the primary way to apply formatting to your project files. ```bash csharpier format . ``` -------------------------------- ### AccessorDeclarationSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents a single accessor declaration (get, set, init, add, remove) in C# syntax. ```APIDOC ## AccessorDeclarationSyntax ### Description Represents an accessor declaration, which can include attributes, modifiers, a keyword, a body, an expression body, and a semicolon. ### Properties - `AttributeLists` (SyntaxList): Gets the attribute declaration list. - `Modifiers` (SyntaxTokenList): Gets the modifier list. - `Keyword` (SyntaxToken): Gets the keyword token (e.g., 'get', 'set'). - `Body` (BlockSyntax?): Gets the optional body block. - `ExpressionBody` (ArrowExpressionClauseSyntax?): Gets the optional expression body. - `SemicolonToken` (SyntaxToken): Gets the optional semicolon token. ### Methods - `Update(SyntaxList attributeLists, SyntaxTokenList modifiers, SyntaxToken keyword, BlockSyntax? body, ArrowExpressionClauseSyntax? expressionBody, SyntaxToken semicolonToken)`: Updates the accessor declaration with new components. ``` -------------------------------- ### TypeOfExpressionSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents a typeof expression in C# code, used to get the Type object for a given type. ```APIDOC ## TypeOfExpressionSyntax ### Description Represents a `typeof` expression in C# code, used to obtain the `System.Type` object for a specified type. This node is associated with the `SyntaxKind.TypeOfExpression`. ### Methods - `Update(SyntaxToken keyword, SyntaxToken openParenToken, TypeSyntax type, SyntaxToken closeParenToken)`: Updates the TypeOfExpressionSyntax node with new tokens and type. ### Properties - `Keyword` (SyntaxToken): The `typeof` keyword. - `OpenParenToken` (SyntaxToken): The opening parenthesis token. - `Type` (TypeSyntax): The type for which the `Type` object is requested. - `CloseParenToken` (SyntaxToken): The closing parenthesis token. ``` -------------------------------- ### Restore and Check Formatting with .NET CLI Source: https://github.com/belav/csharpier/blob/main/docs/ContinuousIntegration.md Use these commands in your CI/CD pipeline to restore .NET tools and check code formatting. This ensures all code committed adheres to the established formatting rules. ```bash dotnet tool restore dotnet csharpier check . ``` -------------------------------- ### XmlElementSyntax With Methods Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Provides methods to create updated XmlElementSyntax nodes by replacing the start tag, content, or end tag. ```csharp public XmlElementSyntax WithStartTag(XmlElementStartTagSyntax startTag) => Update(startTag, this.Content, this.EndTag); ``` ```csharp public XmlElementSyntax WithContent(SyntaxList content) => Update(this.StartTag, content, this.EndTag); ``` ```csharp public XmlElementSyntax WithEndTag(XmlElementEndTagSyntax endTag) => Update(this.StartTag, this.Content, endTag); ``` -------------------------------- ### XmlProcessingInstructionSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents an XML processing instruction. This node contains the start token, name, text tokens, and end token of the instruction. ```APIDOC ## XmlProcessingInstructionSyntax ### Description Represents an XML processing instruction, such as ``. ### Properties - `StartProcessingInstructionToken`: The token marking the beginning of the processing instruction. - `Name`: The name of the processing instruction (e.g., 'xml'). - `TextTokens`: The list of tokens representing the content of the processing instruction. - `EndProcessingInstructionToken`: The token marking the end of the processing instruction. ``` -------------------------------- ### Configure .NET Tool Manifest for CSharpier Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/ContinuousIntegration.md Set up the .config/dotnet-tools.json file to include CSharpier as a local tool. Replace '[SpecificVersion]' with your CSharpier version. ```json { "version": 1, "isRoot": true, "tools": { "csharpier": { "version": "[SpecificVersion]", "commands": [ "csharpier" ] } } } ``` -------------------------------- ### Accept Methods Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Methods for accepting a CSharpSyntaxVisitor. ```APIDOC ## Accept Methods ### Description Methods for accepting a CSharpSyntaxVisitor, allowing for pattern matching and traversal of the syntax tree. ### Methods - **Accept(CSharpSyntaxVisitor visitor)**: Accepts a visitor by calling the appropriate Visit method. - **Accept(CSharpSyntaxVisitor visitor)**: Accepts a visitor that returns a result. ``` -------------------------------- ### XmlCDataSectionSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents an XML CDATA section. Provides methods to update and modify the start token, text tokens, and end token. ```APIDOC ## XmlCDataSectionSyntax ### Description Represents an XML CDATA section, including its start, text, and end tokens. ### Methods - `Update(SyntaxToken startCDataToken, SyntaxTokenList textTokens, SyntaxToken endCDataToken)`: Updates the CDATA section with new tokens. - `WithStartCDataToken(SyntaxToken startCDataToken)`: Creates a new CDATA section with a modified start token. - `WithTextTokens(SyntaxTokenList textTokens)`: Creates a new CDATA section with modified text tokens. - `WithEndCDataToken(SyntaxToken endCDataToken)`: Creates a new CDATA section with a modified end token. - `AddTextTokens(params SyntaxToken[] items)`: Adds text tokens to the CDATA section. ``` -------------------------------- ### WithStartQuoteToken for XmlNameAttribute in C# Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Creates a new XmlNameAttribute node with an updated start quote token. This is a convenience method for the Update method. ```csharp internal override XmlAttributeSyntax WithStartQuoteTokenCore(SyntaxToken startQuoteToken) => WithStartQuoteToken(startQuoteToken); public new XmlNameAttributeSyntax WithStartQuoteToken(SyntaxToken startQuoteToken) => Update(this.Name, this.EqualsToken, startQuoteToken, this.Identifier, this.EndQuoteToken); ``` -------------------------------- ### Basic JSON Configuration Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Configuration.md Use this JSON configuration in a .csharpierrc file to set formatting preferences like line width, tab usage, and indentation size. ```json { "printWidth": 100, "useTabs": false, "indentSize": 4, "endOfLine": "auto" } ``` -------------------------------- ### Interpolated String Expression Syntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents an interpolated string in C#. It includes the start and end tokens, and a list of content parts. ```csharp private SyntaxNode? contents; internal InterpolatedStringExpressionSyntax(InternalSyntax.CSharpSyntaxNode green, SyntaxNode? parent, int position) : base(green, parent, position) { } /// The first part of an interpolated string, $" or $@" or $""" public SyntaxToken StringStartToken => new SyntaxToken(this, ((InternalSyntax.InterpolatedStringExpressionSyntax)this.Green).stringStartToken, Position, 0); /// List of parts of the interpolated string, each one is either a literal part or an interpolation. public SyntaxList Contents => new SyntaxList(GetRed(ref this.contents, 1)); /// The closing quote of the interpolated string. public SyntaxToken StringEndToken => new SyntaxToken(this, ((InternalSyntax.InterpolatedStringExpressionSyntax)this.Green).stringEndToken, GetChildPosition(2), GetChildIndex(2)); internal override SyntaxNode? GetNodeSlot(int index) => index == 1 ? GetRed(ref this.contents, 1)! : null; internal override SyntaxNode? GetCachedSlot(int index) => index == 1 ? this.contents : null; public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitInterpolatedStringExpression(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitInterpolatedStringExpression(this); ``` -------------------------------- ### Run Husky tasks Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Pre-commit.md Execute Husky tasks, including the CSharpier formatting task, using the `dotnet husky run` command. ```bash dotnet husky run ``` -------------------------------- ### XmlElementSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents an XML element in C# code. It contains methods for updating its start tag, content, and end tag, and for accepting visitors. ```APIDOC ## XmlElementSyntax ### Description Represents an XML element in C# code. It contains methods for updating its start tag, content, and end tag, and for accepting visitors. ### Properties - `StartTag`: The starting tag of the XML element. - `Content`: The content within the XML element, represented as a SyntaxList of XmlNodeSyntax. - `EndTag`: The ending tag of the XML element. ### Methods - `Accept(CSharpSyntaxVisitor visitor)`: Accepts a CSharpSyntaxVisitor. - `Accept(CSharpSyntaxVisitor visitor)`: Accepts a CSharpSyntaxVisitor that returns a result. - `Update(XmlElementStartTagSyntax startTag, SyntaxList content, XmlElementEndTagSyntax endTag)`: Creates a new XmlElementSyntax with updated components. - `WithStartTag(XmlElementStartTagSyntax startTag)`: Creates a new XmlElementSyntax with an updated start tag. - `WithContent(SyntaxList content)`: Creates a new XmlElementSyntax with updated content. - `WithEndTag(XmlElementEndTagSyntax endTag)`: Creates a new XmlElementSyntax with an updated end tag. - `AddStartTagAttributes(params XmlAttributeSyntax[] items)`: Adds attributes to the start tag. - `AddContent(params XmlNodeSyntax[] items)`: Adds content nodes to the XML element. ``` -------------------------------- ### Interface Declaration Syntax - Accept Methods Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Accept methods for CSharpSyntaxVisitor and CSharpSyntaxVisitor to allow visiting interface declaration nodes. ```csharp public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitInterfaceDeclaration(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitInterfaceDeclaration(this); ``` -------------------------------- ### InterpolationSyntax Definition Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents an interpolation within an interpolated string, containing an expression and optional alignment/format clauses. The OpenBraceToken indicates the start of the interpolation. ```csharp public sealed partial class InterpolationSyntax : InterpolatedStringContentSyntax { private ExpressionSyntax? expression; private InterpolationAlignmentClauseSyntax? alignmentClause; private InterpolationFormatClauseSyntax? formatClause; internal InterpolationSyntax(InternalSyntax.CSharpSyntaxNode green, SyntaxNode? parent, int position) : base(green, parent, position) { } /// This could be a single { or multiple in a row (in the case of an interpolation in a raw interpolated string). public SyntaxToken OpenBraceToken => new SyntaxToken(this, ((InternalSyntax.InterpolationSyntax)this.Green).openBraceToken, Position, 0); public ExpressionSyntax Expression => GetRed(ref this.expression, 1)!; ``` -------------------------------- ### Run CSharpier Playground with Watch Source: https://github.com/belav/csharpier/blob/main/Src/CONTRIBUTING.md Use this command to run the CSharpier playground in development mode. It will automatically recompile and restart the server when code changes are detected. ```bash dotnet watch run ``` -------------------------------- ### XmlElementSyntax Add Methods Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Adds new XML attribute syntax to the start tag or new XML node syntax to the content of an XmlElementSyntax node. ```csharp public XmlElementSyntax AddStartTagAttributes(params XmlAttributeSyntax[] items) => WithStartTag(this.StartTag.WithAttributes(this.StartTag.Attributes.AddRange(items))); ``` ```csharp public XmlElementSyntax AddContent(params XmlNodeSyntax[] items) => WithContent(this.Content.AddRange(items)); ``` -------------------------------- ### LineSpanDirectiveTriviaSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Represents a line span directive trivia in C# code, used for specifying code spans across lines. It includes start and end positions. ```APIDOC ## Class: LineSpanDirectiveTriviaSyntax ### Description Represents a directive trivia that specifies a span of code across lines, including start and end positions. ### Properties - **HashToken**: The hash token indicating a preprocessor directive. - **LineKeyword**: The 'line' keyword token. - **Start**: The starting `LineDirectivePositionSyntax` of the span. - **MinusToken**: The minus token separating the start and end positions. - **End**: The ending `LineDirectivePositionSyntax` of the span. - **CharacterOffset**: An optional token for character offset within the span. - **File**: The file name token associated with the directive. ``` -------------------------------- ### Visitor Pattern Accept Methods Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Implements the visitor pattern for traversing the syntax tree. Supports both generic and non-generic visitors. ```csharp public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitConversionOperatorDeclaration(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitConversionOperatorDeclaration(this); ``` -------------------------------- ### Method Declaration Visitor Acceptance Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Methods for accepting CSharpSyntaxVisitor and CSharpSyntaxVisitor for visiting method declarations. ```csharp public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitMethodDeclaration(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitMethodDeclaration(this); ``` -------------------------------- ### ParameterSyntax Accept Visitor Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Accepts a CSharpSyntaxVisitor to visit the ParameterSyntax node. ```csharp public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitParameter(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitParameter(this); ``` -------------------------------- ### ConstructorInitializerSyntax Methods Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Methods for manipulating ConstructorInitializerSyntax nodes. ```APIDOC ## ConstructorInitializerSyntax Methods ### Description Provides methods to update or add arguments to a constructor initializer. ### Methods - `WithThisOrBaseKeyword(SyntaxToken thisOrBaseKeyword)`: Updates the constructor initializer to use a specified 'this' or 'base' keyword. - `WithArgumentList(ArgumentListSyntax argumentList)`: Updates the constructor initializer with a new argument list. - `AddArgumentListArguments(params ArgumentSyntax[] items)`: Adds arguments to the existing argument list of the constructor initializer. ``` -------------------------------- ### Configure .pre-commit-config.yaml for CSharpier Source: https://github.com/belav/csharpier/blob/main/Src/Website/docs/Pre-commit.md Add this configuration to your .pre-commit-config.yaml file to enable CSharpier as a local pre-commit hook. It includes steps to restore .NET tools and run CSharpier on C# files. ```yaml repos: - repo: local hooks: - id: dotnet-tool-restore name: Install .NET tools entry: dotnet tool restore # for pre-commit < 4.4.0 use language: system language: unsupported always_run: true pass_filenames: false stages: - commit - push - post-checkout - post-rewrite description: Install the .NET tools listed at .config/dotnet-tools.json. - id: csharpier name: Run CSharpier on C# files entry: dotnet tool run CSharpier format language: system types: - c# description: CSharpier is an opinionated C# formatter inspired by Prettier. ``` -------------------------------- ### Run Extension in VS Code Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.VSCode/CONTRIBUTING.md Instructions for running the extension within VS Code for debugging or without debugging. ```bash Run - Start Debugging Run - Run Without Debugging ``` -------------------------------- ### Accept Visitor Pattern for RecordDeclarationSyntax Source: https://github.com/belav/csharpier/blob/main/Src/CSharpier.Benchmarks/CodeSamples/Syntax.txt Implements the Accept methods for the visitor pattern, allowing visitors to traverse RecordDeclarationSyntax nodes. ```csharp public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitRecordDeclaration(this); public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitRecordDeclaration(this); ```