Search in sources :

Example 1 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk 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 2 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartCoverageProgramRunner method startCollectingCoverage.

private static void startCollectingCoverage(@NotNull final ExecutionEnvironment env, @NotNull final ProcessHandler dartAppProcessHandler, @NotNull final String observatoryUrl) {
    final DartCommandLineRunConfiguration dartRC = (DartCommandLineRunConfiguration) env.getRunProfile();
    final DartCoverageEnabledConfiguration coverageConfiguration = (DartCoverageEnabledConfiguration) CoverageEnabledConfiguration.getOrCreate(dartRC);
    final String coverageFilePath = coverageConfiguration.getCoverageFilePath();
    final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
    LOG.assertTrue(sdk != null);
    final GeneralCommandLine cmdline = new GeneralCommandLine().withExePath(DartSdkUtil.getPubPath(sdk)).withParameters("global", "run", "coverage:collect_coverage", "--uri", observatoryUrl, "--out", coverageFilePath, "--resume-isolates", "--wait-paused");
    try {
        final ProcessHandler coverageProcess = new OSProcessHandler(cmdline);
        coverageProcess.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(@NotNull final ProcessEvent event, @NotNull final Key outputType) {
                LOG.debug(event.getText());
            }
        });
        coverageProcess.startNotify();
        coverageConfiguration.setCoverageProcess(coverageProcess);
        CoverageHelper.attachToProcess(dartRC, dartAppProcessHandler, env.getRunnerSettings());
    } catch (ExecutionException e) {
        LOG.error(e);
    }
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartCommandLineRunConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartCommandLineRunConfiguration) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 3 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartProjectComponent method removeGlobalDartSdkLib.

private void removeGlobalDartSdkLib() {
    for (final Library library : ApplicationLibraryTable.getApplicationTable().getLibraries()) {
        if (DartSdk.DART_SDK_LIB_NAME.equals(library.getName())) {
            final DartSdk oldGlobalSdk = DartSdk.getSdkByLibrary(library);
            if (oldGlobalSdk != null) {
                DartSdkUtil.updateKnownSdkPaths(myProject, oldGlobalSdk.getHomePath());
            }
            ApplicationManager.getApplication().runWriteAction(() -> ApplicationLibraryTable.getApplicationTable().removeLibrary(library));
            return;
        }
    }
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Library(com.intellij.openapi.roots.libraries.Library)

Example 4 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartOutdatedDependenciesInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    if (!isOnTheFly)
        return null;
    if (!(psiFile instanceof DartFile))
        return null;
    if (DartPubActionBase.isInProgress())
        return null;
    final VirtualFile file = DartResolveUtil.getRealVirtualFile(psiFile);
    if (file == null || !file.isInLocalFileSystem())
        return null;
    final Project project = psiFile.getProject();
    if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file))
        return null;
    final DartSdk sdk = DartSdk.getDartSdk(project);
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module == null || sdk == null || !DartSdkLibUtil.isDartSdkEnabled(module))
        return null;
    if (FlutterUtil.isFlutterPluginInstalled() && FlutterUtil.isFlutterModule(module))
        return null;
    final VirtualFile pubspecFile = PubspecYamlUtil.findPubspecYamlFile(project, file);
    if (pubspecFile == null || myIgnoredPubspecPaths.contains(pubspecFile.getPath()))
        return null;
    final String projectName = PubspecYamlUtil.getDartProjectName(pubspecFile);
    // 'pub get' will fail anyway
    if (projectName == null || !StringUtil.isJavaIdentifier(projectName))
        return null;
    final VirtualFile dotPackagesFile = pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
    if (dotPackagesFile == null) {
        return createProblemDescriptors(manager, psiFile, pubspecFile, DartBundle.message("pub.get.never.done"));
    }
    if (FileDocumentManager.getInstance().isFileModified(pubspecFile) || pubspecFile.getTimeStamp() > dotPackagesFile.getTimeStamp()) {
        return createProblemDescriptors(manager, psiFile, pubspecFile, DartBundle.message("pubspec.edited"));
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartFile(com.jetbrains.lang.dart.psi.DartFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartLibraryIndex method getSdkLibByUri.

@Nullable
public static VirtualFile getSdkLibByUri(@NotNull final Project project, @NotNull final String sdkLibUri) {
    final DartSdk sdk = DartSdk.getDartSdk(project);
    final String relativeLibPath = sdk == null ? null : getSdkLibUriToRelativePathMap(project, sdk.getHomePath()).get(sdkLibUri);
    return relativeLibPath == null ? null : LocalFileSystem.getInstance().findFileByPath(sdk.getHomePath() + "/lib/" + relativeLibPath);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)8 Nullable (org.jetbrains.annotations.Nullable)8 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ExecutionException (com.intellij.execution.ExecutionException)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 EvictingQueue (com.google.common.collect.EvictingQueue)2 Lists (com.google.common.collect.Lists)2 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)2 com.google.dart.server (com.google.dart.server)2 AnalysisServer (com.google.dart.server.generated.AnalysisServer)2 DebugPrintStream (com.google.dart.server.internal.remote.DebugPrintStream)2 RemoteAnalysisServerImpl (com.google.dart.server.internal.remote.RemoteAnalysisServerImpl)2 StdioServerSocket (com.google.dart.server.internal.remote.StdioServerSocket)2 Logging (com.google.dart.server.utilities.logging.Logging)2 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)2 Disposable (com.intellij.openapi.Disposable)2