languageserver_types/
request.rsuse super::*;
pub trait Request {
type Params;
type Result;
const METHOD: &'static str;
}
#[macro_export]
macro_rules! lsp_request {
("initialize") => {
$crate::request::Initialize
};
("shutdown") => {
$crate::request::Shutdown
};
("window/showMessageRequest") => {
$crate::request::ShowMessageRequest
};
("client/registerCapability") => {
$crate::request::RegisterCapability
};
("client/unregisterCapability") => {
$crate::request::UnregisterCapability
};
("workspace/symbol") => {
$crate::request::WorkspaceSymbol
};
("workspace/executeCommand") => {
$crate::request::ExecuteCommand
};
("textDocument/completion") => {
$crate::request::Completion
};
("completionItem/resolve") => {
$crate::request::ResolveCompletionItem
};
("textDocument/hover") => {
$crate::request::HoverRequest
};
("textDocument/signatureHelp") => {
$crate::request::SignatureHelpRequest
};
("textDocument/declaration") => {
$crate::request::GotoDeclaration
};
("textDocument/definition") => {
$crate::request::GotoDefinition
};
("textDocument/references") => {
$crate::request::References
};
("textDocument/documentHighlight") => {
$crate::request::DocumentHighlightRequest
};
("textDocument/documentSymbol") => {
$crate::request::DocumentSymbolRequest
};
("textDocument/codeAction") => {
$crate::request::CodeActionRequest
};
("textDocument/codeLens") => {
$crate::request::CodeLensRequest
};
("codeLens/resolve") => {
$crate::request::CodeLensResolve
};
("textDocument/documentLink") => {
$crate::request::DocumentLinkRequest
};
("documentLink/resolve") => {
$crate::request::DocumentLinkResolve
};
("workspace/applyEdit") => {
$crate::request::ApplyWorkspaceEdit
};
("textDocument/rangeFormatting") => {
$crate::request::RangeFormatting
};
("textDocument/onTypeFormatting") => {
$crate::request::OnTypeFormatting
};
("textDocument/formatting") => {
$crate::request::Formatting
};
("textDocument/rename") => {
$crate::request::Rename
};
("textDocument/documentColor") => {
$crate::request::DocumentColor
};
("textDocument/colorPresentation") => {
$crate::request::ColorPresentationRequest
};
("textDocument/foldingRange") => {
$crate::request::FoldingRangeRequest
};
("textDocument/prepareRename") => {
$crate::request::PrepareRenameRequest
};
("textDocument/implementation") => {
$crate::request::GotoImplementation
};
("textDocument/typeDefinition") => {
$crate::request::GotoTypeDefinition
};
("workspace/workspaceFolders") => {
$crate::request::WorkspaceFoldersRequest
};
}
#[derive(Debug)]
pub enum Initialize {}
impl Request for Initialize {
type Params = InitializeParams;
type Result = InitializeResult;
const METHOD: &'static str = "initialize";
}
#[derive(Debug)]
pub enum Shutdown {}
impl Request for Shutdown {
type Params = ();
type Result = ();
const METHOD: &'static str = "shutdown";
}
#[derive(Debug)]
pub enum ShowMessageRequest {}
impl Request for ShowMessageRequest {
type Params = ShowMessageRequestParams;
type Result = Option<MessageActionItem>;
const METHOD: &'static str = "window/showMessageRequest";
}
#[derive(Debug)]
pub enum RegisterCapability {}
impl Request for RegisterCapability {
type Params = RegistrationParams;
type Result = ();
const METHOD: &'static str = "client/registerCapability";
}
#[derive(Debug)]
pub enum UnregisterCapability {}
impl Request for UnregisterCapability {
type Params = UnregistrationParams;
type Result = ();
const METHOD: &'static str = "client/unregisterCapability";
}
#[derive(Debug)]
pub enum Completion {}
impl Request for Completion {
type Params = CompletionParams;
type Result = Option<CompletionResponse>;
const METHOD: &'static str = "textDocument/completion";
}
#[derive(Debug)]
pub enum ResolveCompletionItem {}
impl Request for ResolveCompletionItem {
type Params = CompletionItem;
type Result = CompletionItem;
const METHOD: &'static str = "completionItem/resolve";
}
#[derive(Debug)]
pub enum HoverRequest {}
impl Request for HoverRequest {
type Params = TextDocumentPositionParams;
type Result = Option<Hover>;
const METHOD: &'static str = "textDocument/hover";
}
#[derive(Debug)]
pub enum SignatureHelpRequest {}
impl Request for SignatureHelpRequest {
type Params = TextDocumentPositionParams;
type Result = Option<SignatureHelp>;
const METHOD: &'static str = "textDocument/signatureHelp";
}
#[derive(Debug)]
pub enum GotoDeclaration {}
impl Request for GotoDeclaration {
type Params = TextDocumentPositionParams;
type Result = Option<GotoDefinitionResponse>;
const METHOD: &'static str = "textDocument/declaration";
}
#[derive(Debug)]
pub enum GotoDefinition {}
impl Request for GotoDefinition {
type Params = TextDocumentPositionParams;
type Result = Option<GotoDefinitionResponse>;
const METHOD: &'static str = "textDocument/definition";
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GotoDefinitionResponse {
Scalar(Location),
Array(Vec<Location>),
Link(Vec<LocationLink>)
}
#[derive(Debug)]
pub enum References {}
impl Request for References {
type Params = ReferenceParams;
type Result = Option<Vec<Location>>;
const METHOD: &'static str = "textDocument/references";
}
#[derive(Debug)]
pub enum GotoTypeDefinition {}
pub type GotoTypeDefinitionResponse = GotoDefinitionResponse;
impl Request for GotoTypeDefinition {
type Params = TextDocumentPositionParams;
type Result = Option<GotoTypeDefinitionResponse>;
const METHOD: &'static str = "textDocument/typeDefinition";
}
#[derive(Debug)]
pub enum GotoImplementation {}
pub type GotoImplementationResponse = GotoDefinitionResponse;
impl Request for GotoImplementation {
type Params = TextDocumentPositionParams;
type Result = Option<GotoImplementationResponse>;
const METHOD: &'static str = "textDocument/implementation";
}
#[derive(Debug)]
pub enum DocumentHighlightRequest {}
impl Request for DocumentHighlightRequest {
type Params = TextDocumentPositionParams;
type Result = Option<Vec<DocumentHighlight>>;
const METHOD: &'static str = "textDocument/documentHighlight";
}
#[derive(Debug)]
pub enum DocumentSymbolRequest {}
impl Request for DocumentSymbolRequest {
type Params = DocumentSymbolParams;
type Result = Option<DocumentSymbolResponse>;
const METHOD: &'static str = "textDocument/documentSymbol";
}
#[derive(Debug)]
pub enum WorkspaceSymbol {}
impl Request for WorkspaceSymbol {
type Params = WorkspaceSymbolParams;
type Result = Option<Vec<SymbolInformation>>;
const METHOD: &'static str = "workspace/symbol";
}
#[derive(Debug)]
pub enum ExecuteCommand {}
impl Request for ExecuteCommand {
type Params = ExecuteCommandParams;
type Result = Option<Value>;
const METHOD: &'static str = "workspace/executeCommand";
}
#[derive(Debug)]
pub enum ApplyWorkspaceEdit {}
impl Request for ApplyWorkspaceEdit {
type Params = ApplyWorkspaceEditParams;
type Result = ApplyWorkspaceEditResponse;
const METHOD: &'static str = "workspace/applyEdit";
}
#[derive(Debug)]
pub enum CodeActionRequest {}
impl Request for CodeActionRequest {
type Params = CodeActionParams;
type Result = Option<CodeActionResponse>;
const METHOD: &'static str = "textDocument/codeAction";
}
#[derive(Debug)]
pub enum CodeLensRequest {}
impl Request for CodeLensRequest {
type Params = CodeLensParams;
type Result = Option<Vec<CodeLens>>;
const METHOD: &'static str = "textDocument/codeLens";
}
#[derive(Debug)]
pub enum CodeLensResolve {}
impl Request for CodeLensResolve {
type Params = CodeLens;
type Result = CodeLens;
const METHOD: &'static str = "codeLens/resolve";
}
#[derive(Debug)]
pub enum DocumentLinkRequest {}
impl Request for DocumentLinkRequest {
type Params = DocumentLinkParams;
type Result = Option<Vec<DocumentLink>>;
const METHOD: &'static str = "textDocument/documentLink";
}
#[derive(Debug)]
pub enum DocumentLinkResolve {}
impl Request for DocumentLinkResolve {
type Params = DocumentLink;
type Result = DocumentLink;
const METHOD: &'static str = "documentLink/resolve";
}
#[derive(Debug)]
pub enum Formatting {}
impl Request for Formatting {
type Params = DocumentFormattingParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/formatting";
}
#[derive(Debug)]
pub enum RangeFormatting {}
impl Request for RangeFormatting {
type Params = DocumentRangeFormattingParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/rangeFormatting";
}
#[derive(Debug)]
pub enum OnTypeFormatting {}
impl Request for OnTypeFormatting {
type Params = DocumentOnTypeFormattingParams;
type Result = Option<Vec<TextEdit>>;
const METHOD: &'static str = "textDocument/onTypeFormatting";
}
#[derive(Debug)]
pub enum Rename {}
impl Request for Rename {
type Params = RenameParams;
type Result = Option<WorkspaceEdit>;
const METHOD: &'static str = "textDocument/rename";
}
#[derive(Debug)]
pub enum DocumentColor {}
impl Request for DocumentColor {
type Params = DocumentColorParams;
type Result = Vec<ColorInformation>;
const METHOD: &'static str = "textDocument/documentColor";
}
#[derive(Debug)]
pub enum ColorPresentationRequest {}
impl Request for ColorPresentationRequest {
type Params = ColorPresentationParams;
type Result = Vec<ColorPresentation>;
const METHOD: &'static str = "textDocument/colorPresentation";
}
#[derive(Debug)]
pub enum FoldingRangeRequest {}
impl Request for FoldingRangeRequest {
type Params = FoldingRangeParams;
type Result = Option<Vec<FoldingRange>>;
const METHOD: &'static str = "textDocument/foldingRange";
}
#[derive(Debug)]
pub enum PrepareRenameRequest {}
impl Request for PrepareRenameRequest {
type Params = TextDocumentPositionParams;
type Result = Option<PrepareRenameResponse>;
const METHOD: &'static str = "textDocument/prepareRename";
}
#[derive(Debug)]
pub enum WorkspaceFoldersRequest {}
impl Request for WorkspaceFoldersRequest {
type Params = ();
type Result = Option<Vec<WorkspaceFolder>>;
const METHOD: &'static str = "workspace/workspaceFolders";
}
#[cfg(test)]
mod test {
use super::*;
fn fake_call<R>()
where
R: Request,
R::Params: serde::Serialize,
R::Result: serde::de::DeserializeOwned,
{
}
macro_rules! check_macro {
($name:tt) => {
assert_eq!(<lsp_request!($name) as Request>::METHOD, $name);
fake_call::<lsp_request!($name)>();
};
}
#[test]
fn check_macro_definitions() {
check_macro!("initialize");
check_macro!("shutdown");
check_macro!("window/showMessageRequest");
check_macro!("client/registerCapability");
check_macro!("client/unregisterCapability");
check_macro!("workspace/symbol");
check_macro!("workspace/executeCommand");
check_macro!("textDocument/completion");
check_macro!("completionItem/resolve");
check_macro!("textDocument/hover");
check_macro!("textDocument/signatureHelp");
check_macro!("textDocument/declaration");
check_macro!("textDocument/definition");
check_macro!("textDocument/references");
check_macro!("textDocument/documentHighlight");
check_macro!("textDocument/documentSymbol");
check_macro!("textDocument/codeAction");
check_macro!("textDocument/codeLens");
check_macro!("codeLens/resolve");
check_macro!("textDocument/documentLink");
check_macro!("documentLink/resolve");
check_macro!("workspace/applyEdit");
check_macro!("textDocument/rangeFormatting");
check_macro!("textDocument/onTypeFormatting");
check_macro!("textDocument/formatting");
check_macro!("textDocument/rename");
check_macro!("textDocument/documentColor");
check_macro!("textDocument/colorPresentation");
check_macro!("textDocument/foldingRange");
check_macro!("textDocument/prepareRename");
check_macro!("workspace/workspaceFolders");
check_macro!("textDocument/implementation");
check_macro!("textDocument/typeDefinition");
}
}