Search in sources :

Example 6 with DartSdk

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

the class DartResolveScopeProvider method getDartScope.

/**
   * @param strict Strict scope respects <a href="https://www.dartlang.org/tools/pub/package-layout.html">Dart Package Layout Conventions</a>,
   *               not strict includes the whole Dart project and Path Packages it depends on.
   *               But both strict and not strict scope for file in 'packages' folder includes only 'packages', 'lib' and Path Packages folders.
   */
@Nullable
public static GlobalSearchScope getDartScope(@NotNull final Project project, @NotNull final VirtualFile file, boolean strict) {
    if (file.getFileType() != DartFileType.INSTANCE)
        return null;
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (fileIndex.isInLibraryClasses(file) && !fileIndex.isInContent(file)) {
        if (sdk != null && file.getPath().startsWith(sdk.getHomePath() + "/")) {
            return getDartSdkResolveScope(project);
        }
        return getLibraryAndSdkScope(project, file, sdk);
    }
    final Module module = fileIndex.getModuleForFile(file);
    if (module == null) {
        return null;
    }
    VirtualFile contextSubdir = null;
    VirtualFile dir = file.getParent();
    while (dir != null && fileIndex.isInContent(dir)) {
        final VirtualFile pubspecFile = dir.findChild(PubspecYamlUtil.PUBSPEC_YAML);
        if (pubspecFile != null) {
            final boolean inPackages = contextSubdir != null && PACKAGES_FOLDER_NAME.equals(contextSubdir.getName());
            return getDartResolveScope(module, pubspecFile, strict || inPackages ? contextSubdir : null);
        }
        contextSubdir = dir;
        dir = dir.getParent();
    }
    // no pubspec.yaml => return module content scope + libs + SDK
    return module.getModuleContentWithDependenciesScope().union(module.getModuleWithLibrariesScope());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with DartSdk

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

the class DartCommandLineRunnerParameters method check.

public void check(@NotNull final Project project) throws RuntimeConfigurationError {
    // check sdk
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null) {
        throw new RuntimeConfigurationError(DartBundle.message("dart.sdk.is.not.configured"), () -> DartConfigurable.openDartSettings(project));
    }
    // check main dart file
    getDartFileOrDirectory();
    // check working directory
    if (!StringUtil.isEmptyOrSpaces(myWorkingDirectory)) {
        final VirtualFile workDir = LocalFileSystem.getInstance().findFileByPath(myWorkingDirectory);
        if (workDir == null || !workDir.isDirectory()) {
            throw new RuntimeConfigurationError(DartBundle.message("work.dir.does.not.exist", FileUtil.toSystemDependentName(myWorkingDirectory)));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 8 with DartSdk

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

the class DartRunner method doExecuteDartDebug.

private RunContentDescriptor doExecuteDartDebug(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env, @Nullable final String dasExecutionContextId) throws RuntimeConfigurationError, ExecutionException {
    final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
    // already checked
    assert (sdk != null);
    final RunProfile runConfiguration = env.getRunProfile();
    final VirtualFile contextFileOrDir;
    VirtualFile currentWorkingDirectory;
    final ExecutionResult executionResult;
    final String debuggingHost;
    final int observatoryPort;
    if (runConfiguration instanceof DartRunConfigurationBase) {
        contextFileOrDir = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().getDartFileOrDirectory();
        final String cwd = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().computeProcessWorkingDirectory(env.getProject());
        currentWorkingDirectory = LocalFileSystem.getInstance().findFileByPath((cwd));
        executionResult = state.execute(env.getExecutor(), this);
        if (executionResult == null) {
            return null;
        }
        debuggingHost = null;
        observatoryPort = ((DartCommandLineRunningState) state).getObservatoryPort();
    } else if (runConfiguration instanceof DartRemoteDebugConfiguration) {
        final String path = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getDartProjectPath();
        contextFileOrDir = LocalFileSystem.getInstance().findFileByPath(path);
        if (contextFileOrDir == null) {
            throw new RuntimeConfigurationError("Folder not found: " + FileUtil.toSystemDependentName(path));
        }
        currentWorkingDirectory = contextFileOrDir;
        executionResult = null;
        debuggingHost = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getHost();
        observatoryPort = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getPort();
    } else {
        LOG.error("Unexpected run configuration: " + runConfiguration.getClass().getName());
        return null;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    final XDebuggerManager debuggerManager = XDebuggerManager.getInstance(env.getProject());
    final XDebugSession debugSession = debuggerManager.startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            final DartUrlResolver dartUrlResolver = getDartUrlResolver(env.getProject(), contextFileOrDir);
            return new DartVmServiceDebugProcess(session, StringUtil.notNullize(debuggingHost, "localhost"), observatoryPort, executionResult, dartUrlResolver, dasExecutionContextId, runConfiguration instanceof DartRemoteDebugConfiguration, getTimeout(), currentWorkingDirectory);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) NotNull(org.jetbrains.annotations.NotNull) DartVmServiceDebugProcess(com.jetbrains.lang.dart.ide.runner.server.vmService.DartVmServiceDebugProcess) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartRemoteDebugConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 9 with DartSdk

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

the class DartServerExtractLocalVariableDialog method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null || StringUtil.compareVersionNumbers(sdk.getVersion(), "1.14") < 0) {
        new DartIntroduceVariableHandler().invoke(project, editor, file, dataContext);
        return;
    }
    if (editor == null || file == null) {
        return;
    }
    if (!CommonRefactoringUtil.checkReadOnlyStatus(file)) {
        return;
    }
    new ExtractLocalVariableProcessor(project, editor, file).perform();
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk)

Example 10 with DartSdk

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

the class DartGotoImplementationTest method testIterableSubclasses.

public void testIterableSubclasses() throws Throwable {
    myFixture.configureByText("foo.dart", "");
    myFixture.doHighlighting();
    final DartSdk sdk = DartSdk.getDartSdk(getProject());
    assertNotNull(sdk);
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "set.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "string.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "list.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "iterable.dart");
    final DartClass iterableClass = PsiTreeUtil.findChildOfType(getFile(), DartClass.class);
    assertNotNull(iterableClass);
    assertEquals("Iterable", iterableClass.getName());
    getEditor().getCaretModel().moveToOffset(iterableClass.getTextOffset());
    final GotoTargetHandler.GotoData data = CodeInsightTestUtil.gotoImplementation(myFixture.getEditor(), myFixture.getFile());
    final List<String> actual = ContainerUtil.map(data.targets, psiElement -> psiElement instanceof PsiNamedElement ? ((PsiNamedElement) psiElement).getName() : psiElement.toString());
    // only subclasses from dart:core are known to analyzer at this point
    assertSameElements(actual, "List", "Set", "Runes");
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartClass(com.jetbrains.lang.dart.psi.DartClass) GotoTargetHandler(com.intellij.codeInsight.navigation.GotoTargetHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement)

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