1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(
name = "rust-analyzer-cli",
author,
version,
about = "Compiler-accurate Rust codebase navigation powered by rust-analyzer LSP"
)]
pub struct Cli {
/// Port for the background daemon HTTP server
#[arg(short, long, env = "RUST_ANALYZER_CLI_PORT", default_value_t = 60094)]
pub port: u16,
/// Output results in JSON format
#[arg(short, long, global = true)]
pub json: bool,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Start the background LSP daemon and HTTP server
Daemon {
/// Workspace root directory
#[arg(short, long, default_value = ".")]
workspace: PathBuf,
},
/// Query daemon and rust-analyzer status
Status,
/// Refresh / restart the rust-analyzer session
Refresh,
/// Search workspace symbols
Symbol {
/// Symbol name to search for
name: String,
/// Optional symbol filter: any, struct, enum, fn, trait, type, const, var
#[arg(default_value = "any")]
kind: String,
/// Match exact symbol name
#[arg(long)]
exact: bool,
},
/// Extract file document symbols outline
Outline {
/// Target file path
#[arg(short, long)]
file: Option<PathBuf>,
/// Comma-separated list of target file paths
#[arg(long)]
file_list: Option<String>,
/// Write outline output to a file
#[arg(short, long)]
output: Option<PathBuf>,
},
/// Go to definition at file line and column
Definition {
/// File path
#[arg(short, long)]
file: PathBuf,
/// Line number (1-based)
#[arg(short, long)]
line: u32,
/// Column number (1-based)
#[arg(short, long)]
col: u32,
},
/// Find references or call hierarchy at file line and column
Cursor {
/// File path
#[arg(short, long)]
file: PathBuf,
/// Line number (1-based)
#[arg(short, long)]
line: u32,
/// Column number (1-based)
#[arg(short, long)]
col: u32,
/// Mode: incoming, outgoing, or references
#[arg(short, long, default_value = "incoming")]
mode: String,
/// Traversal depth (default: 1)
#[arg(short, long, default_value_t = 1)]
depth: u32,
},
/// Query type hierarchy (supertypes / subtypes)
TypeHierarchy {
/// File path
#[arg(short, long)]
file: PathBuf,
/// Line number (1-based)
#[arg(short, long)]
line: u32,
/// Column number (1-based)
#[arg(short, long)]
col: u32,
/// Mode: supertypes or subtypes
#[arg(short, long, default_value = "supertypes")]
mode: String,
/// Traversal depth (default: 1)
#[arg(short, long, default_value_t = 1)]
depth: u32,
},
/// Run cargo check compilation verification
Check {
/// Optional cargo build target
#[arg(short, long)]
target: Option<String>,
},
}