Skip to content

Commit e4f24fc

Browse files
Implement signature help for function calls
Co-authored-by: felix-andreas-copilot <[email protected]>
1 parent 879a838 commit e4f24fc

File tree

3 files changed

+377
-4
lines changed

3 files changed

+377
-4
lines changed

crates/roughly/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod format;
77
pub mod index;
88
pub mod rename;
99
pub mod server;
10+
pub mod signature_help;
1011
pub mod tree;
1112
pub mod utils;
1213

crates/roughly/src/server.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ use {
1313
GlobPattern, InitializeParams, InitializeResult, InitializedParams, MessageType, OneOf,
1414
Position, PublishDiagnosticsParams, Range, Registration, RegistrationParams,
1515
RelativePattern, RenameParams, SaveOptions, ServerCapabilities, ServerInfo,
16-
ShowMessageParams, TextDocumentSyncCapability, TextDocumentSyncKind,
17-
TextDocumentSyncOptions, TextDocumentSyncSaveOptions, TextEdit, Url, WorkspaceEdit,
18-
WorkspaceSymbolParams, WorkspaceSymbolResponse,
16+
ShowMessageParams, SignatureHelp, SignatureHelpOptions, SignatureHelpParams,
17+
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions,
18+
TextDocumentSyncSaveOptions, TextEdit, Url, WorkspaceEdit, WorkspaceSymbolParams,
19+
WorkspaceSymbolResponse,
1920
notification::{DidChangeWatchedFiles, Notification},
2021
},
21-
rename, tree, utils,
22+
rename, signature_help, tree, utils,
2223
},
2324
async_lsp::{
2425
ClientSocket, ErrorCode, LanguageClient, LanguageServer, ResponseError,
@@ -156,6 +157,11 @@ impl LanguageServer for ServerState {
156157
)),
157158
document_symbol_provider: Some(OneOf::Left(true)),
158159
rename_provider: Some(OneOf::Left(self.experimental_features.rename)),
160+
signature_help_provider: Some(SignatureHelpOptions {
161+
trigger_characters: Some(vec!["(".into(), ",".into()]),
162+
retrigger_characters: None,
163+
work_done_progress_options: Default::default(),
164+
}),
159165
text_document_sync: Some(TextDocumentSyncCapability::Options(
160166
TextDocumentSyncOptions {
161167
open_close: Some(true),
@@ -476,6 +482,35 @@ impl LanguageServer for ServerState {
476482
box_future(Ok(definitions))
477483
}
478484

485+
//
486+
// SIGNATURE HELP
487+
//
488+
489+
fn signature_help(
490+
&mut self,
491+
params: SignatureHelpParams,
492+
) -> BoxFuture<'static, Result<Option<SignatureHelp>, ResponseError>> {
493+
let uri = params.text_document_position_params.text_document.uri;
494+
let path = uri.to_file_path().unwrap();
495+
let position = params.text_document_position_params.position;
496+
497+
tracing::debug!(?path, "signature help");
498+
499+
let Some(document) = self.document_map.get(&path) else {
500+
tracing::info!(?path, "document not found");
501+
return box_future(Err(path_not_found_error(&path)));
502+
};
503+
504+
let signature_help = signature_help::get(
505+
position,
506+
&document.rope,
507+
&document.tree,
508+
&self.workspace_symbols,
509+
);
510+
511+
box_future(Ok(signature_help))
512+
}
513+
479514
//
480515
// FORMATTING
481516
//

0 commit comments

Comments
 (0)