Search in sources :

Example 6 with AnalysisServer

use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method execution_mapUri.

@Nullable
public String execution_mapUri(@NotNull final String _id, @Nullable final String _filePath, @Nullable final String _uri) {
    // be generated. Similarly, if neither field is provided, then an error of type INVALID_PARAMETER will be generated.
    if ((_filePath == null && _uri == null) || (_filePath != null && _uri != null)) {
        LOG.error("One of _filePath and _uri must be non-null.");
        return null;
    }
    final String filePath = _filePath != null ? FileUtil.toSystemDependentName(_filePath) : null;
    final Ref<String> resultRef = new Ref<>();
    final AnalysisServer server = myServer;
    if (server == null)
        return null;
    final CountDownLatch latch = new CountDownLatch(1);
    server.execution_mapUri(_id, filePath, _uri, new MapUriConsumer() {

        @Override
        public void computedFileOrUri(final String file, final String uri) {
            if (uri != null) {
                resultRef.set(uri);
            } else {
                resultRef.set(file);
            }
            latch.countDown();
        }

        @Override
        public void onError(final RequestError error) {
            LOG.warn("execution_mapUri(" + _id + ", " + filePath + ", " + _uri + ") returned error " + error.getCode() + ": " + error.getMessage());
            latch.countDown();
        }
    });
    awaitForLatchCheckingCanceled(server, latch, EXECUTION_MAP_URI_TIMEOUT);
    if (latch.getCount() > 0) {
        LOG.info("execution_mapUri() took too long for contextID " + _id + " and file or uri " + (filePath != null ? filePath : _uri));
        return null;
    }
    if (_uri != null && !resultRef.isNull()) {
        return FileUtil.toSystemIndependentName(resultRef.get());
    }
    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 7 with AnalysisServer

use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method edit_getRefactoring.

public boolean edit_getRefactoring(String kind, VirtualFile file, int _offset, int _length, boolean validateOnly, RefactoringOptions options, GetRefactoringConsumer consumer) {
    final String filePath = FileUtil.toSystemDependentName(file.getPath());
    final AnalysisServer server = myServer;
    if (server == null)
        return false;
    final int offset = getOriginalOffset(file, _offset);
    final int length = getOriginalOffset(file, _offset + _length) - offset;
    server.edit_getRefactoring(kind, filePath, offset, length, validateOnly, options, consumer);
    return true;
}
Also used : AnalysisServer(com.google.dart.server.generated.AnalysisServer)

Example 8 with AnalysisServer

use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method completion_getSuggestions.

@Nullable
public String completion_getSuggestions(@NotNull final VirtualFile file, final int _offset) {
    final String filePath = FileUtil.toSystemDependentName(file.getPath());
    final Ref<String> resultRef = new Ref<>();
    final AnalysisServer server = myServer;
    if (server == null) {
        return null;
    }
    final CountDownLatch latch = new CountDownLatch(1);
    final int offset = getOriginalOffset(file, _offset);
    server.completion_getSuggestions(filePath, offset, new GetSuggestionsConsumer() {

        @Override
        public void computedCompletionId(@NotNull final String completionId) {
            resultRef.set(completionId);
            latch.countDown();
        }

        @Override
        public void onError(@NotNull final RequestError error) {
            // Not a problem. Happens if a file is outside of the project, or server is just not ready yet.
            latch.countDown();
        }
    });
    awaitForLatchCheckingCanceled(server, latch, GET_SUGGESTIONS_TIMEOUT);
    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 9 with AnalysisServer

use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method edit_format.

@Nullable
public FormatResult edit_format(@NotNull final VirtualFile file, final int _selectionOffset, final int _selectionLength, final int lineLength) {
    final String filePath = FileUtil.toSystemDependentName(file.getPath());
    final Ref<FormatResult> resultRef = new Ref<>();
    final AnalysisServer server = myServer;
    if (server == null)
        return null;
    final CountDownLatch latch = new CountDownLatch(1);
    final int selectionOffset = getOriginalOffset(file, _selectionOffset);
    final int selectionLength = getOriginalOffset(file, _selectionOffset + _selectionLength) - selectionOffset;
    server.edit_format(filePath, selectionOffset, selectionLength, lineLength, new FormatConsumer() {

        @Override
        public void computedFormat(final List<SourceEdit> edits, final int selectionOffset, final int selectionLength) {
            resultRef.set(new FormatResult(edits, selectionOffset, selectionLength));
            latch.countDown();
        }

        @Override
        public void onError(final RequestError error) {
            if (RequestErrorCode.FORMAT_WITH_ERRORS.equals(error.getCode()) || RequestErrorCode.FORMAT_INVALID_FILE.equals(error.getCode())) {
                LOG.info(getShortErrorMessage("edit_format()", filePath, error));
            } else {
                logError("edit_format()", filePath, error);
            }
            latch.countDown();
        }
    });
    awaitForLatchCheckingCanceled(server, latch, EDIT_FORMAT_TIMEOUT);
    if (latch.getCount() > 0) {
        LOG.info("edit_format() 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 10 with AnalysisServer

use of com.google.dart.server.generated.AnalysisServer in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method search_getTypeHierarchy.

@NotNull
public List<TypeHierarchyItem> search_getTypeHierarchy(@NotNull final VirtualFile file, final int _offset, final boolean superOnly) {
    final String filePath = FileUtil.toSystemDependentName(file.getPath());
    final List<TypeHierarchyItem> results = Lists.newArrayList();
    final AnalysisServer server = myServer;
    if (server == null) {
        return results;
    }
    final CountDownLatch latch = new CountDownLatch(1);
    final int offset = getOriginalOffset(file, _offset);
    server.search_getTypeHierarchy(filePath, offset, superOnly, new GetTypeHierarchyConsumer() {

        @Override
        public void computedHierarchy(List<TypeHierarchyItem> hierarchyItems) {
            results.addAll(hierarchyItems);
            latch.countDown();
        }

        @Override
        public void onError(RequestError error) {
            logError("search_getTypeHierarchy()", filePath, error);
            latch.countDown();
        }
    });
    awaitForLatchCheckingCanceled(server, latch, GET_TYPE_HIERARCHY_TIMEOUT);
    return results;
}
Also used : AnalysisServer(com.google.dart.server.generated.AnalysisServer) CountDownLatch(java.util.concurrent.CountDownLatch) NotNull(org.jetbrains.annotations.NotNull)

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