Skip to content

Commit 880cf39

Browse files
author
AztecBot
committed
[1 changes] feat: LSP diagnostics now have "unnecessary" and "deprecated" tags (noir-lang/noir#5878)
feat: LSP code actions to import or qualify unresolved paths (noir-lang/noir#5876)
1 parent cf5b667 commit 880cf39

File tree

23 files changed

+785
-798
lines changed

23 files changed

+785
-798
lines changed

.noir-sync-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e29d4b3646f0527fc01bc4584ee33616db922c72
1+
2f0d4e017b701b46b5c675e3b34af15ad6f28823

noir/noir-repo/acvm-repo/acvm_js/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function run_if_available {
2525
require_command jq
2626
require_command cargo
2727
require_command wasm-bindgen
28-
#require_command wasm-opt
28+
require_command wasm-opt
2929

3030
self_path=$(dirname "$(readlink -f "$0")")
3131
pname=$(cargo read-manifest | jq -r '.name')

noir/noir-repo/compiler/noirc_errors/src/reporter.rs

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub struct CustomDiagnostic {
1212
pub secondaries: Vec<CustomLabel>,
1313
notes: Vec<String>,
1414
pub kind: DiagnosticKind,
15+
pub deprecated: bool,
16+
pub unnecessary: bool,
1517
}
1618

1719
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
@@ -35,6 +37,8 @@ impl CustomDiagnostic {
3537
secondaries: Vec::new(),
3638
notes: Vec::new(),
3739
kind: DiagnosticKind::Error,
40+
deprecated: false,
41+
unnecessary: false,
3842
}
3943
}
4044

@@ -49,6 +53,8 @@ impl CustomDiagnostic {
4953
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
5054
notes: Vec::new(),
5155
kind,
56+
deprecated: false,
57+
unnecessary: false,
5258
}
5359
}
5460

@@ -101,6 +107,8 @@ impl CustomDiagnostic {
101107
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
102108
notes: Vec::new(),
103109
kind: DiagnosticKind::Bug,
110+
deprecated: false,
111+
unnecessary: false,
104112
}
105113
}
106114

