From 0a6b109d1e9aa1690a85a33cd681a4cea845d7a3 Mon Sep 17 00:00:00 2001 From: Lennart Van Hirtum Date: Wed, 6 Nov 2024 00:56:12 +0100 Subject: [PATCH] Show name and template args on hover --- src/dev_aid/lsp/hover_info.rs | 3 ++- src/linker/mod.rs | 29 +++++++++++++++++++++-------- src/to_string.rs | 25 +++---------------------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/dev_aid/lsp/hover_info.rs b/src/dev_aid/lsp/hover_info.rs index f717fd0..5748d14 100644 --- a/src/dev_aid/lsp/hover_info.rs +++ b/src/dev_aid/lsp/hover_info.rs @@ -204,7 +204,8 @@ pub fn hover(info: LocationInfo, linker: &Linker, file_data: &FileData) -> Vec { 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]; diff --git a/src/linker/mod.rs b/src/linker/mod.rs index 44ba6b4..bd90457 100644 --- a/src/linker/mod.rs +++ b/src/linker/mod.rs @@ -1,4 +1,4 @@ -use crate::{flattening::Instruction, prelude::*}; +use crate::{flattening::Instruction, prelude::*, typing::template::{GenerativeTemplateInputKind, TemplateInputKind, TypeTemplateInputKind}}; pub mod checkpoint; mod resolver; @@ -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 { @@ -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", diff --git a/src/to_string.rs b/src/to_string.rs index 1fb16d9..9314b54 100644 --- a/src/to_string.rs +++ b/src/to_string.rs @@ -8,8 +8,7 @@ use crate::typing::{ abstract_type::{AbstractType, DomainType}, concrete_type::ConcreteType, template::{ - ConcreteTemplateArg, ConcreteTemplateArgs, GenerativeTemplateInputKind, TemplateInputKind, - TemplateInputs, TypeTemplateInputKind, + ConcreteTemplateArg, ConcreteTemplateArgs, TemplateInputs, }, }; @@ -176,26 +175,8 @@ impl Module { file_text: &FileText, local_domains: Option, ) -> 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 {