Search in sources :

Example 11 with AnalysisServer

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();
}
Also used : Ref(com.intellij.openapi.util.Ref) AnalysisServer(com.google.dart.server.generated.AnalysisServer) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with AnalysisServer

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();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AnalysisServer(com.google.dart.server.generated.AnalysisServer) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with AnalysisServer

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();
}
Also used : AnalysisServer(com.google.dart.server.generated.AnalysisServer) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with AnalysisServer

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();
}
Also used : Ref(com.intellij.openapi.util.Ref) AnalysisServer(com.google.dart.server.generated.AnalysisServer) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with AnalysisServer

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) AnalysisServer(com.google.dart.server.generated.AnalysisServer) THashMap(gnu.trove.THashMap)

Aggregations

AnalysisServer (com.google.dart.server.generated.AnalysisServer)19 CountDownLatch (java.util.concurrent.CountDownLatch)15 Nullable (org.jetbrains.annotations.Nullable)9 Ref (com.intellij.openapi.util.Ref)8 NotNull (org.jetbrains.annotations.NotNull)4 Document (com.intellij.openapi.editor.Document)2 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)2 EvictingQueue (com.google.common.collect.EvictingQueue)1 Lists (com.google.common.collect.Lists)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 com.google.dart.server (com.google.dart.server)1 DebugPrintStream (com.google.dart.server.internal.remote.DebugPrintStream)1 RemoteAnalysisServerImpl (com.google.dart.server.internal.remote.RemoteAnalysisServerImpl)1 StdioServerSocket (com.google.dart.server.internal.remote.StdioServerSocket)1 Logging (com.google.dart.server.utilities.logging.Logging)1 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)1 Disposable (com.intellij.openapi.Disposable)1 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ApplicationNamesInfo (com.intellij.openapi.application.ApplicationNamesInfo)1