• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * This file mirrors `crates/rust-analyzer/src/lsp_ext.rs` declarations.
3 */
4
5import * as lc from "vscode-languageclient";
6
7// rust-analyzer overrides
8
9export const hover = new lc.RequestType<
10    HoverParams,
11    (lc.Hover & { actions: CommandLinkGroup[] }) | null,
12    void
13>(lc.HoverRequest.method);
14export type HoverParams = { position: lc.Position | lc.Range } & Omit<lc.HoverParams, "position">;
15
16export type CommandLink = {
17    /**
18     * A tooltip for the command, when represented in the UI.
19     */
20    tooltip?: string;
21} & lc.Command;
22export type CommandLinkGroup = {
23    title?: string;
24    commands: CommandLink[];
25};
26
27// rust-analyzer extensions
28
29export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>(
30    "rust-analyzer/analyzerStatus"
31);
32export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
33export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
34export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>(
35    "rust-analyzer/expandMacro"
36);
37export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
38export const openServerLogs = new lc.NotificationType0("rust-analyzer/openServerLogs");
39export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
40    "rust-analyzer/relatedTests"
41);
42export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
43export const rebuildProcMacros = new lc.RequestType0<null, void>("rust-analyzer/rebuildProcMacros");
44
45export const runFlycheck = new lc.NotificationType<{
46    textDocument: lc.TextDocumentIdentifier | null;
47}>("rust-analyzer/runFlycheck");
48export const shuffleCrateGraph = new lc.RequestType0<null, void>("rust-analyzer/shuffleCrateGraph");
49export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>(
50    "rust-analyzer/syntaxTree"
51);
52export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>(
53    "rust-analyzer/viewCrateGraph"
54);
55export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string, void>(
56    "rust-analyzer/viewFileText"
57);
58export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
59    "rust-analyzer/viewHir"
60);
61export const viewMir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
62    "rust-analyzer/viewMir"
63);
64export const interpretFunction = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
65    "rust-analyzer/interpretFunction"
66);
67export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
68    "rust-analyzer/viewItemTree"
69);
70
71export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
72
73export interface FetchDependencyListParams {}
74
75export interface FetchDependencyListResult {
76    crates: {
77        name: string | undefined;
78        version: string | undefined;
79        path: string;
80    }[];
81}
82
83export const fetchDependencyList = new lc.RequestType<
84    FetchDependencyListParams,
85    FetchDependencyListResult,
86    void
87>("rust-analyzer/fetchDependencyList");
88
89export interface FetchDependencyGraphParams {}
90
91export interface FetchDependencyGraphResult {
92    crates: {
93        name: string;
94        version: string;
95        path: string;
96    }[];
97}
98
99export const fetchDependencyGraph = new lc.RequestType<
100    FetchDependencyGraphParams,
101    FetchDependencyGraphResult,
102    void
103>("rust-analyzer/fetchDependencyGraph");
104
105export type ExpandMacroParams = {
106    textDocument: lc.TextDocumentIdentifier;
107    position: lc.Position;
108};
109export type ExpandedMacro = {
110    name: string;
111    expansion: string;
112};
113export type TestInfo = { runnable: Runnable };
114export type SyntaxTreeParams = {
115    textDocument: lc.TextDocumentIdentifier;
116    range: lc.Range | null;
117};
118export type ViewCrateGraphParams = { full: boolean };
119export type ViewItemTreeParams = { textDocument: lc.TextDocumentIdentifier };
120
121// experimental extensions
122
123export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>(
124    "experimental/joinLines"
125);
126export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>(
127    "experimental/matchingBrace"
128);
129export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>(
130    "experimental/moveItem"
131);
132export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
133    "experimental/onEnter"
134);
135export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
136    "experimental/openCargoToml"
137);
138export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
139    "experimental/externalDocs"
140);
141export const parentModule = new lc.RequestType<
142    lc.TextDocumentPositionParams,
143    lc.LocationLink[] | null,
144    void
145>("experimental/parentModule");
146export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
147    "experimental/runnables"
148);
149export const serverStatus = new lc.NotificationType<ServerStatusParams>(
150    "experimental/serverStatus"
151);
152export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr");
153
154export type JoinLinesParams = {
155    textDocument: lc.TextDocumentIdentifier;
156    ranges: lc.Range[];
157};
158export type MatchingBraceParams = {
159    textDocument: lc.TextDocumentIdentifier;
160    positions: lc.Position[];
161};
162export type MoveItemParams = {
163    textDocument: lc.TextDocumentIdentifier;
164    range: lc.Range;
165    direction: Direction;
166};
167export type Direction = "Up" | "Down";
168export type OpenCargoTomlParams = {
169    textDocument: lc.TextDocumentIdentifier;
170};
171export type Runnable = {
172    label: string;
173    location?: lc.LocationLink;
174    kind: "cargo";
175    args: {
176        workspaceRoot?: string;
177        cargoArgs: string[];
178        cargoExtraArgs: string[];
179        executableArgs: string[];
180        expectTest?: boolean;
181        overrideCargo?: string;
182    };
183};
184export type RunnablesParams = {
185    textDocument: lc.TextDocumentIdentifier;
186    position: lc.Position | null;
187};
188export type ServerStatusParams = {
189    health: "ok" | "warning" | "error";
190    quiescent: boolean;
191    message?: string;
192};
193export type SsrParams = {
194    query: string;
195    parseOnly: boolean;
196    textDocument: lc.TextDocumentIdentifier;
197    position: lc.Position;
198    selections: readonly lc.Range[];
199};
200