use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method askForFixesAndWaitABitIfReceivedQuickly.
/**
* If server responds in less than <code>GET_FIXES_TIMEOUT</code> then this method can be considered synchronous: when exiting this method
* <code>consumer</code> is already notified. Otherwise this method is async.
*/
public void askForFixesAndWaitABitIfReceivedQuickly(@NotNull final VirtualFile file, final int _offset, @NotNull final Consumer<List<AnalysisErrorFixes>> consumer) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final AnalysisServer server = myServer;
if (server == null)
return;
final CountDownLatch latch = new CountDownLatch(1);
final int offset = getOriginalOffset(file, _offset);
server.edit_getFixes(filePath, offset, new GetFixesConsumer() {
@Override
public void computedFixes(final List<AnalysisErrorFixes> fixes) {
consumer.consume(fixes);
latch.countDown();
}
@Override
public void onError(final RequestError error) {
logError("edit_getFixes()", filePath, error);
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, GET_FIXES_TIMEOUT);
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method analysis_reanalyze.
public void analysis_reanalyze() {
final AnalysisServer server = myServer;
if (server == null)
return;
server.analysis_reanalyze(null);
ApplicationManager.getApplication().invokeLater(this::clearAllErrors, ModalityState.NON_MODAL);
}
use of com.google.dart.server.generated.AnalysisServer 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();
}
}
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method edit_getAssists.
@NotNull
public List<SourceChange> edit_getAssists(@NotNull final VirtualFile file, final int _offset, final int _length) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final List<SourceChange> results = Lists.newArrayList();
final AnalysisServer server = myServer;
if (server == null) {
return results;
}
final CountDownLatch latch = new CountDownLatch(1);
final int offset = getOriginalOffset(file, _offset);
final int length = getOriginalOffset(file, _offset + _length) - offset;
server.edit_getAssists(filePath, offset, length, new GetAssistsConsumer() {
@Override
public void computedSourceChanges(List<SourceChange> sourceChanges) {
results.addAll(sourceChanges);
latch.countDown();
}
@Override
public void onError(final RequestError error) {
logError("edit_getAssists()", filePath, error);
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, GET_ASSISTS_TIMEOUT);
return results;
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method search_findElementReferences.
public void search_findElementReferences(@NotNull final VirtualFile file, final int _offset, @NotNull final Consumer<SearchResult> consumer) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final Ref<String> searchIdRef = new Ref<>();
final AnalysisServer server = myServer;
if (server == null)
return;
final CountDownLatch latch = new CountDownLatch(1);
final int offset = getOriginalOffset(file, _offset);
server.search_findElementReferences(filePath, offset, true, new FindElementReferencesConsumer() {
@Override
public void computedElementReferences(String searchId, Element element) {
searchIdRef.set(searchId);
latch.countDown();
}
@Override
public void onError(RequestError error) {
LOG.info(getShortErrorMessage("search_findElementReferences()", filePath, error));
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, FIND_ELEMENT_REFERENCES_TIMEOUT);
if (latch.getCount() > 0) {
LOG.info("search_findElementReferences() took too long for " + filePath + "@" + offset);
return;
}
final String searchId = searchIdRef.get();
if (searchId == null) {
return;
}
while (true) {
ProgressManager.checkCanceled();
synchronized (mySearchResultSets) {
SearchResultsSet resultSet;
// process already received results
while ((resultSet = mySearchResultSets.poll()) != null) {
if (!resultSet.id.equals(searchId))
continue;
for (final SearchResult searchResult : resultSet.results) {
consumer.consume(searchResult);
}
if (resultSet.isLast)
return;
}
// wait for more results
try {
mySearchResultSets.wait(CHECK_CANCELLED_PERIOD);
} catch (InterruptedException e) {
return;
}
}
}
}
Aggregations