noir/noir-repo/compiler/noirc_frontend/src/hir/resolution/errors.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,24 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
150150
ResolverError::UnusedVariable { ident } => {
151151
let name = &ident.0.contents;
152152

153-
Diagnostic::simple_warning(
153+
let mut diagnostic = Diagnostic::simple_warning(
154154
format!("unused variable {name}"),
155155
"unused variable ".to_string(),
156156
ident.span(),
157-
)
157+
);
158+
diagnostic.unnecessary = true;
159+
diagnostic
158160
}
159161
ResolverError::UnusedImport { ident } => {
160162
let name = &ident.0.contents;
161163

162-
Diagnostic::simple_warning(
164+
let mut diagnostic = Diagnostic::simple_warning(
163165
format!("unused import {name}"),
164166
"unused import ".to_string(),
165167
ident.span(),
166-
)
168+
);
169+
diagnostic.unnecessary = true;
170+
diagnostic
167171
}
168172
ResolverError::VariableNotDeclared { name, span } => Diagnostic::simple_error(
169173
format!("cannot find `{name}` in this scope "),

noir/noir-repo/compiler/noirc_frontend/src/hir/type_check/errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ impl<'a> From<&'a TypeCheckError> for Diagnostic {
357357
let primary_message = error.to_string();
358358
let secondary_message = note.clone().unwrap_or_default();
359359

360-
Diagnostic::simple_warning(primary_message, secondary_message, *span)
360+
let mut diagnostic = Diagnostic::simple_warning(primary_message, secondary_message, *span);
361+
diagnostic.deprecated = true;
362+
diagnostic
361363
}
362364
TypeCheckError::UnusedResultError { expr_type, expr_span } => {
363365
let msg = format!("Unused expression result of type {expr_type}");

noir/noir-repo/compiler/noirc_frontend/src/parser/errors.rs

+37-28
Original file line numberDiff line numberDiff line change
@@ -165,42 +165,51 @@ impl std::fmt::Display for ParserError {
165165
impl<'a> From<&'a ParserError> for Diagnostic {
166166
fn from(error: &'a ParserError) -> Diagnostic {
167167
match &error.reason {
168-
Some(reason) => {
169-
match reason {
170-
ParserErrorReason::ConstrainDeprecated => Diagnostic::simple_error(
168+
Some(reason) => match reason {
169+
ParserErrorReason::ConstrainDeprecated => {
170+
let mut diagnostic = Diagnostic::simple_error(
171171
"Use of deprecated keyword 'constrain'".into(),
172172
"The 'constrain' keyword is deprecated. Please use the 'assert' function instead.".into(),
173173
error.span,
174-
),
175-
ParserErrorReason::ComptimeDeprecated => Diagnostic::simple_warning(
174+
);
175+
diagnostic.deprecated = true;
176+
diagnostic
177+
}
178+
ParserErrorReason::ComptimeDeprecated => {
179+
let mut diagnostic = Diagnostic::simple_warning(
176180
"Use of deprecated keyword 'comptime'".into(),
177181
"The 'comptime' keyword has been deprecated. It can be removed without affecting your program".into(),
178182
error.span,
183+
) ;
184+
diagnostic.deprecated = true;
185+
diagnostic
186+
}
187+
ParserErrorReason::InvalidBitSize(bit_size) => Diagnostic::simple_error(
188+
format!("Use of invalid bit size {}", bit_size),
189+
format!(
190+
"Allowed bit sizes for integers are {}",
191+
IntegerBitSize::allowed_sizes()
192+
.iter()
193+
.map(|n| n.to_string())
194+
.collect::<Vec<_>>()
195+
.join(", ")
179196
),
180-
ParserErrorReason::InvalidBitSize(bit_size) => Diagnostic::simple_error(
181-
format!("Use of invalid bit size {}", bit_size),
182-
format!("Allowed bit sizes for integers are {}", IntegerBitSize::allowed_sizes().iter().map(|n| n.to_string()).collect::<Vec<_>>().join(", ")),
183-
error.span,
184-
),
185-
ParserErrorReason::ExperimentalFeature(_) => Diagnostic::simple_warning(
186-
reason.to_string(),
187-
"".into(),
188-
error.span,
189-
),
190-
ParserErrorReason::TraitImplFunctionModifiers => Diagnostic::simple_warning(
191-
reason.to_string(),
192-
"".into(),
193-
error.span,
194-
),
195-
ParserErrorReason::ExpectedPatternButFoundType(ty) => {
196-
Diagnostic::simple_error("Expected a ; separating these two statements".into(), format!("{ty} is a type and cannot be used as a variable name"), error.span)
197-
}
198-
ParserErrorReason::Lexer(error) => error.into(),
199-
other => {
200-
Diagnostic::simple_error(format!("{other}"), String::new(), error.span)
201-
}
197+
error.span,
198+
),
199+
ParserErrorReason::ExperimentalFeature(_) => {
200+
Diagnostic::simple_warning(reason.to_string(), "".into(), error.span)
202201
}
203-
}
202+
ParserErrorReason::TraitImplFunctionModifiers => {
203+
Diagnostic::simple_warning(reason.to_string(), "".into(), error.span)
204+
}
205+
ParserErrorReason::ExpectedPatternButFoundType(ty) => Diagnostic::simple_error(
206+
"Expected a ; separating these two statements".into(),
207+
format!("{ty} is a type and cannot be used as a variable name"),
208+
error.span,
209+
),
210+
ParserErrorReason::Lexer(error) => error.into(),
211+
other => Diagnostic::simple_error(format!("{other}"), String::new(), error.span),
212+
},
204213
None => {
205214
let primary = error.to_string();
206215
Diagnostic::simple_error(primary, String::new(), error.span)

noir/noir-repo/compiler/noirc_frontend/src/resolve_locations.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use noirc_errors::Location;
44
use crate::hir_def::expr::HirExpression;
55
use crate::hir_def::types::Type;
66

7-
use crate::node_interner::{DefinitionKind, Node, NodeInterner};
7+
use crate::node_interner::{DefinitionId, DefinitionKind, Node, NodeInterner};
88

99
impl NodeInterner {
1010
/// Scans the interner for the item which is located at that [Location]
@@ -108,14 +108,18 @@ impl NodeInterner {
108108
) -> Option<Location> {
109109
match expression {
110110
HirExpression::Ident(ident, _) => {
111-
let definition_info = self.definition(ident.id);
112-
match definition_info.kind {
113-
DefinitionKind::Function(func_id) => {
114-
Some(self.function_meta(&func_id).location)
111+
if ident.id != DefinitionId::dummy_id() {
112+
let definition_info = self.definition(ident.id);
113+
match definition_info.kind {
114+
DefinitionKind::Function(func_id) => {
115+
Some(self.function_meta(&func_id).location)
116+
}
117+
DefinitionKind::Local(_local_id) => Some(definition_info.location),
118+
DefinitionKind::Global(_global_id) => Some(definition_info.location),
119+
_ => None,
115120
}
116-
DefinitionKind::Local(_local_id) => Some(definition_info.location),
117-
DefinitionKind::Global(_global_id) => Some(definition_info.location),
118-
_ => None,
121+
} else {
122+
None
119123
}
120124
}
121125
HirExpression::Constructor(expr) => {

noir/noir-repo/test_programs/execution_success/verify_honk_proof/Nargo.toml

-6
This file was deleted.

0 commit comments

Comments
 (0)