5
5
import 'dart:async' ;
6
6
import 'dart:convert' ;
7
7
import 'dart:io' ;
8
+ import 'dart:isolate' ;
8
9
9
10
import 'package:analysis_server/lsp_protocol/protocol.dart' ;
10
11
import 'package:analysis_server/src/lsp/channel/lsp_byte_stream_channel.dart' ;
@@ -190,19 +191,6 @@ class LspServerClient {
190
191
_process? .kill ();
191
192
}
192
193
193
- /// Find the root directory of the analysis_server package by proceeding
194
- /// upward to the 'test' dir, and then going up one more directory.
195
- String findRoot (String pathname) {
196
- while (! ['benchmark' , 'test' ].contains (basename (pathname))) {
197
- var parent = dirname (pathname);
198
- if (parent.length >= pathname.length) {
199
- throw Exception ("Can't find root directory" );
200
- }
201
- pathname = parent;
202
- }
203
- return dirname (pathname);
204
- }
205
-
206
194
Future <void > start ({
207
195
required String dartSdkPath,
208
196
List <String >? vmArgs,
@@ -219,14 +207,21 @@ class LspServerClient {
219
207
String serverPath;
220
208
221
209
if (useSnapshot) {
210
+ // TODO(dantup): Consider changing this to "dart language_server" and
211
+ // sharing this code with legacy-server integration tests.
222
212
serverPath = normalize (
223
213
join (dartSdkPath, 'bin' , 'snapshots' , 'analysis_server.dart.snapshot' ),
224
214
);
225
215
} else {
226
- var rootDir = findRoot (
227
- Platform .script.toFilePath (windows: Platform .isWindows),
216
+ // Locate the root of the analysis server package without using
217
+ // `Platform.script` as it fails when run through the `dart test`.
218
+ // https://github.com/dart-lang/test/issues/110
219
+ var serverLibUri = await Isolate .resolvePackageUri (
220
+ Uri .parse ('package:analysis_server/' ),
221
+ );
222
+ serverPath = normalize (
223
+ join (serverLibUri! .toFilePath (), '..' , 'bin' , 'server.dart' ),
228
224
);
229
- serverPath = normalize (join (rootDir, 'bin' , 'server.dart' ));
230
225
}
231
226
232
227
var arguments = [...? vmArgs, serverPath, '--lsp' , '--suppress-analytics' ];
0 commit comments