Auto merge of #14009 - Veykril:ts-client, r=Veykril

🧹 lsp_ext.ts
This commit is contained in:
bors 2023-01-23 16:19:42 +00:00
commit 1575d55fc8
3 changed files with 130 additions and 158 deletions

View File

@ -172,12 +172,10 @@ export async function createClient(
) )
.then( .then(
(result) => { (result) => {
if (!result) return null;
const hover = client.protocol2CodeConverter.asHover(result); const hover = client.protocol2CodeConverter.asHover(result);
if (hover) { if (!!result.actions) {
const actions = (<any>result).actions; hover.contents.push(renderHoverActions(result.actions));
if (actions) {
hover.contents.push(renderHoverActions(actions));
}
} }
return hover; return hover;
}, },
@ -310,14 +308,14 @@ class ExperimentalFeatures implements lc.StaticFeature {
return { kind: "static" }; return { kind: "static" };
} }
fillClientCapabilities(capabilities: lc.ClientCapabilities): void { fillClientCapabilities(capabilities: lc.ClientCapabilities): void {
const caps: any = capabilities.experimental ?? {}; capabilities.experimental = {
caps.snippetTextEdit = true; snippetTextEdit: true,
caps.codeActionGroup = true; codeActionGroup: true,
caps.hoverActions = true; hoverActions: true,
caps.serverStatusNotification = true; serverStatusNotification: true,
caps.colorDiagnosticOutput = true; colorDiagnosticOutput: true,
caps.openServerLogs = true; openServerLogs: true,
caps.commands = { commands: {
commands: [ commands: [
"rust-analyzer.runSingle", "rust-analyzer.runSingle",
"rust-analyzer.debugSingle", "rust-analyzer.debugSingle",
@ -325,11 +323,12 @@ class ExperimentalFeatures implements lc.StaticFeature {
"rust-analyzer.gotoLocation", "rust-analyzer.gotoLocation",
"editor.action.triggerParameterHints", "editor.action.triggerParameterHints",
], ],
},
...capabilities.experimental,
}; };
capabilities.experimental = caps;
} }
initialize( initialize(
_capabilities: lc.ServerCapabilities<any>, _capabilities: lc.ServerCapabilities,
_documentSelector: lc.DocumentSelector | undefined _documentSelector: lc.DocumentSelector | undefined
): void {} ): void {}
dispose(): void {} dispose(): void {}

View File

@ -130,11 +130,11 @@ export function joinLines(ctx: CtxInit): Cmd {
} }
export function moveItemUp(ctx: CtxInit): Cmd { export function moveItemUp(ctx: CtxInit): Cmd {
return moveItem(ctx, ra.Direction.Up); return moveItem(ctx, "Up");
} }
export function moveItemDown(ctx: CtxInit): Cmd { export function moveItemDown(ctx: CtxInit): Cmd {
return moveItem(ctx, ra.Direction.Down); return moveItem(ctx, "Down");
} }
export function moveItem(ctx: CtxInit, direction: ra.Direction): Cmd { export function moveItem(ctx: CtxInit, direction: ra.Direction): Cmd {

View File

@ -4,131 +4,134 @@
import * as lc from "vscode-languageclient"; import * as lc from "vscode-languageclient";
export interface AnalyzerStatusParams { // rust-analyzer overrides
textDocument?: lc.TextDocumentIdentifier;
} export const hover = new lc.RequestType<
HoverParams,
(lc.Hover & { actions: CommandLinkGroup[] }) | null,
void
>("textDocument/hover");
export type HoverParams = { position: lc.Position | lc.Range } & Omit<
lc.TextDocumentPositionParams,
"position"
> &
lc.WorkDoneProgressParams;
export type CommandLink = {
/**
* A tooltip for the command, when represented in the UI.
*/
tooltip?: string;
} & lc.Command;
export type CommandLinkGroup = {
title?: string;
commands: CommandLink[];
};
// rust-analyzer extensions
export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>( export const analyzerStatus = new lc.RequestType<AnalyzerStatusParams, string, void>(
"rust-analyzer/analyzerStatus" "rust-analyzer/analyzerStatus"
); );
export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage"); export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
export const shuffleCrateGraph = new lc.RequestType0<null, void>("rust-analyzer/shuffleCrateGraph"); export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>(
export interface ServerStatusParams { "rust-analyzer/expandMacro"
health: "ok" | "warning" | "error";
quiescent: boolean;
message?: string;
}
export const serverStatus = new lc.NotificationType<ServerStatusParams>(
"experimental/serverStatus"
); );
export const memoryUsage = new lc.RequestType0<string, void>("rust-analyzer/memoryUsage");
export const openServerLogs = new lc.NotificationType0("rust-analyzer/openServerLogs"); export const openServerLogs = new lc.NotificationType0("rust-analyzer/openServerLogs");
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
"rust-analyzer/relatedTests"
);
export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace"); export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
export const runFlycheck = new lc.NotificationType<{
export const hover = new lc.RequestType<HoverParams, lc.Hover | null, void>("textDocument/hover"); textDocument: lc.TextDocumentIdentifier | null;
}>("rust-analyzer/runFlycheck");
export interface HoverParams extends lc.WorkDoneProgressParams { export const shuffleCrateGraph = new lc.RequestType0<null, void>("rust-analyzer/shuffleCrateGraph");
textDocument: lc.TextDocumentIdentifier;
position: lc.Range | lc.Position;
}
export interface SyntaxTreeParams {
textDocument: lc.TextDocumentIdentifier;
range: lc.Range | null;
}
export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>( export const syntaxTree = new lc.RequestType<SyntaxTreeParams, string, void>(
"rust-analyzer/syntaxTree" "rust-analyzer/syntaxTree"
); );
export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>(
export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>( "rust-analyzer/viewCrateGraph"
"rust-analyzer/viewHir"
); );
export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string, void>( export const viewFileText = new lc.RequestType<lc.TextDocumentIdentifier, string, void>(
"rust-analyzer/viewFileText" "rust-analyzer/viewFileText"
); );
export const viewHir = new lc.RequestType<lc.TextDocumentPositionParams, string, void>(
export interface ViewItemTreeParams { "rust-analyzer/viewHir"
textDocument: lc.TextDocumentIdentifier; );
}
export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>( export const viewItemTree = new lc.RequestType<ViewItemTreeParams, string, void>(
"rust-analyzer/viewItemTree" "rust-analyzer/viewItemTree"
); );
export interface ViewCrateGraphParams { export type AnalyzerStatusParams = { textDocument?: lc.TextDocumentIdentifier };
full: boolean;
}
export const viewCrateGraph = new lc.RequestType<ViewCrateGraphParams, string, void>( export type ExpandMacroParams = {
"rust-analyzer/viewCrateGraph"
);
export interface ExpandMacroParams {
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
position: lc.Position; position: lc.Position;
} };
export interface ExpandedMacro { export type ExpandedMacro = {
name: string; name: string;
expansion: string; expansion: string;
} };
export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro | null, void>( export type TestInfo = { runnable: Runnable };
"rust-analyzer/expandMacro" export type SyntaxTreeParams = {
);
export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>(
"rust-analyzer/relatedTests"
);
export const cancelFlycheck = new lc.NotificationType0("rust-analyzer/cancelFlycheck");
export const clearFlycheck = new lc.NotificationType0("rust-analyzer/clearFlycheck");
export const runFlycheck = new lc.NotificationType<{
textDocument: lc.TextDocumentIdentifier | null;
}>("rust-analyzer/runFlycheck");
// Experimental extensions
export interface SsrParams {
query: string;
parseOnly: boolean;
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
position: lc.Position; range: lc.Range | null;
selections: readonly lc.Range[]; };
} export type ViewCrateGraphParams = { full: boolean };
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr"); export type ViewItemTreeParams = { textDocument: lc.TextDocumentIdentifier };
export interface MatchingBraceParams { // experimental extensions
textDocument: lc.TextDocumentIdentifier;
positions: lc.Position[]; export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>(
} "experimental/joinLines"
);
export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>( export const matchingBrace = new lc.RequestType<MatchingBraceParams, lc.Position[], void>(
"experimental/matchingBrace" "experimental/matchingBrace"
); );
export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>(
"experimental/moveItem"
);
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
"experimental/onEnter"
);
export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
"experimental/openCargoToml"
);
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
"experimental/externalDocs"
);
export const parentModule = new lc.RequestType< export const parentModule = new lc.RequestType<
lc.TextDocumentPositionParams, lc.TextDocumentPositionParams,
lc.LocationLink[] | null, lc.LocationLink[] | null,
void void
>("experimental/parentModule"); >("experimental/parentModule");
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
"experimental/runnables"
);
export const serverStatus = new lc.NotificationType<ServerStatusParams>(
"experimental/serverStatus"
);
export const ssr = new lc.RequestType<SsrParams, lc.WorkspaceEdit, void>("experimental/ssr");
export interface JoinLinesParams { export type JoinLinesParams = {
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
ranges: lc.Range[]; ranges: lc.Range[];
} };
export const joinLines = new lc.RequestType<JoinLinesParams, lc.TextEdit[], void>( export type MatchingBraceParams = {
"experimental/joinLines"
);
export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.TextEdit[], void>(
"experimental/onEnter"
);
export interface RunnablesParams {
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
position: lc.Position | null; positions: lc.Position[];
} };
export type MoveItemParams = {
export interface Runnable { textDocument: lc.TextDocumentIdentifier;
range: lc.Range;
direction: Direction;
};
export type Direction = "Up" | "Down";
export type OpenCargoTomlParams = {
textDocument: lc.TextDocumentIdentifier;
};
export type Runnable = {
label: string; label: string;
location?: lc.LocationLink; location?: lc.LocationLink;
kind: "cargo"; kind: "cargo";
@ -140,50 +143,20 @@ export interface Runnable {
expectTest?: boolean; expectTest?: boolean;
overrideCargo?: string; overrideCargo?: string;
}; };
} };
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>( export type RunnablesParams = {
"experimental/runnables"
);
export interface TestInfo {
runnable: Runnable;
}
export interface CommandLink extends lc.Command {
/**
* A tooltip for the command, when represented in the UI.
*/
tooltip?: string;
}
export interface CommandLinkGroup {
title?: string;
commands: CommandLink[];
}
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
"experimental/externalDocs"
);
export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
"experimental/openCargoToml"
);
export interface OpenCargoTomlParams {
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
} position: lc.Position | null;
};
export const moveItem = new lc.RequestType<MoveItemParams, lc.TextEdit[], void>( export type ServerStatusParams = {
"experimental/moveItem" health: "ok" | "warning" | "error";
); quiescent: boolean;
message?: string;
export interface MoveItemParams { };
export type SsrParams = {
query: string;
parseOnly: boolean;
textDocument: lc.TextDocumentIdentifier; textDocument: lc.TextDocumentIdentifier;
range: lc.Range; position: lc.Position;
direction: Direction; selections: readonly lc.Range[];
} };
export const enum Direction {
Up = "Up",
Down = "Down",
}