@@ -4,11 +4,11 @@ use crate::{
4
4
Error , STDLIB_PACKAGE_NAME , analyse,
5
5
ast:: {
6
6
self , ArgNames , AssignName , AssignmentKind , BitArraySegmentTruncation , BoundVariable ,
7
- CallArg , CustomType , FunctionLiteralKind , ImplicitCallArgOrigin , Import , PIPE_PRECEDENCE ,
8
- Pattern , PatternUnusedArguments , PipelineAssignmentKind , Publicity , RecordConstructor ,
9
- SrcSpan , TodoKind , TypedArg , TypedAssignment , TypedClauseGuard , TypedExpr ,
10
- TypedModuleConstant , TypedPattern , TypedPipelineAssignment , TypedRecordConstructor ,
11
- TypedStatement , TypedUse , visit:: Visit as _,
7
+ CallArg , CustomType , FunctionLiteralKind , ImplicitCallArgOrigin , Import , InvalidExpression ,
8
+ PIPE_PRECEDENCE , Pattern , PatternUnusedArguments , PipelineAssignmentKind , Publicity ,
9
+ RecordConstructor , SrcSpan , TodoKind , TypedArg , TypedAssignment , TypedClauseGuard ,
10
+ TypedExpr , TypedModuleConstant , TypedPattern , TypedPipelineAssignment ,
11
+ TypedRecordConstructor , TypedStatement , TypedUse , visit:: Visit as _,
12
12
} ,
13
13
build:: { Located , Module } ,
14
14
config:: PackageConfig ,
@@ -3006,7 +3006,12 @@ impl<'ast> ast::visit::Visit<'ast> for ExtractVariable<'ast> {
3006
3006
3007
3007
// We don't want to offer the action if the cursor is over some invalid
3008
3008
// piece of code.
3009
- fn visit_typed_expr_invalid ( & mut self , location : & ' ast SrcSpan , _type_ : & ' ast Arc < Type > ) {
3009
+ fn visit_typed_expr_invalid (
3010
+ & mut self ,
3011
+ location : & ' ast SrcSpan ,
3012
+ _type_ : & ' ast Arc < Type > ,
3013
+ _extra_information : & ' ast Option < InvalidExpression > ,
3014
+ ) {
3010
3015
let invalid_range = self . edits . src_span_to_lsp_range ( * location) ;
3011
3016
if within ( self . params . range , invalid_range) {
3012
3017
self . selected_expression = None ;
@@ -5121,34 +5126,23 @@ impl<'ast> ast::visit::Visit<'ast> for GenerateFunction<'ast> {
5121
5126
ast:: visit:: visit_typed_function ( self , fun) ;
5122
5127
}
5123
5128
5124
- fn visit_typed_expr_invalid ( & mut self , location : & ' ast SrcSpan , type_ : & ' ast Arc < Type > ) {
5125
- let invalid_range = self . edits . src_span_to_lsp_range ( * location) ;
5126
- if within ( self . params . range , invalid_range) {
5127
- self . try_save_function_to_generate ( * location, type_, None ) ;
5128
- }
5129
-
5130
- ast:: visit:: visit_typed_expr_invalid ( self , location, type_) ;
5131
- }
5132
-
5133
- fn visit_typed_expr_module_select (
5129
+ fn visit_typed_expr_invalid (
5134
5130
& mut self ,
5135
- _location : & ' ast SrcSpan ,
5136
- _field_start : & ' ast u32 ,
5131
+ location : & ' ast SrcSpan ,
5137
5132
type_ : & ' ast Arc < Type > ,
5138
- label : & ' ast EcoString ,
5139
- module_name : & ' ast EcoString ,
5140
- _module_alias : & ' ast EcoString ,
5141
- constructor : & ' ast ModuleValueConstructor ,
5133
+ extra_information : & ' ast Option < InvalidExpression > ,
5142
5134
) {
5143
- match constructor {
5144
- // Invalid module selects leave the `name` field blank
5145
- ModuleValueConstructor :: Fn { name, .. } if name. is_empty ( ) => {
5146
- self . try_save_function_from_other_module ( module_name, label, type_, None ) ;
5135
+ let invalid_range = self . edits . src_span_to_lsp_range ( * location) ;
5136
+ if within ( self . params . range , invalid_range) {
5137
+ match extra_information {
5138
+ Some ( InvalidExpression :: ModuleSelect { module_name, label } ) => {
5139
+ self . try_save_function_from_other_module ( module_name, label, type_, None )
5140
+ }
5141
+ None => self . try_save_function_to_generate ( * location, type_, None ) ,
5147
5142
}
5148
- ModuleValueConstructor :: Fn { .. }
5149
- | ModuleValueConstructor :: Record { .. }
5150
- | ModuleValueConstructor :: Constant { .. } => { }
5151
5143
}
5144
+
5145
+ ast:: visit:: visit_typed_expr_invalid ( self , location, type_, extra_information) ;
5152
5146
}
5153
5147
5154
5148
fn visit_typed_expr_call (
@@ -5168,23 +5162,25 @@ impl<'ast> ast::visit::Visit<'ast> for GenerateFunction<'ast> {
5168
5162
}
5169
5163
5170
5164
match fun {
5171
- TypedExpr :: Invalid { type_, location } => {
5172
- return self . try_save_function_to_generate ( * location, type_, Some ( arguments) ) ;
5173
- }
5174
- TypedExpr :: ModuleSelect {
5175
- module_name,
5176
- label,
5165
+ TypedExpr :: Invalid {
5177
5166
type_,
5178
- constructor : ModuleValueConstructor :: Fn { name , .. } ,
5179
- ..
5180
- } if name . is_empty ( ) => {
5167
+ extra_information : Some ( InvalidExpression :: ModuleSelect { module_name , label } ) ,
5168
+ location : _ ,
5169
+ } => {
5181
5170
return self . try_save_function_from_other_module (
5182
5171
module_name,
5183
5172
label,
5184
5173
type_,
5185
5174
Some ( arguments) ,
5186
5175
) ;
5187
5176
}
5177
+ TypedExpr :: Invalid {
5178
+ type_,
5179
+ location,
5180
+ extra_information : _,
5181
+ } => {
5182
+ return self . try_save_function_to_generate ( * location, type_, Some ( arguments) ) ;
5183
+ }
5188
5184
_ => { }
5189
5185
}
5190
5186
}
@@ -5494,12 +5490,17 @@ impl<'ast, IO> ast::visit::Visit<'ast> for GenerateVariant<'ast, IO>
5494
5490
where
5495
5491
IO : FileSystemReader + FileSystemWriter + BeamCompiler + CommandExecutor + Clone ,
5496
5492
{
5497
- fn visit_typed_expr_invalid ( & mut self , location : & ' ast SrcSpan , type_ : & ' ast Arc < Type > ) {
5493
+ fn visit_typed_expr_invalid (
5494
+ & mut self ,
5495
+ location : & ' ast SrcSpan ,
5496
+ type_ : & ' ast Arc < Type > ,
5497
+ extra_information : & ' ast Option < InvalidExpression > ,
5498
+ ) {
5498
5499
let invalid_range = src_span_to_lsp_range ( * location, self . line_numbers ) ;
5499
5500
if within ( self . params . range , invalid_range) {
5500
5501
self . try_save_variant_to_generate ( * location, type_, None ) ;
5501
5502
}
5502
- ast:: visit:: visit_typed_expr_invalid ( self , location, type_) ;
5503
+ ast:: visit:: visit_typed_expr_invalid ( self , location, type_, extra_information ) ;
5503
5504
}
5504
5505
5505
5506
fn visit_typed_expr_call (
0 commit comments