Skip to content

Commit

Permalink
[1 changes] feat: LSP diagnostics now have "unnecessary" and "depreca…
Browse files Browse the repository at this point in the history
…ted" tags (noir-lang/noir#5878)

feat: LSP code actions to import or qualify unresolved paths (noir-lang/noir#5876)
  • Loading branch information
AztecBot committed Sep 2, 2024
1 parent cf5b667 commit 880cf39
Show file tree
Hide file tree
Showing 23 changed files with 785 additions and 798 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e29d4b3646f0527fc01bc4584ee33616db922c72
2f0d4e017b701b46b5c675e3b34af15ad6f28823
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
#require_command wasm-opt
require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
8 changes: 8 additions & 0 deletions noir/noir-repo/compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct CustomDiagnostic {
pub secondaries: Vec<CustomLabel>,
notes: Vec<String>,
pub kind: DiagnosticKind,
pub deprecated: bool,
pub unnecessary: bool,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand All @@ -35,6 +37,8 @@ impl CustomDiagnostic {
secondaries: Vec::new(),
notes: Vec::new(),
kind: DiagnosticKind::Error,
deprecated: false,
unnecessary: false,
}
}

Expand All @@ -49,6 +53,8 @@ impl CustomDiagnostic {
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
notes: Vec::new(),
kind,
deprecated: false,
unnecessary: false,
}
}

Expand Down Expand Up @@ -101,6 +107,8 @@ impl CustomDiagnostic {
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
notes: Vec::new(),
kind: DiagnosticKind::Bug,
deprecated: false,
unnecessary: false,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,24 @@ impl<'a> From<&'a ResolverError> for Diagnostic {
ResolverError::UnusedVariable { ident } => {
let name = &ident.0.contents;

Diagnostic::simple_warning(
let mut diagnostic = Diagnostic::simple_warning(
format!("unused variable {name}"),
"unused variable ".to_string(),
ident.span(),
)
);
diagnostic.unnecessary = true;
diagnostic
}
ResolverError::UnusedImport { ident } => {
let name = &ident.0.contents;

Diagnostic::simple_warning(
let mut diagnostic = Diagnostic::simple_warning(
format!("unused import {name}"),
"unused import ".to_string(),
ident.span(),
)
);
diagnostic.unnecessary = true;
diagnostic
}
ResolverError::VariableNotDeclared { name, span } => Diagnostic::simple_error(
format!("cannot find `{name}` in this scope "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ impl<'a> From<&'a TypeCheckError> for Diagnostic {
let primary_message = error.to_string();
let secondary_message = note.clone().unwrap_or_default();

Diagnostic::simple_warning(primary_message, secondary_message, *span)
let mut diagnostic = Diagnostic::simple_warning(primary_message, secondary_message, *span);
diagnostic.deprecated = true;
diagnostic
}
TypeCheckError::UnusedResultError { expr_type, expr_span } => {
let msg = format!("Unused expression result of type {expr_type}");
Expand Down
65 changes: 37 additions & 28 deletions noir/noir-repo/compiler/noirc_frontend/src/parser/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,42 +165,51 @@ impl std::fmt::Display for ParserError {
impl<'a> From<&'a ParserError> for Diagnostic {
fn from(error: &'a ParserError) -> Diagnostic {
match &error.reason {
Some(reason) => {
match reason {
ParserErrorReason::ConstrainDeprecated => Diagnostic::simple_error(
Some(reason) => match reason {
ParserErrorReason::ConstrainDeprecated => {
let mut diagnostic = Diagnostic::simple_error(
"Use of deprecated keyword 'constrain'".into(),
"The 'constrain' keyword is deprecated. Please use the 'assert' function instead.".into(),
error.span,
),
ParserErrorReason::ComptimeDeprecated => Diagnostic::simple_warning(
);
diagnostic.deprecated = true;
diagnostic
}
ParserErrorReason::ComptimeDeprecated => {
let mut diagnostic = Diagnostic::simple_warning(
"Use of deprecated keyword 'comptime'".into(),
"The 'comptime' keyword has been deprecated. It can be removed without affecting your program".into(),
error.span,
) ;
diagnostic.deprecated = true;
diagnostic
}
ParserErrorReason::InvalidBitSize(bit_size) => Diagnostic::simple_error(
format!("Use of invalid bit size {}", bit_size),
format!(
"Allowed bit sizes for integers are {}",
IntegerBitSize::allowed_sizes()
.iter()
.map(|n| n.to_string())
.collect::<Vec<_>>()
.join(", ")
),
ParserErrorReason::InvalidBitSize(bit_size) => Diagnostic::simple_error(
format!("Use of invalid bit size {}", bit_size),
format!("Allowed bit sizes for integers are {}", IntegerBitSize::allowed_sizes().iter().map(|n| n.to_string()).collect::<Vec<_>>().join(", ")),
error.span,
),
ParserErrorReason::ExperimentalFeature(_) => Diagnostic::simple_warning(
reason.to_string(),
"".into(),
error.span,
),
ParserErrorReason::TraitImplFunctionModifiers => Diagnostic::simple_warning(
reason.to_string(),
"".into(),
error.span,
),
ParserErrorReason::ExpectedPatternButFoundType(ty) => {
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)
}
ParserErrorReason::Lexer(error) => error.into(),
other => {
Diagnostic::simple_error(format!("{other}"), String::new(), error.span)
}
error.span,
),
ParserErrorReason::ExperimentalFeature(_) => {
Diagnostic::simple_warning(reason.to_string(), "".into(), error.span)
}
}
ParserErrorReason::TraitImplFunctionModifiers => {
Diagnostic::simple_warning(reason.to_string(), "".into(), error.span)
}
ParserErrorReason::ExpectedPatternButFoundType(ty) => 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,
),
ParserErrorReason::Lexer(error) => error.into(),
other => Diagnostic::simple_error(format!("{other}"), String::new(), error.span),
},
None => {
let primary = error.to_string();
Diagnostic::simple_error(primary, String::new(), error.span)
Expand Down
20 changes: 12 additions & 8 deletions noir/noir-repo/compiler/noirc_frontend/src/resolve_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use noirc_errors::Location;
use crate::hir_def::expr::HirExpression;
use crate::hir_def::types::Type;

use crate::node_interner::{DefinitionKind, Node, NodeInterner};
use crate::node_interner::{DefinitionId, DefinitionKind, Node, NodeInterner};

impl NodeInterner {
/// Scans the interner for the item which is located at that [Location]
Expand Down Expand Up @@ -108,14 +108,18 @@ impl NodeInterner {
) -> Option<Location> {
match expression {
HirExpression::Ident(ident, _) => {
let definition_info = self.definition(ident.id);
match definition_info.kind {
DefinitionKind::Function(func_id) => {
Some(self.function_meta(&func_id).location)
if ident.id != DefinitionId::dummy_id() {
let definition_info = self.definition(ident.id);
match definition_info.kind {
DefinitionKind::Function(func_id) => {
Some(self.function_meta(&func_id).location)
}
DefinitionKind::Local(_local_id) => Some(definition_info.location),
DefinitionKind::Global(_global_id) => Some(definition_info.location),
_ => None,
}
DefinitionKind::Local(_local_id) => Some(definition_info.location),
DefinitionKind::Global(_global_id) => Some(definition_info.location),
_ => None,
} else {
None
}
}
HirExpression::Constructor(expr) => {
Expand Down

This file was deleted.

Loading

0 comments on commit 880cf39

Please sign in to comment.