### Project Configuration for LSP-rust-analyzer Source: https://github.com/sublimelsp/lsp-rust-analyzer/blob/main/README.md Example of how to configure LSP-rust-analyzer within a Sublime Text project's settings. This allows for project-specific overrides and configurations for the rust-analyzer language server. ```json { "settings": { "LSP": { "rust-analyzer": { "settings": { //Setting-here } } } } } ``` -------------------------------- ### Configure rust-analyzer Inlay Hints Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt This section details the configuration options for displaying inlay hints, such as type hints, parameter hints, and chaining hints. It allows enabling and customizing various hint types, setting maximum lengths, controlling colon rendering, and configuring closure return type hints. ```json { "settings": { "rust-analyzer.inlayHints.typeHints.enable": true, "rust-analyzer.inlayHints.typeHints.hideClosureInitialization": false, "rust-analyzer.inlayHints.typeHints.hideNamedConstructor": false, "rust-analyzer.inlayHints.parameterHints.enable": true, "rust-analyzer.inlayHints.chainingHints.enable": true, "rust-analyzer.inlayHints.closingBraceHints.enable": true, "rust-analyzer.inlayHints.closingBraceHints.minLines": 25, "rust-analyzer.inlayHints.lifetimeElisionHints.enable": "skip_trivial", "rust-analyzer.inlayHints.maxLength": 25, "rust-analyzer.inlayHints.renderColons": true, "rust-analyzer.inlayHints.closureReturnTypeHints.enable": "with_block" } } ``` -------------------------------- ### Configure Rust Hover and Documentation Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Configure hover information display for rust-analyzer, including memory layout details and documentation. Options control the visibility of various hover actions, documentation keywords, memory layout specifics, display limits, and links. ```json { "settings": { // Hover actions "rust-analyzer.hover.actions.enable": true, "rust-analyzer.hover.actions.run.enable": true, "rust-analyzer.hover.actions.debug.enable": true, "rust-analyzer.hover.actions.implementations.enable": true, "rust-analyzer.hover.actions.gotoTypeDef.enable": true, "rust-analyzer.hover.actions.references.enable": true, // Documentation "rust-analyzer.hover.documentation.enable": true, "rust-analyzer.hover.documentation.keywords.enable": true, // Memory layout information "rust-analyzer.hover.memoryLayout.enable": true, "rust-analyzer.hover.memoryLayout.size": "both", "rust-analyzer.hover.memoryLayout.alignment": "hexadecimal", "rust-analyzer.hover.memoryLayout.offset": "hexadecimal", "rust-analyzer.hover.memoryLayout.niches": true, // Display limits "rust-analyzer.hover.show.fields": 10, "rust-analyzer.hover.show.enumVariants": 10, "rust-analyzer.hover.show.traitAssocItems": 5, "rust-analyzer.hover.maxSubstitutionLength": 30, // Links in hover "rust-analyzer.hover.links.enable": true } } ``` -------------------------------- ### Configure Rustfmt Formatting Settings (JSON) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt This JSON configuration snippet demonstrates how to set up rustfmt for code formatting within Sublime Text. It includes options for specifying extra arguments, overriding the default rustfmt command, and enabling range formatting, which requires a nightly version of rustfmt. ```json { "settings": { "rust-analyzer.rustfmt.extraArgs": [ "--config", "max_width=120", "--config", "tab_spaces=4" ], "rust-analyzer.rustfmt.overrideCommand": [ "rustfmt", "--edition", "2021" ], "rust-analyzer.rustfmt.rangeFormatting.enable": true } } ``` -------------------------------- ### Open Documentation for Symbol Under Cursor in Sublime Text Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Open the official documentation URL for the Rust symbol currently under the cursor in your default web browser. This command utilizes LSP requests to fetch external documentation links. ```python # Command Palette: "LSP-rust-analyzer: Open Docs Under Cursor" # Position cursor on any Rust symbol and execute the command: fn main() { let v: Vec = vec![1, 2, 3]; // Cursor on "Vec" opens https://doc.rust-lang.org/std/vec/struct.Vec.html v.iter().map(|x| x * 2); // Cursor on "map" opens Iterator::map docs } # LSP request sent: # Request("experimental/externalDocs", { ``` -------------------------------- ### Configure Rust Imports Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Configure automatic import organization and formatting for rust-analyzer. Options include import granularity, grouping strategies, path prefix styles, and preferences for std vs. no_std crates. ```json { "settings": { // Import grouping strategy "rust-analyzer.imports.granularity.group": "crate", "rust-analyzer.imports.granularity.enforce": true, // Import grouping (separates std, external, internal) "rust-analyzer.imports.group.enable": true, // Import path prefix style "rust-analyzer.imports.prefix": "crate", // Merge glob imports "rust-analyzer.imports.merge.glob": true, // Prefer no_std crates "rust-analyzer.imports.preferNoStd": false, // Prefer prelude imports "rust-analyzer.imports.preferPrelude": true, // Prefix external crates with :: "rust-analyzer.imports.prefixExternPrelude": false } } ``` -------------------------------- ### Configure Rust Runnables and Test Execution Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Define how tests, benchmarks, and binaries are executed, including overriding the cargo command, setting extra arguments, and configuring environment variables. Platform-specific environment variables can also be specified. ```json { "settings": { // Override cargo command "rust-analyzer.runnables.command": "/custom/path/to/cargo", // Extra arguments for all runnables "rust-analyzer.runnables.extraArgs": ["--release"], // Test-specific arguments passed after -- "rust-analyzer.runnables.extraTestBinaryArgs": ["--nocapture", "--test-threads=1"], // Custom test command "rust-analyzer.runnables.test.command": "nextest", "rust-analyzer.runnables.test.overrideCommand": [ "cargo", "nextest", "run", "--package", "${package}", "${test_name}" ], // Bench command "rust-analyzer.runnables.bench.command": "bench", // Environment variables for runnables "rust-analyzer.runnables.extraEnv": { "RUST_LOG": "debug", "DATABASE_URL": "postgres://localhost/test" }, // Platform-specific environment "rust-analyzer.runnables.extraEnv": [ { "platform": "linux", "env": {"LD_LIBRARY_PATH": "/custom/lib"} }, { "platform": "win32", "mask": "test_*", "env": {"PATH": "C:\\custom\\bin;${env:PATH}"} } ] } } ``` -------------------------------- ### Configure Linked Projects and Workspace Discovery Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Manage multiple Rust projects, define workspace symbol search behavior, and configure custom workspace discovery for non-Cargo build systems. This configuration is applied within the 'settings' block of a JSON configuration file. ```json { "settings": { // Manually specify project roots "rust-analyzer.linkedProjects": [ "crates/core/Cargo.toml", "crates/cli/Cargo.toml", "path/to/rust-project.json" ], // Workspace symbol search "rust-analyzer.workspace.symbol.search.kind": "all_symbols", "rust-analyzer.workspace.symbol.search.limit": 256, "rust-analyzer.workspace.symbol.search.scope": "workspace_and_dependencies", // Files to exclude from analysis "rust-analyzer.files.exclude": [ "target", "generated" ], // Custom workspace discovery (for non-Cargo build systems like Buck2) "rust-analyzer.workspace.discoverConfig": { "command": ["rust-project", "develop-json", "{arg}"], "progressLabel": "rust-project", "filesToWatch": ["BUCK"] } } } ``` -------------------------------- ### View Item Tree (Text) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Displays the item tree, illustrating the module structure and definitions within a crate. This is helpful for visualizing the organization of Rust code. ```text # Command Palette: "LSP-rust-analyzer: View Item Tree" # Shows module-level items and their structure # Useful for understanding crate organization # Output example: pub struct MyStruct pub enum MyEnum impl MyStruct pub fn my_function mod inner_module pub fn inner_function ``` -------------------------------- ### Configure rust-analyzer Check on Save Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt This section explains how to configure diagnostics and the check command that runs when a file is saved. It covers enabling check on save, choosing between cargo check and clippy, specifying extra arguments, checking all targets, ignoring specific diagnostics, enabling features, and setting environment variables for the check command. ```json { "settings": { "rust-analyzer.checkOnSave": true, "rust-analyzer.check.command": "clippy", "rust-analyzer.check.extraArgs": [ "--", "-W", "clippy::pedantic", "-A", "clippy::must_use_candidate" ], "rust-analyzer.check.allTargets": true, "rust-analyzer.check.ignore": ["dead_code", "unused_variables"], "rust-analyzer.check.features": ["feature1", "feature2"], "rust-analyzer.check.extraEnv": { "RUST_BACKTRACE": "1" } } } ``` -------------------------------- ### Configure Rust Code Completion Settings Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Customize code completion behavior, including enabling auto-imports, defining custom snippets, and configuring postfix completions. This configuration is applied within the 'settings' block of a JSON configuration file. ```json { "settings": { // Auto-import completions "rust-analyzer.completion.autoimport.enable": true, // Exclude specific items from auto-import "rust-analyzer.completion.autoimport.exclude": [ {"path": "core::borrow::Borrow", "type": "methods"}, "some::unwanted::Type" ], // Callable snippet style "rust-analyzer.completion.callable.snippets": "fill_arguments", // Postfix completions (e.g., expr.if, expr.match) "rust-analyzer.completion.postfix.enable": true, // Custom snippets "rust-analyzer.completion.snippets.custom": { "Ok": { "postfix": "ok", "body": "Ok(${receiver})", "description": "Wrap in Result::Ok", "scope": "expr" }, "Arc::new": { "postfix": "arc", "body": "Arc::new(${receiver})", "requires": "std::sync::Arc", "description": "Wrap in Arc", "scope": "expr" }, "thread_local": { "prefix": ["tl", "threadlocal"], "body": "thread_local! {\n\tstatic ${1:NAME}: ${2:Type} = ${0};\n}", "description": "Create thread_local", "scope": "item" } }, // Term search for smart completions "rust-analyzer.completion.termSearch.enable": true, "rust-analyzer.completion.termSearch.fuel": 1000 } } ``` -------------------------------- ### Open Cargo.toml (JSON) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Navigates to the Cargo.toml file corresponding to the crate of the current file. This command simplifies managing project configurations. ```json # Command Palette: "LSP-rust-analyzer: Open Cargo.toml" # When editing src/lib.rs or any source file, this command # opens the corresponding Cargo.toml at the correct location # LSP request: # Request("experimental/openCargoToml", { # "textDocument": {"uri": "file:///project/src/lib.rs"}, # "position": {"line": 0, "character": 0} # }) # Opens: /project/Cargo.toml ``` -------------------------------- ### Configure rust-analyzer Cargo Build Scripts Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt This section details how to configure rust-analyzer's handling of build.rs scripts and procedural macros. It allows enabling script execution, setting rebuild behavior, customizing build commands, and managing procedural macro settings, including ignoring specific macros. ```json { "settings": { "rust-analyzer.cargo.buildScripts.enable": true, "rust-analyzer.cargo.buildScripts.rebuildOnSave": true, "rust-analyzer.cargo.buildScripts.overrideCommand": [ "cargo", "check", "--message-format=json", "--all-targets" ], "rust-analyzer.cargo.buildScripts.invocationStrategy": "per_workspace", "rust-analyzer.procMacro.enable": true, "rust-analyzer.procMacro.attributes.enable": true, "rust-analyzer.procMacro.ignored": { "problematic-crate": ["problematic_macro"] } } } ``` -------------------------------- ### Memory Usage (Text) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Displays per-query memory usage statistics for debugging rust-analyzer performance. Note that this action clears the internal database. ```text # Command Palette: "LSP-rust-analyzer: Memory Usage (Clears Database)" ``` -------------------------------- ### Global Settings Configuration for rust-analyzer in Sublime Text Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Configure rust-analyzer settings globally through the LSP-rust-analyzer.sublime-settings file. This JSON object allows customization of various aspects like cargo configuration, diagnostics, completion, and inlay hints. ```json // Access via Command Palette: "Preferences: LSP-rust-analyzer Settings" { "settings": { // Cargo configuration "rust-analyzer.cargo.autoreload": true, "rust-analyzer.cargo.buildScripts.enable": true, "rust-analyzer.cargo.features": ["my-feature"], "rust-analyzer.cargo.target": "wasm32-unknown-unknown", // Diagnostics "rust-analyzer.checkOnSave": true, "rust-analyzer.check.command": "clippy", "rust-analyzer.diagnostics.enable": true, // Completion "rust-analyzer.completion.autoimport.enable": true, "rust-analyzer.completion.callable.snippets": "fill_arguments", "rust-analyzer.completion.postfix.enable": true, // Inlay hints "rust-analyzer.inlayHints.typeHints.enable": true, "rust-analyzer.inlayHints.parameterHints.enable": true, "rust-analyzer.inlayHints.chainingHints.enable": true, // Terminus integration "rust-analyzer.terminusAutoClose": false, "rust-analyzer.terminusUsePanel": true } } ``` -------------------------------- ### Join Lines (Python) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Joins selected lines with Rust-aware logic, intelligently handling trailing commas, else-if chains, and assignments. Configuration options allow customization of its behavior. ```python # Command Palette: "LSP-rust-analyzer: Join Lines" # Keyboard shortcut: Ctrl+Shift+J (Cmd+Shift+J on macOS) # Example 1: Join struct fields struct Point { x: i32, y: i32, # Select these lines and join } # Result: struct Point { x: i32, y: i32 } # Example 2: Join else-if if condition { // ... } else { # Join lines merges else onto previous line // ... } # Result: } else { # Settings to customize behavior: { "settings": { "rust-analyzer.joinLines.joinAssignments": true, // Merge let x; x = 1; into let x = 1; "rust-analyzer.joinLines.joinElseIf": true, // Join } and else/else if "rust-analyzer.joinLines.removeTrailingComma": true, // Remove trailing commas when joining "rust-analyzer.joinLines.unwrapTrivialBlock": true // Unwrap single-statement blocks } } ``` -------------------------------- ### Project-Specific rust-analyzer Configuration in Sublime Text Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Configure rust-analyzer settings on a per-project basis by editing the .sublime-project file. This allows for tailored settings for different projects, overriding global configurations. ```json // In your .sublime-project file { "folders": [ { "path": "." } ], "settings": { "LSP": { "rust-analyzer": { "settings": { "rust-analyzer.cargo.features": ["feature1", "feature2"], "rust-analyzer.cargo.target": "x86_64-unknown-linux-gnu", "rust-analyzer.check.command": "clippy", "rust-analyzer.check.extraArgs": ["--", "-W", "clippy::pedantic"], "rust-analyzer.procMacro.enable": true, "rust-analyzer.linkedProjects": [ "crates/my-crate/Cargo.toml" ] } } } } } ``` -------------------------------- ### Configure Rust Semantic Highlighting Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Configure semantic highlighting for Rust-specific syntax elements in rust-analyzer. This allows customization of highlighting for strings, comments, operators, punctuation, and doc comments. ```json { "settings": { // Enable semantic tokens "rust-analyzer.semanticHighlighting.strings.enable": true, "rust-analyzer.semanticHighlighting.comments.enable": true, "rust-analyzer.semanticHighlighting.operator.enable": true, "rust-analyzer.semanticHighlighting.punctuation.enable": false, // Doc comment injection (highlights code in doc comments) "rust-analyzer.semanticHighlighting.doc.comment.inject.enable": true, // Operator specialization "rust-analyzer.semanticHighlighting.operator.specialization.enable": false, // Non-standard tokens "rust-analyzer.semanticHighlighting.nonStandardTokens": true, // Macro bang highlighting "rust-analyzer.semanticHighlighting.punctuation.separate.macro.bang": true } } ``` -------------------------------- ### Configure Rust Diagnostics Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Configure diagnostic display, filtering, and severity levels for rust-analyzer. This includes enabling/disabling diagnostics, experimental features, and specifying how warnings should be presented (e.g., as hints or info). ```json { "settings": { // Enable/disable diagnostics "rust-analyzer.diagnostics.enable": true, // Experimental diagnostics (may have false positives) "rust-analyzer.diagnostics.experimental.enable": false, // Disable specific diagnostics "rust-analyzer.diagnostics.disabled": [ "unresolved-proc-macro", "inactive-code" ], // Show warnings as hints (less prominent) "rust-analyzer.diagnostics.warningsAsHint": [ "unused_variables", "dead_code" ], // Show warnings as info "rust-analyzer.diagnostics.warningsAsInfo": [ "unused_imports" ], // Path prefix remapping (for --remap-path-prefix builds) "rust-analyzer.diagnostics.remapPrefix": { "/build/source": "/actual/source/path" }, // Style lints "rust-analyzer.diagnostics.styleLints.enable": true } } ``` -------------------------------- ### Run Cargo Commands with Terminus Integration in Sublime Text Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Execute cargo commands (run, test, check, bench) using the Terminus terminal integration within Sublime Text. This feature automatically detects the working directory and provides a seamless way to interact with cargo. ```python # Command Palette: "LSP-rust-analyzer: Run..." # Opens a quick panel to select from available runnables # Example: Position cursor on a test function and run the command # The plugin will detect available runnables and show options like: # - "cargo test module::test_function" # - "cargo run --bin my_binary" # - "cargo check" # Terminus panel configuration in settings: { "settings": { "rust-analyzer.terminusUsePanel": true, // Use bottom panel instead of new tab "rust-analyzer.terminusAutoClose": false // Keep panel open after command completes } } # The command executes via Terminus with proper working directory: # terminus_open({ # "title": "cargo test my_test", # "cmd": ["cargo", "test", "my_test", "--", "--nocapture"], # "cwd": "/path/to/workspace", # "auto_close": false, # "panel_name": "cargo test my_test" // if terminusUsePanel is true # }) ``` -------------------------------- ### View Syntax Tree (Text) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Displays the internal syntax tree representation of the current file or selection. This is a debugging tool for understanding the parsed structure of Rust code. ```text # Command Palette: "LSP-rust-analyzer: View Syntax Tree" # For code: fn main() { println!("Hello"); } # Output in new "Syntax Tree" tab: SOURCE_FILE@0..42 FN@0..42 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..7 IDENT@3..7 "main" PARAM_LIST@7..9 L_PAREN@7..8 "(" R_PAREN@8..9 ")" WHITESPACE@9..10 " " BLOCK_EXPR@10..42 STMT_LIST@10..42 L_CURLY@10..11 "{" ... ``` -------------------------------- ### Expand Macro Recursively (Python) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Displays the full recursive expansion of a macro at the cursor position in a new transient view. This command is useful for understanding how macros transform code. ```python # Command Palette: "LSP-rust-analyzer: Expand Macro Recursively" # Example: Position cursor on the derive macro #[derive(Debug, Clone)] // <-- cursor here struct MyStruct { field: i32, } # Output in new "Macro Expansion" tab: // Recursive expansion of derive! macro // ===================================== impl ::core::fmt::Debug for MyStruct { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { ::core::fmt::Formatter::debug_struct_field1_finish(f, "MyStruct", "field", &&self.field) } } impl ::core::clone::Clone for MyStruct { #[inline] fn clone(&self) -> MyStruct { MyStruct { field: ::core::clone::Clone::clone(&self.field), } } } ``` -------------------------------- ### Reload Project (Text) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Forces rust-analyzer to reload project metadata by re-running 'cargo metadata'. This is useful after making changes to build configurations or dependencies. ```text # Command Palette: "LSP-rust-analyzer: Reload Project" # Useful after: # - Modifying Cargo.toml dependencies # - Changing workspace configuration # - Switching git branches with different dependencies # LSP request sent: # Request("rust-analyzer/reloadWorkspace") ``` -------------------------------- ### Move Item Up/Down (JSON) Source: https://context7.com/sublimelsp/lsp-rust-analyzer/llms.txt Moves functions, structs, impl blocks, or other code items up or down within the file while maintaining correct syntax. This command can be invoked via the Command Palette or with specific arguments. ```json # Command Palette: "LSP-rust-analyzer: Move Item Down" or "LSP-rust-analyzer: Move Item Up" # Example: Moving a function down fn first() {} // <-- cursor here, execute "Move Item Down" fn second() {} # Result: fn second() {} fn first() {} // Function moved below # Works with complex items: impl MyTrait for MyStruct { // Move entire impl block fn method1(&self) {} fn method2(&self) {} } # Command arguments: {"command": "rust_analyzer_move_item", "args": {"direction": "Down"}} {"command": "rust_analyzer_move_item", "args": {"direction": "Up"}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.