From a30bdd9795770329e4562d8bfca60ebe2e52dea1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 May 2020 14:56:26 +0200 Subject: Cleanup lsp extensions on the client side --- editors/code/src/commands.ts | 2 +- editors/code/src/debug.ts | 2 +- editors/code/src/inlay_hints.ts | 2 +- editors/code/src/lsp_ext.ts | 84 +++++++++++++++++++++++ editors/code/src/run.ts | 2 +- editors/code/src/rust-analyzer-api.ts | 123 ---------------------------------- 6 files changed, 88 insertions(+), 127 deletions(-) create mode 100644 editors/code/src/lsp_ext.ts delete mode 100644 editors/code/src/rust-analyzer-api.ts (limited to 'editors') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index e08030140..49e3845d5 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -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'; diff --git a/editors/code/src/debug.ts b/editors/code/src/debug.ts index d3fe588e8..027504ecd 100644 --- a/editors/code/src/debug.ts +++ b/editors/code/src/debug.ts @@ -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"; diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index a2b07d003..9e6d6045f 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -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'; diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts new file mode 100644 index 000000000..2a0663261 --- /dev/null +++ b/editors/code/src/lsp_ext.ts @@ -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("rust-analyzer/analyzerStatus"); + +export const collectGarbage = new lc.RequestType("rust-analyzer/collectGarbage"); + +export interface SyntaxTreeParams { + textDocument: lc.TextDocumentIdentifier; + range: lc.Range | null; +} +export const syntaxTree = new lc.RequestType("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("rust-analyzer/expandMacro"); + +export interface MatchingBraceParams { + textDocument: lc.TextDocumentIdentifier; + positions: lc.Position[]; +} +export const matchingBrace = new lc.RequestType("experimental/matchingBrace"); + +export const parentModule = new lc.RequestType("rust-analyzer/parentModule"); + +export interface JoinLinesParams { + textDocument: lc.TextDocumentIdentifier; + ranges: lc.Range[]; +} +export const joinLines = new lc.RequestType("experimental/joinLines"); + +export const onEnter = new lc.RequestType("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("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("rust-analyzer/inlayHints"); + +export interface SsrParams { + query: string; + parseOnly: boolean; +} +export const ssr = new lc.RequestType('experimental/ssr'); diff --git a/editors/code/src/run.ts b/editors/code/src/run.ts index 8f0487d74..2a7a429cf 100644 --- a/editors/code/src/run.ts +++ b/editors/code/src/run.ts @@ -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'; diff --git a/editors/code/src/rust-analyzer-api.ts b/editors/code/src/rust-analyzer-api.ts deleted file mode 100644 index c10c0fa78..000000000 --- a/editors/code/src/rust-analyzer-api.ts +++ /dev/null @@ -1,123 +0,0 @@ -/** - * This file mirrors `crates/rust-analyzer/src/req.rs` declarations. - */ - -import * as lc from "vscode-languageclient"; - -type Option = null | T; -type Vec = T[]; -type FxHashMap = Record; - -function request(method: string) { - return new lc.RequestType(`rust-analyzer/${method}`); -} -function notification(method: string) { - return new lc.NotificationType(method); -} - - -export const analyzerStatus = request("analyzerStatus"); - - -export const collectGarbage = request("collectGarbage"); - - -export interface SyntaxTreeParams { - textDocument: lc.TextDocumentIdentifier; - range: Option; -} -export const syntaxTree = request("syntaxTree"); - - -export interface ExpandMacroParams { - textDocument: lc.TextDocumentIdentifier; - position: Option; -} -export interface ExpandedMacro { - name: string; - expansion: string; -} -export const expandMacro = request>("expandMacro"); - - -export interface MatchingBraceParams { - textDocument: lc.TextDocumentIdentifier; - positions: lc.Position[]; -} -export const matchingBrace = new lc.RequestType('experimental/matchingBrace'); - -export interface PublishDecorationsParams { - uri: string; - decorations: Vec; -} -export interface Decoration { - range: lc.Range; - tag: string; - bindingHash: Option; -} -export const decorationsRequest = request>("decorationsRequest"); - - -export const parentModule = request>("parentModule"); - - -export interface JoinLinesParams { - textDocument: lc.TextDocumentIdentifier; - ranges: lc.Range[]; -} -export const joinLines = new lc.RequestType('experimental/joinLines'); - -export const onEnter = new lc.RequestType('experimental/onEnter'); - -export interface RunnablesParams { - textDocument: lc.TextDocumentIdentifier; - position: Option; -} -export interface Runnable { - range: lc.Range; - label: string; - bin: string; - args: Vec; - extraArgs: Vec; - env: FxHashMap; - cwd: Option; -} -export const runnables = request>("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>("inlayHints"); - - -export interface SsrParams { - query: string; - parseOnly: boolean; -} -export const ssr = new lc.RequestType('experimental/ssr'); - - -export const publishDecorations = notification("publishDecorations"); - - -export interface SourceChange { - label: string; - workspaceEdit: lc.WorkspaceEdit; - cursorPosition: Option; -} -- cgit v1.2.3