@@ -16,6 +16,7 @@ pub enum Message {
1616 UnboundName {
1717 range : FileRange ,
1818 name : StringId ,
19+ suggestion : Option < StringId > ,
1920 } ,
2021 RefutablePattern {
2122 pattern_range : FileRange ,
@@ -47,6 +48,7 @@ pub enum Message {
4748 head_type : String ,
4849 label_range : FileRange ,
4950 label : StringId ,
51+ suggestion : Option < StringId > ,
5052 } ,
5153 MismatchedFieldLabels {
5254 range : FileRange ,
@@ -144,14 +146,25 @@ impl Message {
144146 let secondary_label = |range : & FileRange | Label :: secondary ( range. file_id ( ) , * range) ;
145147
146148 match self {
147- Message :: UnboundName { range, name } => {
149+ Message :: UnboundName {
150+ range,
151+ name,
152+ suggestion,
153+ } => {
148154 let interner = interner. borrow ( ) ;
149155 let name = interner. resolve ( * name) . unwrap ( ) ;
150156
151- Diagnostic :: error ( )
157+ let mut diagnostic = Diagnostic :: error ( )
152158 . with_message ( format ! ( "cannot find `{name}` in scope" ) )
153- . with_labels ( vec ! [ primary_label( range) . with_message( "unbound name" ) ] )
154- // TODO: list suggestions
159+ . with_labels ( vec ! [ primary_label( range) . with_message( "unbound name" ) ] ) ;
160+
161+ if let Some ( suggestion) = suggestion {
162+ diagnostic = diagnostic. with_notes ( vec ! [ format!(
163+ "help: did you mean `{}`?" ,
164+ interner. resolve( * suggestion) . unwrap( )
165+ ) ] )
166+ }
167+ diagnostic
155168 }
156169 Message :: RefutablePattern { pattern_range } => Diagnostic :: error ( )
157170 . with_message ( "refutable patterns found in binding" )
@@ -208,18 +221,25 @@ impl Message {
208221 head_type,
209222 label_range,
210223 label,
224+ suggestion,
211225 } => {
212226 let interner = interner. borrow ( ) ;
213227 let label = interner. resolve ( * label) . unwrap ( ) ;
214228
215- Diagnostic :: error ( )
229+ let mut diagnostic = Diagnostic :: error ( )
216230 . with_message ( format ! ( "cannot find `{label}` in expression" ) )
217231 . with_labels ( vec ! [
218232 primary_label( label_range) . with_message( "unknown label" ) ,
219233 secondary_label( head_range)
220234 . with_message( format!( "expression of type {head_type}" ) ) ,
221- ] )
222- // TODO: list suggestions
235+ ] ) ;
236+ if let Some ( suggestion) = suggestion {
237+ diagnostic = diagnostic. with_notes ( vec ! [ format!(
238+ "help: did you mean `{}`?" ,
239+ interner. resolve( * suggestion) . unwrap( )
240+ ) ] ) ;
241+ }
242+ diagnostic
223243 }
224244 Message :: MismatchedFieldLabels {
225245 range,
0 commit comments