### Install Pest Language Server Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Install the language server binary using the Cargo package manager. ```bash cargo install pest-language-server ``` -------------------------------- ### Running the Language Server Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Commands to start the language server and details on its JSON-RPC communication. ```bash # Run the language server (communicates via stdin/stdout) pest-language-server # The server speaks JSON-RPC over stdio # Example initialization request: # {"jsonrpc":"2.0","id":1,"method":"initialize","params":{...}} # Example response includes server capabilities: # - textDocumentSync: full document sync # - hoverProvider: true # - completionProvider: triggered by { ~ | ( # - codeActionProvider: extract and inline refactoring # - definitionProvider: go to definition # - referencesProvider: find all references # - documentFormattingProvider: format document # - renameProvider: rename symbol # - documentSymbolProvider: outline view ``` -------------------------------- ### Define Pest Grammar Rules Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Example of a JSON parser grammar definition using Pest syntax. ```pest //! A parser for JSON file. //! //! And this is an example for JSON parser. /// Entry point - matches a complete JSON document json = { SOI ~ (object | array) ~ EOI } /// Matches object, e.g.: `{ "foo": "bar" }` object = { "{" ~ pair ~ ("," ~ pair)* ~ "}" | "{" ~ "}" } pair = { string ~ ":" ~ value } /// Matches array, e.g.: `[1, 2, 3]` array = { "[" ~ value ~ ("," ~ value)* ~ "]" | "[" ~ "]" } /// Match any JSON value value = { string | number | object | array | bool | null } /// String literal with escape sequences string = @{ "\"" ~ inner ~ "\"" } inner = @{ (!("\"" | "\\") ~ ANY)* ~ (escape ~ inner)? } escape = @{ "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t" | unicode) } // Unicode escape, e.g.: `\u0000` unicode = @{ "u" ~ ASCII_HEX_DIGIT{4} } /// Integer and float, including negative numbers number = @{ "-"? ~ int ~ ("." ~ ASCII_DIGIT+ ~ exp? | exp)? } int = @{ "0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* } exp = @{ ("E" | "e") ~ ("+" | "-")? ~ ASCII_DIGIT+ } bool = { "true" | "false" } null = { "null" } // Implicit whitespace rule - inserted between expressions WHITESPACE = _{ " " | "\t" | "\r" | "\n" } ``` -------------------------------- ### Configure Pest IDE Tools settings Source: https://github.com/pest-parser/pest-ide-tools/blob/main/vscode/README.md Use this JSON configuration to set the server binary path, enable update checks, and define rules to ignore during unused rule diagnostics. ```jsonc { // Set a custom path to a Pest LS binary. "pestIdeTools.serverPath": "/path/to/binary", // Check for updates to the Pest LS binary via crates.io "pestIdeTools.checkForUpdates": true, // Ignore specific rule names for the unused rules diagnostics (useful for specifying root rules) "pestIdeTools.alwaysUsedRuleNames": [ "rule_one", "rule_two" ] } ``` -------------------------------- ### Configure Sublime Text LSP Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt LSP client configuration for Sublime Text to enable the Pest language server. ```json { "clients": { "pest": { "enabled": true, "command": ["/home/username/.cargo/bin/pest-language-server"], "selector": "source.pest" } } } ``` -------------------------------- ### Sublime Text LSP Client Configuration for Pest Source: https://github.com/pest-parser/pest-ide-tools/blob/main/DOCS.md Configure the Sublime Text LSP client for Pest. Ensure the command points to the language server binary. ```json "clients": { "pest": { "enabled": true, // This is usually something like /home/username/.cargo/bin/pest-language-server "command": ["/path/to/language/server/binary"], "selector": "source.pest", }, // ...other LSPs } ``` -------------------------------- ### Configure Pest IDE Tools Settings Source: https://github.com/pest-parser/pest-ide-tools/blob/main/DOCS.md Configure Pest IDE tools settings for update checks and unused rule names. Useful for specifying root rules. ```jsonc { // Check for updates to the Pest LS binary via crates.io "pestIdeTools.checkForUpdates": true, // Ignore specific rule names for the unused rules diagnostics (useful for specifying root rules) "pestIdeTools.alwaysUsedRuleNames": [ "rule_one", "rule_two" ] } ``` -------------------------------- ### Navigation: Go to Definition and References Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Allows jumping to rule definitions and finding all references within the grammar. ```pest // Ctrl+Click or F12 on "value" jumps to its definition array = { "[" ~ value ~ ("," ~ value)* ~ "]" } // ^^^^^ ^^^^^ // Click to go to definition // Right-click > "Find All References" on value shows: value = { string | number | bool } // Definition // References: // - array rule (2 occurrences) // - pair rule (1 occurrence) pair = { string ~ ":" ~ value } ``` -------------------------------- ### Configure VSCode Extension Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Settings for the Pest IDE Tools extension in VSCode, including binary paths and rule exclusion lists. ```jsonc { // Check for updates to the Pest LS binary via crates.io "pestIdeTools.checkForUpdates": true, // Set a custom path to a Pest LS binary (optional) "pestIdeTools.serverPath": "/path/to/pest-language-server", // Custom arguments to pass to the Pest LS binary "pestIdeTools.customArgs": [], // Rule names that should not be flagged as unused (useful for root rules) "pestIdeTools.alwaysUsedRuleNames": [ "main", "file" ] } ``` -------------------------------- ### VSCode Specific Pest IDE Tools Configurations Source: https://github.com/pest-parser/pest-ide-tools/blob/main/DOCS.md Configure VSCode specific settings for Pest IDE tools, including server path and custom arguments. ```jsonc { // Set a custom path to a Pest LS binary "pestIdeTools.serverPath": "/path/to/binary", // Custom arguments to pass to the Pest LS binary "pestIdeTools.customArgs": [] } ``` -------------------------------- ### Hover Information Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Displays documentation comments when hovering over rule names. ```pest /// Matches a JSON string with escape sequences. /// /// Examples: /// - `"hello"` /// - `"hello\nworld"` /// - `"unicode: \u0041"` string = @{ "\"" ~ inner ~ "\"" } // Hovering over "string" anywhere shows: // "Matches a JSON string with escape sequences. // Examples: // - "hello" // - "hello\nworld" // - "unicode: \u0041"" ``` -------------------------------- ### Autocompletion Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Provides suggestions for rule names and built-in expressions. ```pest // Type "str" and autocomplete suggests: // - string (your defined rule) // - STRING (if defined) // Type "ASCII" and autocomplete suggests built-ins: // - ASCII_DIGIT // - ASCII_NONZERO_DIGIT // - ASCII_HEX_DIGIT // - ASCII_ALPHA // - ASCII_ALPHA_LOWER // - ASCII_ALPHA_UPPER // - ASCII_ALPHANUMERIC rule = { // Trigger characters: { ~ | ( // After typing these, autocomplete activates } ``` -------------------------------- ### Document Formatting Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Standardizes the layout of the Pest grammar file. ```pest // Before: Inconsistent formatting json={SOI~(object|array)~EOI} object={"{"~pair~(,","~pair)*~"}"|"{"~"}"} pair={string~":"~value} // After: Using "Format Document" command json = { SOI ~ (object | array) ~ EOI } object = { "{" ~ pair ~ ("," ~ pair)* ~ "}" | "{" ~ "}" } pair = { string ~ ":" ~ value } ``` -------------------------------- ### Syntax Error Diagnostics Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Provides real-time feedback on syntax errors and valid rule modifiers. ```pest // Error: Expected expression after ~ broken_rule = { "start" ~ } // Error: Unclosed string literal bad_string = { "unclosed } // Error: Invalid rule modifier invalid = $@ { "conflict" } // Valid rule modifiers: atomic = @{ "no" ~ "whitespace" } // Atomic - no implicit whitespace compound = ${ "compound" ~ "atomic" } // Compound atomic silent = _{ "silent" } // Silent - not in parse tree non_atom = !{ "non" ~ "atomic" } // Non-atomic ``` -------------------------------- ### Extract Rule Code Action Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Demonstrates the refactoring process of extracting an expression into a new named rule. ```pest // Before: Select `ASCII_DIGIT+` in the number rule number = { "-"? ~ ASCII_DIGIT+ } // After: Using "Extract into new rule" code action number = { "-"? ~ number_0 } number_0 = { ASCII_DIGIT+ } ``` -------------------------------- ### Reference Built-in Pest Rules Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Common built-in rules and stack operations available in Pest grammars. ```pest // Input position rules rule_start = { SOI ~ content } // SOI - Start of input rule_end = { content ~ EOI } // EOI - End of input // Character matching any_char = { ANY } // Matches any single character whitespace = { ASCII_DIGIT } // Matches 0-9 letter = { ASCII_ALPHA } // Matches a-z, A-Z alphanum = { ASCII_ALPHANUMERIC } // Matches 0-9, a-z, A-Z hex = { ASCII_HEX_DIGIT } // Matches 0-9, a-f, A-F newline = { NEWLINE } // Matches \n, \r\n, \r // Unicode categories unicode_letter = { LETTER } // Any Unicode letter unicode_number = { NUMBER } // Any Unicode number emoji = { EMOJI } // Any emoji character // Stack operations for matching pairs balanced = { PUSH("(") ~ inner ~ POP } // PUSH/POP for balanced matching peek_top = { PEEK ~ content } // PEEK without consuming // Implicit rules (inserted automatically between tokens) WHITESPACE = _{ " " | "\t" | "\n" } // Auto-inserted whitespace COMMENT = _{ "//" ~ (!"\n" ~ ANY)* } // Auto-inserted comments ``` -------------------------------- ### Rename Symbol Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Updates a rule name and all its references throughout the grammar file. ```pest // Before: Rename "value" to "json_value" value = { string | number | bool } array = { "[" ~ value ~ ("," ~ value)* ~ "]" } object = { "{" ~ pair ~ "}" } pair = { string ~ ":" ~ value } // After: All references updated automatically json_value = { string | number | bool } array = { "[" ~ json_value ~ ("," ~ json_value)* ~ "]" } object = { "{" ~ pair ~ "}" } pair = { string ~ ":" ~ json_value } ``` -------------------------------- ### Inline Rule Refactoring Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Replaces a rule reference with its expression or removes the rule definition entirely. ```pest // Before: With digit rule defined digit = { ASCII_DIGIT } number = { digit+ } // After: Using "Inline digit" code action on digit reference digit = { ASCII_DIGIT } number = { ASCII_DIGIT+ } // After: Using "Inline all occurrences of digit" // Removes the rule definition and inlines everywhere number = { ASCII_DIGIT+ } ``` -------------------------------- ### Unused Rules Diagnostics Source: https://context7.com/pest-parser/pest-ide-tools/llms.txt Identifies rules that are defined but never referenced, with options to suppress warnings. ```pest // Warning: "Rule unused_rule is unused" unused_rule = { "unused" } // No warning: Rule starts with underscore (private convention) _helper = { "helper" } // No warning: Special implicit rules WHITESPACE = _{ " " } COMMENT = _{ "//" ~ ANY* } // Suppress warning via configuration: // "pestIdeTools.alwaysUsedRuleNames": ["entry_point"] entry_point = { SOI ~ content ~ EOI } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.