Skip to content

Commit

Permalink
Add 'Find References' feature without functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley-Kilgore committed Sep 4, 2024
1 parent 575f0f9 commit 8d118b5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
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

0 comments on commit 8d118b5

Please sign in to comment.