@@ -52,6 +52,17 @@ macro_rules! url {
52
52
} ;
53
53
}
54
54
55
+ macro_rules! clear_notifications {
56
+ ( $channel: expr) => {
57
+ if $channel
58
+ . has_changed( )
59
+ . expect( "Channel should not be closed" )
60
+ {
61
+ let _ = $channel. changed( ) . await ;
62
+ }
63
+ } ;
64
+ }
65
+
55
66
fn fixable_diagnostic ( line : u32 ) -> Result < lsp:: Diagnostic > {
56
67
Ok ( lsp:: Diagnostic {
57
68
range : Range {
@@ -2992,9 +3003,9 @@ export function bar() {
2992
3003
fs. create_file ( "foo.ts" , FOO_CONTENT ) ;
2993
3004
fs. create_file ( "bar.ts" , BAR_CONTENT ) ;
2994
3005
2995
- let ( mut watcher, instruction_channel, notification_channel ) = WorkspaceWatcher :: new ( ) ?;
3006
+ let ( mut watcher, instruction_channel) = WorkspaceWatcher :: new ( ) ?;
2996
3007
2997
- let factory = ServerFactory :: new ( true , instruction_channel. sender . clone ( ) ) ;
3008
+ let mut factory = ServerFactory :: new ( true , instruction_channel. sender . clone ( ) ) ;
2998
3009
2999
3010
let workspace = factory. workspace ( ) ;
3000
3011
tokio:: task:: spawn_blocking ( move || {
@@ -3062,14 +3073,15 @@ export function bar() {
3062
3073
"This import is part of a cycle."
3063
3074
) ;
3064
3075
3065
- let _ = notification_channel . receiver . try_recv ( ) ; // Clear notification, if any.
3076
+ clear_notifications ! ( factory . service_data_rx ) ;
3066
3077
3067
3078
// ARRANGE: Remove `bar.ts`.
3068
3079
std:: fs:: remove_file ( fs. working_directory . join ( "bar.ts" ) ) . expect ( "Cannot remove bar.ts" ) ;
3069
3080
3070
- notification_channel
3071
- . receiver
3072
- . recv ( )
3081
+ factory
3082
+ . service_data_rx
3083
+ . changed ( )
3084
+ . await
3073
3085
. expect ( "Expected notification" ) ;
3074
3086
3075
3087
// ACT: Pull diagnostics.
@@ -3094,13 +3106,14 @@ export function bar() {
3094
3106
assert_eq ! ( result. diagnostics. len( ) , 0 ) ;
3095
3107
3096
3108
// ARRANGE: Recreate `bar.ts`.
3097
- let _ = notification_channel . receiver . try_recv ( ) ; // Clear notification, if any.
3109
+ clear_notifications ! ( factory . service_data_rx ) ;
3098
3110
3099
3111
fs. create_file ( "bar.ts" , BAR_CONTENT ) ;
3100
3112
3101
- notification_channel
3102
- . receiver
3103
- . recv ( )
3113
+ factory
3114
+ . service_data_rx
3115
+ . changed ( )
3116
+ . await
3104
3117
. expect ( "Expected notification" ) ;
3105
3118
3106
3119
// ACT: Pull diagnostics.
@@ -3129,13 +3142,14 @@ export function bar() {
3129
3142
) ;
3130
3143
3131
3144
// ARRANGE: Fix `bar.ts`.
3132
- let _ = notification_channel . receiver . try_recv ( ) ; // Clear notification, if any.
3145
+ clear_notifications ! ( factory . service_data_rx ) ;
3133
3146
3134
3147
fs. create_file ( "bar.ts" , BAR_CONTENT_FIXED ) ;
3135
3148
3136
- notification_channel
3137
- . receiver
3138
- . recv ( )
3149
+ factory
3150
+ . service_data_rx
3151
+ . changed ( )
3152
+ . await
3139
3153
. expect ( "Expected notification" ) ;
3140
3154
3141
3155
// ACT: Pull diagnostics.
@@ -3159,7 +3173,6 @@ export function bar() {
3159
3173
// ASSERT: Diagnostic should disappear again with a fixed `bar.ts`.
3160
3174
assert_eq ! ( result. diagnostics. len( ) , 0 ) ;
3161
3175
3162
- let _ = instruction_channel. sender . send ( WatcherInstruction :: Stop ) ;
3163
3176
server. shutdown ( ) . await ?;
3164
3177
reader. abort ( ) ;
3165
3178
@@ -3201,9 +3214,9 @@ export function bar() {
3201
3214
fs. create_file ( "foo.ts" , FOO_CONTENT ) ;
3202
3215
fs. create_file ( "utils/bar.ts" , BAR_CONTENT ) ;
3203
3216
3204
- let ( mut watcher, instruction_channel, notification_channel ) = WorkspaceWatcher :: new ( ) ?;
3217
+ let ( mut watcher, instruction_channel) = WorkspaceWatcher :: new ( ) ?;
3205
3218
3206
- let factory = ServerFactory :: new ( true , instruction_channel. sender . clone ( ) ) ;
3219
+ let mut factory = ServerFactory :: new ( true , instruction_channel. sender . clone ( ) ) ;
3207
3220
3208
3221
let workspace = factory. workspace ( ) ;
3209
3222
tokio:: task:: spawn_blocking ( move || {
@@ -3271,7 +3284,7 @@ export function bar() {
3271
3284
"This import is part of a cycle."
3272
3285
) ;
3273
3286
3274
- let _ = notification_channel . receiver . try_recv ( ) ; // Clear notification, if any.
3287
+ clear_notifications ! ( factory . service_data_rx ) ;
3275
3288
3276
3289
// ARRANGE: Move `utils` directory.
3277
3290
std:: fs:: rename (
@@ -3280,9 +3293,10 @@ export function bar() {
3280
3293
)
3281
3294
. expect ( "Cannot move utils" ) ;
3282
3295
3283
- notification_channel
3284
- . receiver
3285
- . recv ( )
3296
+ factory
3297
+ . service_data_rx
3298
+ . changed ( )
3299
+ . await
3286
3300
. expect ( "Expected notification" ) ;
3287
3301
3288
3302
// ACT: Pull diagnostics.
@@ -3308,17 +3322,18 @@ export function bar() {
3308
3322
assert_eq ! ( result. diagnostics. len( ) , 0 ) ;
3309
3323
3310
3324
// ARRANGE: Move `utils` back.
3311
- let _ = notification_channel . receiver . try_recv ( ) ; // Clear notification, if any.
3325
+ clear_notifications ! ( factory . service_data_rx ) ;
3312
3326
3313
3327
std:: fs:: rename (
3314
3328
fs. working_directory . join ( "bin" ) ,
3315
3329
fs. working_directory . join ( "utils" ) ,
3316
3330
)
3317
3331
. expect ( "Cannot restore utils" ) ;
3318
3332
3319
- notification_channel
3320
- . receiver
3321
- . recv ( )
3333
+ factory
3334
+ . service_data_rx
3335
+ . changed ( )
3336
+ . await
3322
3337
. expect ( "Expected notification" ) ;
3323
3338
3324
3339
// ACT: Pull diagnostics.
@@ -3346,7 +3361,6 @@ export function bar() {
3346
3361
"This import is part of a cycle."
3347
3362
) ;
3348
3363
3349
- let _ = instruction_channel. sender . send ( WatcherInstruction :: Stop ) ;
3350
3364
server. shutdown ( ) . await ?;
3351
3365
reader. abort ( ) ;
3352
3366
0 commit comments