diff --git a/lapce-proxy/src/dispatch.rs b/lapce-proxy/src/dispatch.rs index e5146a40..b7f1fac1 100644 --- a/lapce-proxy/src/dispatch.rs +++ b/lapce-proxy/src/dispatch.rs @@ -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( diff --git a/lapce-proxy/src/plugin/mod.rs b/lapce-proxy/src/plugin/mod.rs index 677c3c49..590f9de6 100644 --- a/lapce-proxy/src/plugin/mod.rs +++ b/lapce-proxy/src/plugin/mod.rs @@ -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>, 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 { diff --git a/lapce-proxy/src/plugin/psp.rs b/lapce-proxy/src/plugin/psp.rs index 4c385e4f..1f78c0de 100644 --- a/lapce-proxy/src/plugin/psp.rs +++ b/lapce-proxy/src/plugin/psp.rs @@ -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 diff --git a/lapce-rpc/src/proxy.rs b/lapce-rpc/src/proxy.rs index 0b756daa..7bbf6407 100644 --- a/lapce-rpc/src/proxy.rs +++ b/lapce-rpc/src/proxy.rs @@ -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>, + }, GetCodeLensResponse { plugin_id: PluginId, resp: Option>, @@ -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,