Skip to content

Commit

Permalink
Show name and template args on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Nov 5, 2024
1 parent 4d6b440 commit 0a6b109
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/dev_aid/lsp/hover_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ pub fn hover(info: LocationInfo, linker: &Linker, file_data: &FileData) -> Vec<M
LocationInfo::Global(global) => {
let link_info = linker.get_link_info(global);
hover.documentation_link_info(link_info);
hover.sus_code(format!("{}", linker.get_full_name(global)));
let file = &linker.files[link_info.file];
hover.sus_code(format!("{}", link_info.get_full_name_and_template_args(&file.file_text)));
match global {
NameElem::Module(md_uuid) => {
let md = &linker.modules[md_uuid];
Expand Down
29 changes: 21 additions & 8 deletions src/linker/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{flattening::Instruction, prelude::*};
use crate::{flattening::Instruction, prelude::*, typing::template::{GenerativeTemplateInputKind, TemplateInputKind, TypeTemplateInputKind}};

pub mod checkpoint;
mod resolver;
Expand Down Expand Up @@ -118,6 +118,26 @@ impl LinkInfo {
pub fn get_span_file(&self) -> SpanFile {
(self.name_span, self.file)
}
pub fn get_full_name_and_template_args(&self, file_text: &FileText) -> String {
let mut template_args: Vec<&str> = Vec::new();
for (_id, t) in &self.template_arguments {
match &t.kind {
TemplateInputKind::Type(TypeTemplateInputKind { }) => {
template_args.push(&t.name)
}
TemplateInputKind::Generative(GenerativeTemplateInputKind {
decl_span,
declaration_instruction: _,
}) => template_args.push(&file_text[*decl_span])
}
}

format!(
"{} #({})",
self.get_full_name(),
template_args.join(", ")
)
}
}

pub struct LinkingErrorLocation {
Expand Down Expand Up @@ -217,13 +237,6 @@ impl Linker {
NameElem::Constant(cst_id) => &mut constants[cst_id].link_info
}
}
pub fn get_full_name(&self, global: NameElem) -> String {
match global {
NameElem::Module(id) => self.modules[id].link_info.get_full_name(),
NameElem::Type(id) => self.types[id].link_info.get_full_name(),
NameElem::Constant(id) => self.constants[id].link_info.get_full_name(),
}
}
fn get_linking_error_location(&self, global: NameElem) -> LinkingErrorLocation {
let named_type = match global {
NameElem::Module(_) => "Module",
Expand Down
25 changes: 3 additions & 22 deletions src/to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::typing::{
abstract_type::{AbstractType, DomainType},
concrete_type::ConcreteType,
template::{
ConcreteTemplateArg, ConcreteTemplateArgs, GenerativeTemplateInputKind, TemplateInputKind,
TemplateInputs, TypeTemplateInputKind,
ConcreteTemplateArg, ConcreteTemplateArgs, TemplateInputs,
},
};

Expand Down Expand Up @@ -176,26 +175,8 @@ impl Module {
file_text: &FileText,
local_domains: Option<InterfaceToDomainMap>,
) -> String {
use std::fmt::Write;

let mut template_args: Vec<&str> = Vec::new();
for (_id, t) in &self.link_info.template_arguments {
match &t.kind {
TemplateInputKind::Type(TypeTemplateInputKind { }) => {
template_args.push(&t.name)
}
TemplateInputKind::Generative(GenerativeTemplateInputKind {
decl_span,
declaration_instruction: _,
}) => template_args.push(&file_text[*decl_span])
}
}

let mut result = format!(
"module {} #({}):\n",
self.link_info.get_full_name(),
template_args.join(", ")
);
let full_name_with_args = self.link_info.get_full_name_and_template_args(file_text);
let mut result = format!("module {full_name_with_args}:\n");

for (domain_id, domain) in &self.domains {
if let Some(domain_map) = &local_domains {
Expand Down

0 comments on commit 0a6b109

Please sign in to comment.