22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5+ import 'dart:async' ;
6+
57import 'package:analysis_server/lsp_protocol/protocol.dart' ;
68import 'package:analysis_server/src/analysis_server.dart' ;
79import 'package:analysis_server/src/lsp/extensions/code_action.dart' ;
@@ -16,9 +18,9 @@ import 'package:linter/src/rules.dart';
1618import 'package:test/test.dart' ;
1719import 'package:test_reflective_loader/test_reflective_loader.dart' ;
1820
21+ import '../lsp/code_actions_mixin.dart' ;
22+ import '../lsp/server_abstract.dart' ;
1923import '../utils/test_code_extensions.dart' ;
20- import 'code_actions_mixin.dart' ;
21- import 'server_abstract.dart' ;
2224
2325void main () {
2426 defineReflectiveSuite (() {
@@ -123,14 +125,17 @@ bar
123125 }
124126
125127 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+ );
127132
128133 var code = TestCode .parse ('''
129134MyCla^ss? a;
130135''' );
131136
132- newFile (testFilePath, code.code);
133- await initialize ();
137+ createFile (testFilePath, code.code);
138+ await initializeServer ();
134139
135140 var codeActions = await getCodeActions (
136141 testFileUri,
@@ -151,14 +156,17 @@ MyCla^ss? a;
151156 Future <void > test_addImport_preferAbsolute () async {
152157 _enableLints (['always_use_package_imports' ]);
153158
154- newFile (join (projectFolderPath, 'lib' , 'class.dart' ), 'class MyClass {}' );
159+ createFile (
160+ pathContext.join (projectFolderPath, 'lib' , 'class.dart' ),
161+ 'class MyClass {}' ,
162+ );
155163
156164 var code = TestCode .parse ('''
157165MyCla^ss? a;
158166''' );
159167
160- newFile (testFilePath, code.code);
161- await initialize ();
168+ createFile (testFilePath, code.code);
169+ await initializeServer ();
162170
163171 var codeActions = await getCodeActions (
164172 testFileUri,
@@ -175,14 +183,17 @@ MyCla^ss? a;
175183 Future <void > test_addImport_preferRelative () async {
176184 _enableLints (['prefer_relative_imports' ]);
177185
178- newFile (join (projectFolderPath, 'lib' , 'class.dart' ), 'class MyClass {}' );
186+ createFile (
187+ pathContext.join (projectFolderPath, 'lib' , 'class.dart' ),
188+ 'class MyClass {}' ,
189+ );
179190
180191 var code = TestCode .parse ('''
181192MyCla^ss? a;
182193''' );
183194
184- newFile (testFilePath, code.code);
185- await initialize ();
195+ createFile (testFilePath, code.code);
196+ await initializeServer ();
186197
187198 var codeActions = await getCodeActions (
188199 testFileUri,
@@ -288,11 +299,11 @@ Future foo;
288299
289300 Future <void > test_createFile () async {
290301 const content = '''
291- import '[!newfile .dart!]';
302+ import '[!createFile .dart!]';
292303''' ;
293304
294305 const expectedContent = '''
295- >>>>>>>>>> lib/newfile .dart created
306+ >>>>>>>>>> lib/createFile .dart created
296307// TODO Implement this library.<<<<<<<<<<
297308''' ;
298309
@@ -301,7 +312,7 @@ import '[!newfile.dart!]';
301312 content,
302313 expectedContent,
303314 kind: CodeActionKind ('quickfix.create.file' ),
304- title: "Create file 'newfile .dart'" ,
315+ title: "Create file 'createFile .dart'" ,
305316 );
306317 }
307318
@@ -317,8 +328,8 @@ import 'dart:async';
317328
318329Future foo;
319330''' );
320- newFile (testFilePath, code.code);
321- await initialize ();
331+ createFile (testFilePath, code.code);
332+ await initializeServer ();
322333
323334 ofKind (CodeActionKind kind) =>
324335 getCodeActions (testFileUri, range: code.range.range, kinds: [kind]);
@@ -358,8 +369,8 @@ var a = [!foo!]();
358369var b = bar();
359370''' );
360371
361- newFile (testFilePath, code.code);
362- await initialize ();
372+ createFile (testFilePath, code.code);
373+ await initializeServer ();
363374
364375 var allFixes = await getCodeActions (testFileUri, range: code.range.range);
365376
@@ -390,7 +401,7 @@ void f(String a) {
390401 /// https://github.com/dart-lang/sdk/issues/53021
391402 Future <void > test_fixAll_unfixable () async {
392403 registerLintRules ();
393- newFile (analysisOptionsPath, '''
404+ createFile (analysisOptionsPath, '''
394405linter:
395406 rules:
396407 - non_constant_identifier_names
@@ -446,8 +457,8 @@ void main() {
446457}
447458''' );
448459
449- newFile (testFilePath, code.code);
450- await initialize ();
460+ createFile (testFilePath, code.code);
461+ await initializeServer ();
451462
452463 var position = code.position.position;
453464 var range = Range (start: position, end: position);
@@ -536,8 +547,8 @@ Future foo;
536547 var code = TestCode .parse ('''
537548[!import!] 'dart:convert';
538549''' );
539- newFile (testFilePath, code.code);
540- await initialize ();
550+ createFile (testFilePath, code.code);
551+ await initializeServer ();
541552
542553 var codeActions = await getCodeActions (
543554 testFileUri,
@@ -560,7 +571,7 @@ Future foo;
560571 /// is the opening brace) and not the whole range of the error.
561572 Future <void > test_multilineError () async {
562573 registerLintRules ();
563- newFile (analysisOptionsPath, '''
574+ createFile (analysisOptionsPath, '''
564575linter:
565576 rules:
566577 - prefer_expression_function_bodies
@@ -572,8 +583,8 @@ int foo() {
572583}
573584 ''' );
574585
575- newFile (testFilePath, code.code);
576- await initialize ();
586+ createFile (testFilePath, code.code);
587+ await initializeServer ();
577588
578589 var codeActions = await getCodeActions (
579590 testFileUri,
@@ -600,8 +611,8 @@ void f() {
600611}
601612''' );
602613
603- newFile (testFilePath, code.code);
604- await initialize ();
614+ createFile (testFilePath, code.code);
615+ await initializeServer ();
605616
606617 var codeActions = await getCodeActions (
607618 testFileUri,
@@ -628,8 +639,8 @@ void f() {
628639var a = [Test, Test, Te[!!]st];
629640''' );
630641
631- newFile (testFilePath, code.code);
632- await initialize ();
642+ createFile (testFilePath, code.code);
643+ await initializeServer ();
633644
634645 var codeActions = await getCodeActions (
635646 testFileUri,
@@ -654,8 +665,8 @@ var a = [Test, Test, Te[!!]st];
654665var a = [Test, Test, Te[!!]st];
655666''' );
656667
657- newFile (testFilePath, code.code);
658- await initialize ();
668+ createFile (testFilePath, code.code);
669+ await initializeServer ();
659670
660671 var codeActions = await getCodeActions (
661672 testFileUri,
@@ -673,7 +684,7 @@ var a = [Test, Test, Te[!!]st];
673684
674685 Future <void > test_organizeImportsFix_namedOrganizeImports () async {
675686 registerLintRules ();
676- newFile (analysisOptionsPath, '''
687+ createFile (analysisOptionsPath, '''
677688linter:
678689 rules:
679690 - directives_ordering
@@ -705,10 +716,12 @@ ProcessInfo b;
705716 }
706717
707718 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+ );
709722 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 ();
712725
713726 var codeActions = await getCodeActions (
714727 otherFileUri,
@@ -878,7 +891,7 @@ useFunction(int g(a, b)) {}
878891 void _enableLints (List <String > lintNames) {
879892 registerLintRules ();
880893 var lintsYaml = lintNames.map ((name) => ' - $name \n ' ).join ();
881- newFile (analysisOptionsPath, '''
894+ createFile (analysisOptionsPath, '''
882895linter:
883896 rules:
884897$lintsYaml
0 commit comments