use of com.google.dart.server.internal.remote.StdioServerSocket in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method startServer.
private void startServer(@NotNull final DartSdk sdk) {
// DartPubActionBase will start the server itself when finished
if (DartPubActionBase.isInProgress())
return;
synchronized (myLock) {
mySdkHome = sdk.getHomePath();
final String runtimePath = FileUtil.toSystemDependentName(DartSdkUtil.getDartExePath(sdk));
String analysisServerPath = FileUtil.toSystemDependentName(mySdkHome + "/bin/snapshots/analysis_server.dart.snapshot");
analysisServerPath = System.getProperty("dart.server.path", analysisServerPath);
String dasStartupErrorMessage = "";
final File runtimePathFile = new File(runtimePath);
final File dasSnapshotFile = new File(analysisServerPath);
if (!runtimePathFile.exists()) {
dasStartupErrorMessage = "the Dart VM file does not exist at location: " + runtimePath;
} else if (!dasSnapshotFile.exists()) {
dasStartupErrorMessage = "the Dart Analysis Server snapshot file does not exist at location: " + analysisServerPath;
} else if (!runtimePathFile.canExecute()) {
dasStartupErrorMessage = "the Dart VM file is not executable at location: " + runtimePath;
} else if (!dasSnapshotFile.canRead()) {
dasStartupErrorMessage = "the Dart Analysis Server snapshot file is not readable at location: " + analysisServerPath;
}
if (!dasStartupErrorMessage.isEmpty()) {
LOG.warn("Failed to start Dart analysis server: " + dasStartupErrorMessage);
stopServer();
return;
}
final DebugPrintStream debugStream = str -> {
str = str.substring(0, Math.min(str.length(), MAX_DEBUG_LOG_LINE_LENGTH));
synchronized (myDebugLog) {
myDebugLog.add(str);
}
};
String vmArgsRaw;
try {
vmArgsRaw = Registry.stringValue("dart.server.vm.options");
} catch (MissingResourceException e) {
vmArgsRaw = "";
}
String serverArgsRaw = "";
serverArgsRaw += " --useAnalysisHighlight2";
//serverArgsRaw += " --file-read-mode=normalize-eol-always";
try {
serverArgsRaw += " " + Registry.stringValue("dart.server.additional.arguments");
} catch (MissingResourceException e) {
// NOP
}
myServerSocket = new StdioServerSocket(runtimePath, StringUtil.split(vmArgsRaw, " "), analysisServerPath, StringUtil.split(serverArgsRaw, " "), debugStream);
myServerSocket.setClientId(getClientId());
myServerSocket.setClientVersion(getClientVersion());
final AnalysisServer startedServer = new RemoteAnalysisServerImpl(myServerSocket);
try {
startedServer.start();
startedServer.server_setSubscriptions(Collections.singletonList(ServerService.STATUS));
if (Registry.is("dart.projects.without.pubspec", false)) {
startedServer.analysis_setGeneralSubscriptions(Collections.singletonList(GeneralAnalysisService.ANALYZED_FILES));
}
if (!myInitializationOnServerStartupDone) {
myInitializationOnServerStartupDone = true;
registerFileEditorManagerListener();
registerDocumentListener();
setDasLogger();
registerQuickAssistIntentions();
}
startedServer.addAnalysisServerListener(myAnalysisServerListener);
for (AnalysisServerListener listener : myAdditionalServerListeners) {
startedServer.addAnalysisServerListener(listener);
}
myHaveShownInitialProgress = false;
startedServer.addStatusListener(isAlive -> {
if (!isAlive) {
synchronized (myLock) {
if (startedServer == myServer) {
stopServer();
}
}
}
});
mySdkVersion = sdk.getVersion();
startedServer.analysis_updateOptions(new AnalysisOptions(true, true, true, true, true, false, true, false));
myServer = startedServer;
} catch (Exception e) {
LOG.warn("Failed to start Dart analysis server", e);
stopServer();
}
}
}
Aggregations