Search in sources :

Example 1 with AnalysisServer

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

Example 2 with AnalysisServer

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);
}
Also used : AnalysisServer(com.google.dart.server.generated.AnalysisServer)

Example 3 with AnalysisServer

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();
        }
    }
}
Also used : DartFileType(com.jetbrains.lang.dart.DartFileType) UIUtil(com.intellij.util.ui.UIUtil) HtmlUtil(com.intellij.xml.util.HtmlUtil) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Logging(com.google.dart.server.utilities.logging.Logging) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) THashMap(gnu.trove.THashMap) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) Library(com.intellij.openapi.roots.libraries.Library) Task(com.intellij.openapi.progress.Task) DartProblemsView(com.jetbrains.lang.dart.ide.errorTreeView.DartProblemsView) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) org.dartlang.analysis.server.protocol(org.dartlang.analysis.server.protocol) DebugPrintStream(com.google.dart.server.internal.remote.DebugPrintStream) DartSdkUpdateChecker(com.jetbrains.lang.dart.sdk.DartSdkUpdateChecker) RemoteAnalysisServerImpl(com.google.dart.server.internal.remote.RemoteAnalysisServerImpl) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) DartYamlFileTypeFactory(com.jetbrains.lang.dart.DartYamlFileTypeFactory) AnalysisServer(com.google.dart.server.generated.AnalysisServer) DartSdkUtil(com.jetbrains.lang.dart.sdk.DartSdkUtil) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) DartBundle(com.jetbrains.lang.dart.DartBundle) Nullable(org.jetbrains.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Contract(org.jetbrains.annotations.Contract) ServiceManager(com.intellij.openapi.components.ServiceManager) DartPubActionBase(com.jetbrains.lang.dart.ide.actions.DartPubActionBase) EditorFactory(com.intellij.openapi.editor.EditorFactory) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Consumer(com.intellij.util.Consumer) DartFileListener(com.jetbrains.lang.dart.DartFileListener) com.google.dart.server(com.google.dart.server) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) java.util(java.util) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) StdioServerSocket(com.google.dart.server.internal.remote.StdioServerSocket) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) DartQuickAssistIntention(com.jetbrains.lang.dart.assists.DartQuickAssistIntention) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Lists(com.google.common.collect.Lists) Comparing(com.intellij.openapi.util.Comparing) EvictingQueue(com.google.common.collect.EvictingQueue) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) DartSdkLibUtil(com.jetbrains.lang.dart.sdk.DartSdkLibUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Disposable(com.intellij.openapi.Disposable) File(java.io.File) DartFeedbackBuilder(com.jetbrains.lang.dart.ide.errorTreeView.DartFeedbackBuilder) TimeUnit(java.util.concurrent.TimeUnit) PubspecYamlUtil(com.jetbrains.lang.dart.util.PubspecYamlUtil) QuickAssistSet(com.jetbrains.lang.dart.assists.QuickAssistSet) Condition(com.intellij.openapi.util.Condition) DebugPrintStream(com.google.dart.server.internal.remote.DebugPrintStream) AnalysisServer(com.google.dart.server.generated.AnalysisServer) RemoteAnalysisServerImpl(com.google.dart.server.internal.remote.RemoteAnalysisServerImpl) StdioServerSocket(com.google.dart.server.internal.remote.StdioServerSocket) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 4 with AnalysisServer

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

Example 5 with AnalysisServer

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

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