use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method execution_createContext.
@Nullable
public String execution_createContext(@NotNull final String _filePath) {
final String filePath = FileUtil.toSystemDependentName(_filePath);
final Ref<String> resultRef = new Ref<>();
final AnalysisServer server = myServer;
if (server == null)
return null;
final CountDownLatch latch = new CountDownLatch(1);
server.execution_createContext(filePath, new CreateContextConsumer() {
@Override
public void computedExecutionContext(final String contextId) {
resultRef.set(contextId);
latch.countDown();
}
@Override
public void onError(final RequestError error) {
logError("execution_createContext()", filePath, error);
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, EXECUTION_CREATE_CONTEXT_TIMEOUT);
if (latch.getCount() > 0) {
LOG.info("execution_createContext() took too long for file " + filePath);
}
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method analysis_getNavigation.
@Nullable
public List<DartServerData.DartNavigationRegion> analysis_getNavigation(@NotNull final VirtualFile file, final int _offset, final int length) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final Ref<List<DartServerData.DartNavigationRegion>> resultRef = Ref.create();
final AnalysisServer server = myServer;
if (server == null) {
return null;
}
final CountDownLatch latch = new CountDownLatch(1);
LOG.debug("analysis_getNavigation(" + filePath + ")");
final int offset = getOriginalOffset(file, _offset);
server.analysis_getNavigation(filePath, offset, length, new GetNavigationConsumer() {
@Override
public void computedNavigation(final List<NavigationRegion> regions) {
final List<DartServerData.DartNavigationRegion> dartRegions = new ArrayList<>(regions.size());
for (NavigationRegion region : regions) {
if (region.getLength() > 0) {
dartRegions.add(DartServerData.createDartNavigationRegion(DartAnalysisServerService.this, file, region));
}
}
resultRef.set(dartRegions);
latch.countDown();
}
@Override
public void onError(final RequestError error) {
if (RequestErrorCode.GET_NAVIGATION_INVALID_FILE.equals(error.getCode())) {
LOG.info(getShortErrorMessage("analysis_getNavigation()", filePath, error));
} else {
logError("analysis_getNavigation()", filePath, error);
}
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, GET_NAVIGATION_TIMEOUT);
if (latch.getCount() > 0) {
LOG.info("analysis_getNavigation() took more than " + GET_NAVIGATION_TIMEOUT + "ms for file " + filePath);
}
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method edit_getStatementCompletion.
@Nullable
public SourceChange edit_getStatementCompletion(@NotNull final VirtualFile file, final int _offset) {
final String filePath = FileUtil.toSystemDependentName(file.getPath());
final AnalysisServer server = myServer;
if (server == null) {
return null;
}
final Ref<SourceChange> resultRef = Ref.create();
final CountDownLatch latch = new CountDownLatch(1);
final int offset = getOriginalOffset(file, _offset);
server.edit_getStatementCompletion(filePath, offset, new GetStatementCompletionConsumer() {
@Override
public void computedSourceChange(SourceChange sourceChange) {
resultRef.set(sourceChange);
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, STATEMENT_COMPLETION_TIMEOUT);
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method edit_sortMembers.
@Nullable
public SourceFileEdit edit_sortMembers(@NotNull final String _filePath) {
final String filePath = FileUtil.toSystemDependentName(_filePath);
final Ref<SourceFileEdit> resultRef = new Ref<>();
final AnalysisServer server = myServer;
if (server == null)
return null;
final CountDownLatch latch = new CountDownLatch(1);
server.edit_sortMembers(filePath, new SortMembersConsumer() {
@Override
public void computedEdit(final SourceFileEdit edit) {
resultRef.set(edit);
latch.countDown();
}
@Override
public void onError(final RequestError error) {
if (RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS.equals(error.getCode()) || RequestErrorCode.SORT_MEMBERS_INVALID_FILE.equals(error.getCode())) {
LOG.info(getShortErrorMessage("edit_sortMembers()", filePath, error));
} else {
logError("edit_sortMembers()", filePath, error);
}
latch.countDown();
}
});
awaitForLatchCheckingCanceled(server, latch, EDIT_SORT_MEMBERS_TIMEOUT);
if (latch.getCount() > 0) {
LOG.info("edit_sortMembers() took too long for file " + filePath);
}
return resultRef.get();
}
use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.
the class DartAnalysisServerService method doUpdateFilesContent.
private void doUpdateFilesContent() {
// may be use DocumentListener to collect deltas instead of sending the whole Document.getText() each time?
AnalysisServer server = myServer;
if (server == null) {
return;
}
myUpdateFilesAlarm.cancelAllRequests();
final Map<String, Object> filesToUpdate = new THashMap<>();
ApplicationManager.getApplication().assertReadAccessAllowed();
synchronized (myLock) {
final Set<String> oldTrackedFiles = new THashSet<>(myFilePathWithOverlaidContentToTimestamp.keySet());
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
// some documents in myChangedDocuments may be updated by external change, suxh as switch branch, that's why we track them,
// getUnsavedDocuments() is not enough, we must make sure that overlaid content is sent for for myChangedDocuments as well (to trigger DAS notifications)
final Set<Document> documents = new THashSet<>(myChangedDocuments);
myChangedDocuments.clear();
ContainerUtil.addAll(documents, fileDocumentManager.getUnsavedDocuments());
for (Document document : documents) {
final VirtualFile file = fileDocumentManager.getFile(document);
if (isLocalAnalyzableFile(file)) {
oldTrackedFiles.remove(file.getPath());
final Long oldTimestamp = myFilePathWithOverlaidContentToTimestamp.get(file.getPath());
if (oldTimestamp == null || document.getModificationStamp() != oldTimestamp) {
filesToUpdate.put(FileUtil.toSystemDependentName(file.getPath()), new AddContentOverlay(document.getText()));
myFilePathWithOverlaidContentToTimestamp.put(file.getPath(), document.getModificationStamp());
}
}
}
// oldTrackedFiles at this point contains only those files that are not in FileDocumentManager.getUnsavedDocuments() any more
for (String oldPath : oldTrackedFiles) {
final Long removed = myFilePathWithOverlaidContentToTimestamp.remove(oldPath);
LOG.assertTrue(removed != null, oldPath);
filesToUpdate.put(FileUtil.toSystemDependentName(oldPath), new RemoveContentOverlay());
}
if (LOG.isDebugEnabled()) {
final Set<String> overlaid = new THashSet<>(filesToUpdate.keySet());
for (String removeOverlaid : oldTrackedFiles) {
overlaid.remove(FileUtil.toSystemDependentName(removeOverlaid));
}
if (!overlaid.isEmpty()) {
LOG.debug("Sending overlaid content: " + StringUtil.join(overlaid, ",\n"));
}
if (!oldTrackedFiles.isEmpty()) {
LOG.debug("Removing overlaid content: " + StringUtil.join(oldTrackedFiles, ",\n"));
}
}
}
if (!filesToUpdate.isEmpty()) {
server.analysis_updateContent(filesToUpdate, myServerData::onFilesContentUpdated);
}
}
Aggregations