Skip to content

Commit c5f1e60

Browse files
committed
Rework and improve limitation messaging
Signed-off-by: Jonatan Waern<[email protected]>
1 parent 4ffa670 commit c5f1e60

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Change Log
66

77
# 0.9.15
8-
8+
- Improved feedback to user when attempting to obtain symbol information on
9+
a symbol inside an unused template.
910

1011
## 0.9.14
1112
- Slight optimization to the memory usage of device-level analysis which

src/actions/requests.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use crate::actions::{AnalysisProgressKind, AnalysisWaitKind,
1515
ContextDefinition, InitActionContext,
1616
rpc_error_code};
1717
use crate::actions::notifications::ContextDefinitionKindParam;
18-
use crate::analysis::{ZeroSpan, ZeroFilePosition, SymbolRef};
18+
use crate::analysis::{Named, DeclarationSpan, LocationSpan, DLSLimitation,
19+
SymbolRef, ZeroFilePosition, ZeroSpan,
20+
isolated_template_limitation};
1921
use crate::analysis::reference::ReferenceKind;
2022
use crate::analysis::symbols::SimpleSymbol;
2123
use crate::config::Config;
@@ -43,8 +45,7 @@ pub use crate::lsp_data::request::{
4345
};
4446

4547
pub use crate::lsp_data::{self as lsp_data, *};
46-
use crate::analysis::{Named, DeclarationSpan, LocationSpan,
47-
DLSLimitation, ISOLATED_TEMPLATE_LIMITATION};
48+
4849
use crate::analysis::structure::objects::CompObjectKind;
4950

5051
use crate::analysis::scope::{SymbolContext, SubSymbol, ContextKey, Scope};
@@ -127,11 +128,13 @@ where
127128
}
128129

129130

130-
pub const TYPE_SEMANTIC_LIMITATION: DLSLimitation = DLSLimitation {
131-
issue_num: 65,
132-
description: "The DLS does not currently support semantic analysis of \
133-
types, including reference finding",
134-
};
131+
pub fn type_semantic_limitation() -> DLSLimitation {
132+
DLSLimitation {
133+
issue_num: 65,
134+
description: "The DLS does not currently support semantic analysis of \
135+
types, including reference finding".to_string(),
136+
}
137+
}
135138

136139
// TODO: This function is getting bloated, refactor into several smaller ones
137140
fn fp_to_symbol_refs<O: Output>
@@ -185,7 +188,7 @@ fn fp_to_symbol_refs<O: Output>
185188
// Should be guaranteed by the context reference lookup above
186189
// (isolated analysis does exist)
187190
if refr.reference_kind() == ReferenceKind::Type {
188-
relevant_limitations.insert(TYPE_SEMANTIC_LIMITATION);
191+
relevant_limitations.insert(type_semantic_limitation());
189192
}
190193

191194
let first_context = analysis.first_context_at_pos(fp).unwrap();
@@ -210,9 +213,11 @@ fn fp_to_symbol_refs<O: Output>
210213
definitions.append(
211214
&mut device.symbols_of_ref(*refr.loc_span()));
212215
}
213-
if let Some(ContextKey::Template(_)) = first_context {
216+
if let Some(ContextKey::Template(templ)) = first_context {
214217
if !any_template_used {
215-
relevant_limitations.insert(ISOLATED_TEMPLATE_LIMITATION);
218+
relevant_limitations.insert(
219+
isolated_template_limitation(templ.name.as_str())
220+
);
216221
}
217222
}
218223
},

src/analysis/mod.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,16 @@ pub const IMPLICIT_IMPORTS: [&str; 2] = ["dml-builtins.dml",
8282
// The issue number is used as the _unique identifier_ for this
8383
// limitation, and should be the number of an open GITHUB
8484
// issue.
85-
#[allow(dead_code)]
86-
const EXAMPLE: DLSLimitation =
87-
DLSLimitation {
88-
issue_num: 42,
89-
description: "Example of a DLS limitation",
90-
};
85+
// Example:
86+
// DLSLimitation {
87+
// issue_num: 42,
88+
// description: "Example of a DLS limitation".to_string(),
89+
// };
9190

9291
#[derive(Clone, Debug, Eq, PartialEq, Hash,)]
9392
pub struct DLSLimitation {
9493
pub issue_num: u64,
95-
pub description: &'static str,
94+
pub description: String,
9695
}
9796

9897
impl fmt::Display for DLSLimitation {
@@ -555,11 +554,17 @@ fn gather_scopes<'c>(next_scopes: Vec<&'c dyn Scope>,
555554
}
556555
}
557556

558-
pub const ISOLATED_TEMPLATE_LIMITATION: DLSLimitation = DLSLimitation {
559-
issue_num: 31,
560-
description: "References from, and definitions inside, templates cannot \
561-
be evaluated without an instantiating object",
562-
};
557+
pub fn isolated_template_limitation(template_name: &str) -> DLSLimitation {
558+
DLSLimitation {
559+
issue_num: 31,
560+
description:
561+
format!("References from, and definitions inside, a template \
562+
cannot be evaluated \
563+
without an instantiating object. Open a device file \
564+
that uses the template '{}' to obtain such information.",
565+
template_name),
566+
}
567+
}
563568

564569
impl DeviceAnalysis {
565570
pub fn get_device_obj(&self) -> &DMLObject {
@@ -731,7 +736,9 @@ impl DeviceAnalysis {
731736
.get(loc))
732737
{
733738
if templ_impls.is_empty() {
734-
limitations.insert(ISOLATED_TEMPLATE_LIMITATION);
739+
limitations.insert(
740+
isolated_template_limitation(&templ.name)
741+
);
735742
}
736743
return self.contexts_to_objs(
737744
templ_impls

0 commit comments

Comments
 (0)