Search in sources :

Example 1 with DartPubActionBase

use of com.jetbrains.lang.dart.ide.actions.DartPubActionBase 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)

Aggregations

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 AnalysisServer (com.google.dart.server.generated.AnalysisServer)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 ModalityState (com.intellij.openapi.application.ModalityState)1 ServiceManager (com.intellij.openapi.components.ServiceManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1