detectIDEs method
Detects IDEs that have a running extension/plugin.
Implementation
Future<List<DetectedIDEInfo>> detectIDEs({
bool includeInvalid = false,
}) async {
final detectedIDEs = <DetectedIDEInfo>[];
try {
final cwd = _getOriginalCwd();
final lockfiles = await getSortedIdeLockfiles();
final lockfileInfos = await Future.wait(lockfiles.map(readIdeLockfile));
for (final lockfileInfo in lockfileInfos) {
if (lockfileInfo == null) continue;
// Check workspace folder match
bool isValid = false;
for (final idePath in lockfileInfo.workspaceFolders) {
if (idePath.isEmpty) continue;
final resolvedPath = Uri.parse(idePath).toFilePath();
if (cwd == resolvedPath || cwd.startsWith('$resolvedPath/')) {
isValid = true;
break;
}
}
if (!isValid && !includeInvalid) continue;
final host = await detectHostIP(
lockfileInfo.runningInWindows,
lockfileInfo.port,
);
final url = lockfileInfo.useWebSocket
? 'ws://$host:${lockfileInfo.port}'
: 'http://$host:${lockfileInfo.port}/sse';
detectedIDEs.add(
DetectedIDEInfo(
url: url,
name: lockfileInfo.ideName ?? 'IDE',
workspaceFolders: lockfileInfo.workspaceFolders,
port: lockfileInfo.port,
isValid: isValid,
authToken: lockfileInfo.authToken,
ideRunningInWindows: lockfileInfo.runningInWindows,
),
);
}
} catch (e) {
_logError(e);
}
return detectedIDEs;
}