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());
}
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)));
}
}
}
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();
}
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();
}
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");
}
Aggregations