Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions crates/roughly/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,18 @@ fn index_function(
"fn({})",
parameters
.children_by_field_name("parameter", &mut parameters.walk())
.map(|parameter| match parameter.child(0) {
Some(name) => {
rope.byte_slice(name.byte_range()).to_string()
.map(|parameter| {
let name = match parameter.child(0) {
Some(name) => rope.byte_slice(name.byte_range()).to_string(),
None => "Unknown".into(),
};
match parameter.child_by_field_name("default") {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want to store this info on the ItemInfo instead

Some(default) => {
let default = rope.byte_slice(default.byte_range()).to_string();
format!("{name} = {default}")
}
None => name,
}
None => "Unknown".into(),
})
.collect::<Vec<String>>()
.join(", ")
Expand Down
1 change: 1 addition & 0 deletions crates/roughly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod index;
pub mod references;
pub mod rename;
pub mod server;
pub mod signature_help;
pub mod symbols;
pub mod tree;
pub mod utils;
Expand Down
43 changes: 39 additions & 4 deletions crates/roughly/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ use {
GlobPattern, InitializeParams, InitializeResult, InitializedParams, Location,
MessageType, OneOf, Position, PublishDiagnosticsParams, Range, ReferenceParams,
Registration, RegistrationParams, RelativePattern, RenameParams, SaveOptions,
ServerCapabilities, ServerInfo, ShowMessageParams, TextDocumentSyncCapability,
TextDocumentSyncKind, TextDocumentSyncOptions, TextDocumentSyncSaveOptions, TextEdit,
Url, WorkspaceEdit, WorkspaceSymbolParams, WorkspaceSymbolResponse,
ServerCapabilities, ServerInfo, ShowMessageParams, SignatureHelpOptions,
SignatureHelpParams, TextDocumentSyncCapability, TextDocumentSyncKind,
TextDocumentSyncOptions, TextDocumentSyncSaveOptions, TextEdit, Url, WorkspaceEdit,
WorkspaceSymbolParams, WorkspaceSymbolResponse,
notification::{DidChangeWatchedFiles, Notification},
},
references, rename, symbols, tree, utils,
references, rename, signature_help, symbols, tree, utils,
},
async_lsp::{
ClientSocket, ErrorCode, LanguageClient, LanguageServer, ResponseError,
Expand Down Expand Up @@ -149,6 +150,11 @@ impl LanguageServer for ServerState {
trigger_characters: Some(vec!["$".into(), "@".into(), ":".into()]),
..Default::default()
}),
signature_help_provider: Some(SignatureHelpOptions {
trigger_characters: Some(vec!["(".into(), ",".into()]),
retrigger_characters: Some(vec![",".into()]),
..Default::default()
}),
definition_provider: Some(OneOf::Left(true)),
document_formatting_provider: Some(OneOf::Left(true)),
document_range_formatting_provider: Some(OneOf::Left(
Expand Down Expand Up @@ -425,6 +431,35 @@ impl LanguageServer for ServerState {
ControlFlow::Continue(())
}

//
// SIGNATURE HELP
//

fn signature_help(
&mut self,
params: SignatureHelpParams,
) -> BoxFuture<'static, Result<Option<crate::lsp_types::SignatureHelp>, ResponseError>> {
let uri = params.text_document_position_params.text_document.uri;
let path = uri.to_file_path().unwrap();
let position = params.text_document_position_params.position;

tracing::debug!(?path, "signature help");

let Some(document) = self.document_map.get(&path) else {
tracing::error!(?path, "document not found");
return box_future(Err(path_not_found_error(&path)));
};

let result = signature_help::get(
position,
&document.rope,
&document.tree,
&self.workspace_items,
);

box_future(Ok(result))
}

//
// COMPLETION
//
Expand Down
Loading