mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Cleanup lsp extensions on the client side
This commit is contained in:
parent
8686d0b0ac
commit
a30bdd9795
9 changed files with 93 additions and 137 deletions
|
@ -50,7 +50,7 @@ impl Request for ExpandMacro {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExpandMacroParams {
|
||||
pub text_document: TextDocumentIdentifier,
|
||||
pub position: Option<Position>,
|
||||
pub position: Position,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
|
|
|
@ -72,16 +72,11 @@ pub fn handle_expand_macro(
|
|||
let _p = profile("handle_expand_macro");
|
||||
let file_id = from_proto::file_id(&world, ¶ms.text_document.uri)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
let offset = params.position.map(|p| from_proto::offset(&line_index, p));
|
||||
let offset = from_proto::offset(&line_index, params.position);
|
||||
|
||||
match offset {
|
||||
None => Ok(None),
|
||||
Some(offset) => {
|
||||
let res = world.analysis().expand_macro(FilePosition { file_id, offset })?;
|
||||
Ok(res.map(|it| lsp_ext::ExpandedMacro { name: it.name, expansion: it.expansion }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_selection_range(
|
||||
world: WorldSnapshot,
|
||||
|
|
|
@ -318,7 +318,7 @@ Primarily for debugging, but very useful for all people working on rust-analyzer
|
|||
```typescript
|
||||
interface ExpandMacroParams {
|
||||
textDocument: TextDocumentIdentifier,
|
||||
position?: Position,
|
||||
position: Position,
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import * as ra from './rust-analyzer-api';
|
||||
import * as ra from './lsp_ext';
|
||||
|
||||
import { Ctx, Cmd } from './ctx';
|
||||
import { applySnippetWorkspaceEdit, applySnippetTextEdits } from './snippets';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as os from "os";
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as ra from './rust-analyzer-api';
|
||||
import * as ra from './lsp_ext';
|
||||
|
||||
import { Cargo } from './cargo';
|
||||
import { Ctx } from "./ctx";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as lc from "vscode-languageclient";
|
||||
import * as vscode from 'vscode';
|
||||
import * as ra from './rust-analyzer-api';
|
||||
import * as ra from './lsp_ext';
|
||||
|
||||
import { Ctx, Disposable } from './ctx';
|
||||
import { sendRequestWithRetry, isRustDocument, RustDocument, RustEditor, sleep } from './util';
|
||||
|
|
84
editors/code/src/lsp_ext.ts
Normal file
84
editors/code/src/lsp_ext.ts
Normal file
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* This file mirrors `crates/rust-analyzer/src/req.rs` declarations.
|
||||
*/
|
||||
|
||||
import * as lc from "vscode-languageclient";
|
||||
|
||||
export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus");
|
||||
|
||||
export const collectGarbage = new lc.RequestType<null, null, void>("rust-analyzer/collectGarbage");
|
||||
|
||||
export interface SyntaxTreeParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
range: lc.Range | null;
|
||||
}
|
||||
export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>("rust-analyzer/syntaxTree");
|
||||
|
||||
|
||||
export interface ExpandMacroParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
position: lc.Position;
|
||||
}
|
||||
export interface ExpandedMacro {
|
||||
name: string;
|
||||
expansion: string;
|
||||
}
|
||||
export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>("rust-analyzer/expandMacro");
|
||||
|
||||
export interface MatchingBraceParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
positions: lc.Position[];
|
||||
}
|
||||
export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>("experimental/matchingBrace");
|
||||
|
||||
export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc.Location[], void>("rust-analyzer/parentModule");
|
||||
|
||||
export interface JoinLinesParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
ranges: lc.Range[];
|
||||
}
|
||||
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>("experimental/joinLines");
|
||||
|
||||
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>("experimental/onEnter");
|
||||
|
||||
export interface RunnablesParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
position: lc.Position | null;
|
||||
}
|
||||
export interface Runnable {
|
||||
range: lc.Range;
|
||||
label: string;
|
||||
bin: string;
|
||||
args: string[];
|
||||
extraArgs: string[];
|
||||
env: { [key: string]: string };
|
||||
cwd: string | null;
|
||||
}
|
||||
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("rust-analyzer/runnables");
|
||||
|
||||
export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;
|
||||
|
||||
export namespace InlayHint {
|
||||
export const enum Kind {
|
||||
TypeHint = "TypeHint",
|
||||
ParamHint = "ParameterHint",
|
||||
ChainingHint = "ChainingHint",
|
||||
}
|
||||
interface Common {
|
||||
range: lc.Range;
|
||||
label: string;
|
||||
}
|
||||
export type TypeHint = Common & { kind: Kind.TypeHint };
|
||||
export type ParamHint = Common & { kind: Kind.ParamHint };
|
||||
export type ChainingHint = Common & { kind: Kind.ChainingHint };
|
||||
}
|
||||
export interface InlayHintsParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
}
|
||||
export const inlayHints = new lc.RequestType<InlayHintsParams, InlayHint[], void>("rust-analyzer/inlayHints");
|
||||
|
||||
export interface SsrParams {
|
||||
query: string;
|
||||
parseOnly: boolean;
|
||||
}
|
||||
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>('experimental/ssr');
|
|
@ -1,6 +1,6 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import * as ra from './rust-analyzer-api';
|
||||
import * as ra from './lsp_ext';
|
||||
|
||||
import { Ctx, Cmd } from './ctx';
|
||||
import { startDebugSession, getDebugConfiguration } from './debug';
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
/**
|
||||
* This file mirrors `crates/rust-analyzer/src/req.rs` declarations.
|
||||
*/
|
||||
|
||||
import * as lc from "vscode-languageclient";
|
||||
|
||||
type Option<T> = null | T;
|
||||
type Vec<T> = T[];
|
||||
type FxHashMap<K extends PropertyKey, V> = Record<K, V>;
|
||||
|
||||
function request<TParams, TResult>(method: string) {
|
||||
return new lc.RequestType<TParams, TResult, unknown>(`rust-analyzer/${method}`);
|
||||
}
|
||||
function notification<TParam>(method: string) {
|
||||
return new lc.NotificationType<TParam>(method);
|
||||
}
|
||||
|
||||
|
||||
export const analyzerStatus = request<null, string>("analyzerStatus");
|
||||
|
||||
|
||||
export const collectGarbage = request<null, null>("collectGarbage");
|
||||
|
||||
|
||||
export interface SyntaxTreeParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
range: Option<lc.Range>;
|
||||
}
|
||||
export const syntaxTree = request<SyntaxTreeParams, string>("syntaxTree");
|
||||
|
||||
|
||||
export interface ExpandMacroParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
position: Option<lc.Position>;
|
||||
}
|
||||
export interface ExpandedMacro {
|
||||
name: string;
|
||||
expansion: string;
|
||||
}
|
||||
export const expandMacro = request<ExpandMacroParams, Option<ExpandedMacro>>("expandMacro");
|
||||
|
||||
|
||||
export interface MatchingBraceParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
positions: lc.Position[];
|
||||
}
|
||||
export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], unknown>('experimental/matchingBrace');
|
||||
|
||||
export interface PublishDecorationsParams {
|
||||
uri: string;
|
||||
decorations: Vec<Decoration>;
|
||||
}
|
||||
export interface Decoration {
|
||||
range: lc.Range;
|
||||
tag: string;
|
||||
bindingHash: Option<string>;
|
||||
}
|
||||
export const decorationsRequest = request<lc.TextDocumentIdentifier, Vec<Decoration>>("decorationsRequest");
|
||||
|
||||
|
||||
export const parentModule = request<lc.TextDocumentPositionParams, Vec<lc.Location>>("parentModule");
|
||||
|
||||
|
||||
export interface JoinLinesParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
ranges: lc.Range[];
|
||||
}
|
||||
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], unknown>('experimental/joinLines');
|
||||
|
||||
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], unknown>('experimental/onEnter');
|
||||
|
||||
export interface RunnablesParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
position: Option<lc.Position>;
|
||||
}
|
||||
export interface Runnable {
|
||||
range: lc.Range;
|
||||
label: string;
|
||||
bin: string;
|
||||
args: Vec<string>;
|
||||
extraArgs: Vec<string>;
|
||||
env: FxHashMap<string, string>;
|
||||
cwd: Option<string>;
|
||||
}
|
||||
export const runnables = request<RunnablesParams, Vec<Runnable>>("runnables");
|
||||
|
||||
export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;
|
||||
|
||||
export namespace InlayHint {
|
||||
export const enum Kind {
|
||||
TypeHint = "TypeHint",
|
||||
ParamHint = "ParameterHint",
|
||||
ChainingHint = "ChainingHint",
|
||||
}
|
||||
interface Common {
|
||||
range: lc.Range;
|
||||
label: string;
|
||||
}
|
||||
export type TypeHint = Common & { kind: Kind.TypeHint };
|
||||
export type ParamHint = Common & { kind: Kind.ParamHint };
|
||||
export type ChainingHint = Common & { kind: Kind.ChainingHint };
|
||||
}
|
||||
export interface InlayHintsParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
}
|
||||
export const inlayHints = request<InlayHintsParams, Vec<InlayHint>>("inlayHints");
|
||||
|
||||
|
||||
export interface SsrParams {
|
||||
query: string;
|
||||
parseOnly: boolean;
|
||||
}
|
||||
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, unknown>('experimental/ssr');
|
||||
|
||||
|
||||
export const publishDecorations = notification<PublishDecorationsParams>("publishDecorations");
|
||||
|
||||
|
||||
export interface SourceChange {
|
||||
label: string;
|
||||
workspaceEdit: lc.WorkspaceEdit;
|
||||
cursorPosition: Option<lc.TextDocumentPositionParams>;
|
||||
}
|
Loading…
Reference in a new issue