mirror of https://github.com/lapce/lapce.git
Implement the `foldingRange` request in the LSP (#3544)
This commit is contained in:
parent
ca0e689a06
commit
a5b7accf61
|
@ -1130,6 +1130,21 @@ fn handle_request(&mut self, id: RequestId, rpc: ProxyRequest) {
|
|||
proxy_rpc.handle_response(id, result);
|
||||
});
|
||||
}
|
||||
LspFoldingRange { path } => {
|
||||
let proxy_rpc = self.proxy_rpc.clone();
|
||||
self.catalog_rpc.get_lsp_folding_range(
|
||||
&path,
|
||||
move |plugin_id, result| {
|
||||
let result = result.map(|resp| {
|
||||
ProxyResponse::LspFoldingRangeResponse {
|
||||
plugin_id,
|
||||
resp,
|
||||
}
|
||||
});
|
||||
proxy_rpc.handle_response(id, result);
|
||||
},
|
||||
);
|
||||
}
|
||||
GetCodeLensResolve { code_lens, path } => {
|
||||
let proxy_rpc = self.proxy_rpc.clone();
|
||||
self.catalog_rpc.get_code_lens_resolve(
|
||||
|
|
|
@ -35,12 +35,12 @@
|
|||
request::{
|
||||
CallHierarchyIncomingCalls, CallHierarchyPrepare, CodeActionRequest,
|
||||
CodeActionResolveRequest, CodeLensRequest, CodeLensResolve, Completion,
|
||||
DocumentSymbolRequest, Formatting, GotoDefinition, GotoImplementation,
|
||||
GotoImplementationResponse, GotoTypeDefinition, GotoTypeDefinitionParams,
|
||||
GotoTypeDefinitionResponse, HoverRequest, InlayHintRequest,
|
||||
InlineCompletionRequest, PrepareRenameRequest, References, Rename, Request,
|
||||
ResolveCompletionItem, SelectionRangeRequest, SemanticTokensFullRequest,
|
||||
SignatureHelpRequest, WorkspaceSymbolRequest,
|
||||
DocumentSymbolRequest, FoldingRangeRequest, Formatting, GotoDefinition,
|
||||
GotoImplementation, GotoImplementationResponse, GotoTypeDefinition,
|
||||
GotoTypeDefinitionParams, GotoTypeDefinitionResponse, HoverRequest,
|
||||
InlayHintRequest, InlineCompletionRequest, PrepareRenameRequest, References,
|
||||
Rename, Request, ResolveCompletionItem, SelectionRangeRequest,
|
||||
SemanticTokensFullRequest, SignatureHelpRequest, WorkspaceSymbolRequest,
|
||||
},
|
||||
CallHierarchyClientCapabilities, CallHierarchyIncomingCall,
|
||||
CallHierarchyIncomingCallsParams, CallHierarchyItem, CallHierarchyPrepareParams,
|
||||
|
@ -51,10 +51,11 @@
|
|||
CompletionItem, CompletionItemCapability,
|
||||
CompletionItemCapabilityResolveSupport, CompletionParams, CompletionResponse,
|
||||
Diagnostic, DocumentFormattingParams, DocumentSymbolClientCapabilities,
|
||||
DocumentSymbolParams, DocumentSymbolResponse, FormattingOptions, GotoCapability,
|
||||
GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverClientCapabilities,
|
||||
HoverParams, InlayHint, InlayHintClientCapabilities, InlayHintParams,
|
||||
InlineCompletionClientCapabilities, InlineCompletionParams,
|
||||
DocumentSymbolParams, DocumentSymbolResponse, FoldingRange,
|
||||
FoldingRangeClientCapabilities, FoldingRangeParams, FormattingOptions,
|
||||
GotoCapability, GotoDefinitionParams, GotoDefinitionResponse, Hover,
|
||||
HoverClientCapabilities, HoverParams, InlayHint, InlayHintClientCapabilities,
|
||||
InlayHintParams, InlineCompletionClientCapabilities, InlineCompletionParams,
|
||||
InlineCompletionResponse, InlineCompletionTriggerKind, Location, MarkupKind,
|
||||
MessageActionItemCapabilities, ParameterInformationSettings,
|
||||
PartialResultParams, Position, PrepareRenameResponse,
|
||||
|
@ -698,6 +699,35 @@ pub fn get_references(
|
|||
);
|
||||
}
|
||||
|
||||
pub fn get_lsp_folding_range(
|
||||
&self,
|
||||
path: &Path,
|
||||
cb: impl FnOnce(
|
||||
PluginId,
|
||||
std::result::Result<Option<Vec<FoldingRange>>, RpcError>,
|
||||
) + Clone
|
||||
+ Send
|
||||
+ 'static,
|
||||
) {
|
||||
let uri = Url::from_file_path(path).unwrap();
|
||||
let method = FoldingRangeRequest::METHOD;
|
||||
let params = FoldingRangeParams {
|
||||
text_document: TextDocumentIdentifier { uri },
|
||||
work_done_progress_params: WorkDoneProgressParams::default(),
|
||||
partial_result_params: PartialResultParams::default(),
|
||||
};
|
||||
|
||||
let language_id =
|
||||
Some(language_id_from_path(path).unwrap_or("").to_string());
|
||||
self.send_request_to_all_plugins(
|
||||
method,
|
||||
params,
|
||||
language_id,
|
||||
Some(path.to_path_buf()),
|
||||
cb,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn go_to_implementation(
|
||||
&self,
|
||||
path: &Path,
|
||||
|
@ -1727,6 +1757,13 @@ fn client_capabilities() -> ClientCapabilities {
|
|||
hierarchical_document_symbol_support: Some(true),
|
||||
..Default::default()
|
||||
}),
|
||||
folding_range: Some(FoldingRangeClientCapabilities {
|
||||
dynamic_registration: Some(false),
|
||||
range_limit: None,
|
||||
line_folding_only: Some(false),
|
||||
folding_range_kind: None,
|
||||
folding_range: None,
|
||||
}),
|
||||
..Default::default()
|
||||
}),
|
||||
window: Some(WindowClientCapabilities {
|
||||
|
|
|
@ -31,18 +31,18 @@
|
|||
request::{
|
||||
CallHierarchyIncomingCalls, CallHierarchyPrepare, CodeActionRequest,
|
||||
CodeActionResolveRequest, CodeLensRequest, CodeLensResolve, Completion,
|
||||
DocumentSymbolRequest, Formatting, GotoDefinition, GotoImplementation,
|
||||
GotoTypeDefinition, HoverRequest, Initialize, InlayHintRequest,
|
||||
InlineCompletionRequest, PrepareRenameRequest, References,
|
||||
DocumentSymbolRequest, FoldingRangeRequest, Formatting, GotoDefinition,
|
||||
GotoImplementation, GotoTypeDefinition, HoverRequest, Initialize,
|
||||
InlayHintRequest, InlineCompletionRequest, PrepareRenameRequest, References,
|
||||
RegisterCapability, Rename, ResolveCompletionItem, SelectionRangeRequest,
|
||||
SemanticTokensFullRequest, SignatureHelpRequest, WorkDoneProgressCreate,
|
||||
WorkspaceSymbolRequest,
|
||||
},
|
||||
CancelParams, CodeActionProviderCapability, DidChangeTextDocumentParams,
|
||||
DidSaveTextDocumentParams, DocumentSelector, HoverProviderCapability,
|
||||
ImplementationProviderCapability, InitializeResult, LogMessageParams,
|
||||
MessageType, OneOf, ProgressParams, PublishDiagnosticsParams, Range,
|
||||
Registration, RegistrationParams, SemanticTokens, SemanticTokensLegend,
|
||||
DidSaveTextDocumentParams, DocumentSelector, FoldingRangeProviderCapability,
|
||||
HoverProviderCapability, ImplementationProviderCapability, InitializeResult,
|
||||
LogMessageParams, MessageType, OneOf, ProgressParams, PublishDiagnosticsParams,
|
||||
Range, Registration, RegistrationParams, SemanticTokens, SemanticTokensLegend,
|
||||
SemanticTokensServerCapabilities, ServerCapabilities, ShowMessageParams,
|
||||
TextDocumentContentChangeEvent, TextDocumentIdentifier,
|
||||
TextDocumentSaveRegistrationOptions, TextDocumentSyncCapability,
|
||||
|
@ -781,6 +781,22 @@ pub fn method_registered(&mut self, method: &str) -> bool {
|
|||
}
|
||||
})
|
||||
.unwrap_or(false),
|
||||
FoldingRangeRequest::METHOD => self
|
||||
.server_capabilities
|
||||
.folding_range_provider
|
||||
.as_ref()
|
||||
.map(|r| match r {
|
||||
FoldingRangeProviderCapability::Simple(support) => *support,
|
||||
FoldingRangeProviderCapability::FoldingProvider(_) => {
|
||||
// todo
|
||||
true
|
||||
}
|
||||
FoldingRangeProviderCapability::Options(_) => {
|
||||
// todo
|
||||
true
|
||||
}
|
||||
})
|
||||
.unwrap_or(false),
|
||||
CodeActionRequest::METHOD => self
|
||||
.server_capabilities
|
||||
.code_action_provider
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
use lsp_types::{
|
||||
request::{GotoImplementationResponse, GotoTypeDefinitionResponse},
|
||||
CallHierarchyIncomingCall, CallHierarchyItem, CodeAction, CodeActionResponse,
|
||||
CodeLens, CompletionItem, Diagnostic, DocumentSymbolResponse,
|
||||
CodeLens, CompletionItem, Diagnostic, DocumentSymbolResponse, FoldingRange,
|
||||
GotoDefinitionResponse, Hover, InlayHint, InlineCompletionResponse,
|
||||
InlineCompletionTriggerKind, Location, Position, PrepareRenameResponse,
|
||||
SelectionRange, SymbolInformation, TextDocumentItem, TextEdit, WorkspaceEdit,
|
||||
|
@ -134,6 +134,9 @@ pub enum ProxyRequest {
|
|||
GetSemanticTokens {
|
||||
path: PathBuf,
|
||||
},
|
||||
LspFoldingRange {
|
||||
path: PathBuf,
|
||||
},
|
||||
PrepareRename {
|
||||
path: PathBuf,
|
||||
position: Position,
|
||||
|
@ -399,6 +402,10 @@ pub enum ProxyResponse {
|
|||
plugin_id: PluginId,
|
||||
resp: CodeActionResponse,
|
||||
},
|
||||
LspFoldingRangeResponse {
|
||||
plugin_id: PluginId,
|
||||
resp: Option<Vec<FoldingRange>>,
|
||||
},
|
||||
GetCodeLensResponse {
|
||||
plugin_id: PluginId,
|
||||
resp: Option<Vec<CodeLens>>,
|
||||
|
@ -932,6 +939,14 @@ pub fn get_type_definition(
|
|||
);
|
||||
}
|
||||
|
||||
pub fn get_lsp_folding_range(
|
||||
&self,
|
||||
path: PathBuf,
|
||||
f: impl ProxyCallback + 'static,
|
||||
) {
|
||||
self.request_async(ProxyRequest::LspFoldingRange { path }, f);
|
||||
}
|
||||
|
||||
pub fn get_references(
|
||||
&self,
|
||||
path: PathBuf,
|
||||
|
|
Loading…
Reference in New Issue