2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ import 'dart:async' ;
6
+
5
7
import 'package:analysis_server/lsp_protocol/protocol.dart' ;
6
8
import 'package:analysis_server/src/analysis_server.dart' ;
7
9
import 'package:analysis_server/src/lsp/extensions/code_action.dart' ;
@@ -16,9 +18,9 @@ import 'package:linter/src/rules.dart';
16
18
import 'package:test/test.dart' ;
17
19
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
18
20
21
+ import '../lsp/code_actions_mixin.dart' ;
22
+ import '../lsp/server_abstract.dart' ;
19
23
import '../utils/test_code_extensions.dart' ;
20
- import 'code_actions_mixin.dart' ;
21
- import 'server_abstract.dart' ;
22
24
23
25
void main () {
24
26
defineReflectiveSuite (() {
@@ -123,14 +125,17 @@ bar
123
125
}
124
126
125
127
Future <void > test_addImport_noPreference () async {
126
- newFile (join (projectFolderPath, 'lib' , 'class.dart' ), 'class MyClass {}' );
128
+ createFile (
129
+ pathContext.join (projectFolderPath, 'lib' , 'class.dart' ),
130
+ 'class MyClass {}' ,
131
+ );
127
132
128
133
var code = TestCode .parse ('''
129
134
MyCla^ss? a;
130
135
''' );
131
136
132
- newFile (testFilePath, code.code);
133
- await initialize ();
137
+ createFile (testFilePath, code.code);
138
+ await initializeServer ();
134
139
135
140
var codeActions = await getCodeActions (
136
141
testFileUri,
@@ -151,14 +156,17 @@ MyCla^ss? a;
151
156
Future <void > test_addImport_preferAbsolute () async {
152
157
_enableLints (['always_use_package_imports' ]);
153
158
154
- newFile (join (projectFolderPath, 'lib' , 'class.dart' ), 'class MyClass {}' );
159
+ createFile (
160
+ pathContext.join (projectFolderPath, 'lib' , 'class.dart' ),
161
+ 'class MyClass {}' ,
162
+ );
155
163
156
164
var code = TestCode .parse ('''
157
165
MyCla^ss? a;
158
166
''' );
159
167
160
- newFile (testFilePath, code.code);
161
- await initialize ();
168
+ createFile (testFilePath, code.code);
169
+ await initializeServer ();
162
170
163
171
var codeActions = await getCodeActions (
164
172
testFileUri,
@@ -175,14 +183,17 @@ MyCla^ss? a;
175
183
Future <void > test_addImport_preferRelative () async {
176
184
_enableLints (['prefer_relative_imports' ]);
177
185
178
- newFile (join (projectFolderPath, 'lib' , 'class.dart' ), 'class MyClass {}' );
186
+ createFile (
187
+ pathContext.join (projectFolderPath, 'lib' , 'class.dart' ),
188
+ 'class MyClass {}' ,
189
+ );
179
190
180
191
var code = TestCode .parse ('''
181
192
MyCla^ss? a;
182
193
''' );
183
194
184
- newFile (testFilePath, code.code);
185
- await initialize ();
195
+ createFile (testFilePath, code.code);
196
+ await initializeServer ();
186
197
187
198
var codeActions = await getCodeActions (
188
199
testFileUri,
@@ -288,11 +299,11 @@ Future foo;
288
299
289
300
Future <void > test_createFile () async {
290
301
const content = '''
291
- import '[!newfile .dart!]';
302
+ import '[!createFile .dart!]';
292
303
''' ;
293
304
294
305
const expectedContent = '''
295
- >>>>>>>>>> lib/newfile .dart created
306
+ >>>>>>>>>> lib/createFile .dart created
296
307
// TODO Implement this library.<<<<<<<<<<
297
308
''' ;
298
309
@@ -301,7 +312,7 @@ import '[!newfile.dart!]';
301
312
content,
302
313
expectedContent,
303
314
kind: CodeActionKind ('quickfix.create.file' ),
304
- title: "Create file 'newfile .dart'" ,
315
+ title: "Create file 'createFile .dart'" ,
305
316
);
306
317
}
307
318
@@ -317,8 +328,8 @@ import 'dart:async';
317
328
318
329
Future foo;
319
330
''' );
320
- newFile (testFilePath, code.code);
321
- await initialize ();
331
+ createFile (testFilePath, code.code);
332
+ await initializeServer ();
322
333
323
334
ofKind (CodeActionKind kind) =>
324
335
getCodeActions (testFileUri, range: code.range.range, kinds: [kind]);
@@ -358,8 +369,8 @@ var a = [!foo!]();
358
369
var b = bar();
359
370
''' );
360
371
361
- newFile (testFilePath, code.code);
362
- await initialize ();
372
+ createFile (testFilePath, code.code);
373
+ await initializeServer ();
363
374
364
375
var allFixes = await getCodeActions (testFileUri, range: code.range.range);
365
376
@@ -390,7 +401,7 @@ void f(String a) {
390
401
/// https://github.com/dart-lang/sdk/issues/53021
391
402
Future <void > test_fixAll_unfixable () async {
392
403
registerLintRules ();
393
- newFile (analysisOptionsPath, '''
404
+ createFile (analysisOptionsPath, '''
394
405
linter:
395
406
rules:
396
407
- non_constant_identifier_names
@@ -446,8 +457,8 @@ void main() {
446
457
}
447
458
''' );
448
459
449
- newFile (testFilePath, code.code);
450
- await initialize ();
460
+ createFile (testFilePath, code.code);
461
+ await initializeServer ();
451
462
452
463
var position = code.position.position;
453
464
var range = Range (start: position, end: position);
@@ -536,8 +547,8 @@ Future foo;
536
547
var code = TestCode .parse ('''
537
548
[!import!] 'dart:convert';
538
549
''' );
539
- newFile (testFilePath, code.code);
540
- await initialize ();
550
+ createFile (testFilePath, code.code);
551
+ await initializeServer ();
541
552
542
553
var codeActions = await getCodeActions (
543
554
testFileUri,
@@ -560,7 +571,7 @@ Future foo;
560
571
/// is the opening brace) and not the whole range of the error.
561
572
Future <void > test_multilineError () async {
562
573
registerLintRules ();
563
- newFile (analysisOptionsPath, '''
574
+ createFile (analysisOptionsPath, '''
564
575
linter:
565
576
rules:
566
577
- prefer_expression_function_bodies
@@ -572,8 +583,8 @@ int foo() {
572
583
}
573
584
''' );
574
585
575
- newFile (testFilePath, code.code);
576
- await initialize ();
586
+ createFile (testFilePath, code.code);
587
+ await initializeServer ();
577
588
578
589
var codeActions = await getCodeActions (
579
590
testFileUri,
@@ -600,8 +611,8 @@ void f() {
600
611
}
601
612
''' );
602
613
603
- newFile (testFilePath, code.code);
604
- await initialize ();
614
+ createFile (testFilePath, code.code);
615
+ await initializeServer ();
605
616
606
617
var codeActions = await getCodeActions (
607
618
testFileUri,
@@ -628,8 +639,8 @@ void f() {
628
639
var a = [Test, Test, Te[!!]st];
629
640
''' );
630
641
631
- newFile (testFilePath, code.code);
632
- await initialize ();
642
+ createFile (testFilePath, code.code);
643
+ await initializeServer ();
633
644
634
645
var codeActions = await getCodeActions (
635
646
testFileUri,
@@ -654,8 +665,8 @@ var a = [Test, Test, Te[!!]st];
654
665
var a = [Test, Test, Te[!!]st];
655
666
''' );
656
667
657
- newFile (testFilePath, code.code);
658
- await initialize ();
668
+ createFile (testFilePath, code.code);
669
+ await initializeServer ();
659
670
660
671
var codeActions = await getCodeActions (
661
672
testFileUri,
@@ -673,7 +684,7 @@ var a = [Test, Test, Te[!!]st];
673
684
674
685
Future <void > test_organizeImportsFix_namedOrganizeImports () async {
675
686
registerLintRules ();
676
- newFile (analysisOptionsPath, '''
687
+ createFile (analysisOptionsPath, '''
677
688
linter:
678
689
rules:
679
690
- directives_ordering
@@ -705,10 +716,12 @@ ProcessInfo b;
705
716
}
706
717
707
718
Future <void > test_outsideRoot () async {
708
- var otherFilePath = convertPath ('/home/otherProject/foo.dart' );
719
+ var otherFilePath = pathContext.normalize (
720
+ pathContext.join (projectFolderPath, '..' , 'otherProject' , 'foo.dart' ),
721
+ );
709
722
var otherFileUri = pathContext.toUri (otherFilePath);
710
- newFile (otherFilePath, 'bad code to create error' );
711
- await initialize ();
723
+ createFile (otherFilePath, 'bad code to create error' );
724
+ await initializeServer ();
712
725
713
726
var codeActions = await getCodeActions (
714
727
otherFileUri,
@@ -878,7 +891,7 @@ useFunction(int g(a, b)) {}
878
891
void _enableLints (List <String > lintNames) {
879
892
registerLintRules ();
880
893
var lintsYaml = lintNames.map ((name) => ' - $name \n ' ).join ();
881
- newFile (analysisOptionsPath, '''
894
+ createFile (analysisOptionsPath, '''
882
895
linter:
883
896
rules:
884
897
$lintsYaml
0 commit comments