Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Find References' feature without functionality #1011

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 10 additions & 2 deletions crates/aiken-lang/src/tipo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use self::{environment::Environment, pretty::Printer};
use crate::{
ast::{
well_known, Annotation, DataType, DataTypeKey, DefinitionLocation, ModuleKind, Span,
TypedDataType,
well_known, Annotation, DataType, DataTypeKey, DefinitionLocation, Located, ModuleKind,
Span, TypedDataType, TypedModule,
},
tipo::fields::FieldMap,
};
Expand Down Expand Up @@ -723,6 +723,14 @@ pub fn get_arg_type_name(tipo: &Type) -> String {
}
}

pub fn find_references(_ast: &TypedModule, _node: Located<'_>) -> Vec<Span> {
let references = Vec::new();

// Implement reference finding logic here

references
}

pub fn convert_opaque_type(
t: &Rc<Type>,
data_types: &IndexMap<&DataTypeKey, &TypedDataType>,
Expand Down
1 change: 1 addition & 0 deletions crates/aiken-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn capabilities() -> lsp_types::ServerCapabilities {
// work_done_progress: None,
// },
// }),
references_provider: Some(lsp_types::OneOf::Left(true)),
code_action_provider: Some(lsp_types::CodeActionProviderCapability::Simple(true)),
document_formatting_provider: Some(lsp_types::OneOf::Left(true)),
definition_provider: Some(lsp_types::OneOf::Left(true)),
Expand Down
54 changes: 50 additions & 4 deletions crates/aiken-lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use aiken_lang::{
ast::{Definition, Located, ModuleKind, Span, Use},
error::ExtraData,
line_numbers::LineNumbers,
parser,
parser, tipo,
tipo::pretty::Printer,
};
use aiken_project::{
Expand All @@ -30,10 +30,10 @@ use lsp_types::{
Notification, Progress, PublishDiagnostics, ShowMessage,
},
request::{
CodeActionRequest, Completion, Formatting, GotoDefinition, HoverRequest, Request,
WorkDoneProgressCreate,
CodeActionRequest, Completion, Formatting, GotoDefinition, HoverRequest, References,
Request, WorkDoneProgressCreate,
},
DocumentFormattingParams, InitializeParams, TextEdit,
DocumentFormattingParams, InitializeParams, ReferenceParams, TextEdit,
};
use miette::Diagnostic;
use std::{
Expand Down Expand Up @@ -314,6 +314,18 @@ impl Server {
})
}

References::METHOD => {
let params = cast_request::<References>(request)?;

let locations = self.handle_references(params)?;

Ok(lsp_server::Response {
id,
error: None,
result: Some(serde_json::to_value(locations)?),
})
}

Completion::METHOD => {
let params = cast_request::<Completion>(request).expect("cast Completion");

Expand Down Expand Up @@ -498,6 +510,40 @@ impl Server {
})
}

fn handle_references(
&self,
params: ReferenceParams,
) -> Result<Option<Vec<lsp_types::Location>>, ServerError> {
let position = params.text_document_position.position;
let text_document = params.text_document_position.text_document.clone();

let (line_numbers, node) =
match self.node_at_position(&lsp_types::TextDocumentPositionParams {
text_document: text_document.clone(),
position,
}) {
Some(location) => location,
None => return Ok(None),
};

let module = match self.module_for_uri(&text_document.uri) {
Some(module) => module,
None => return Ok(None),
};

let references = tipo::find_references(&module.ast, node);

let locations = references
.into_iter()
.map(|span| lsp_types::Location {
uri: text_document.uri.clone(),
range: span_to_lsp_range(span, &line_numbers),
})
.collect();

Ok(Some(locations))
}

fn hover(
&self,
params: lsp_types::HoverParams,
Expand Down
Loading