take search scope obtained from run configuration into account to navigate to correct class when user clicks on stacktrace printed in console or log (IDEA-63362)

This commit is contained in:
nik
2013-03-01 17:19:52 +04:00
parent 864210182c
commit 872772ddbc
10 changed files with 93 additions and 43 deletions
@@ -23,10 +23,9 @@ import com.intellij.execution.filters.ExceptionFilters;
import com.intellij.execution.filters.Filter;
import com.intellij.execution.filters.TextConsoleBuilder;
import com.intellij.execution.runners.ProgramRunner;
import com.intellij.openapi.module.Module;
import com.intellij.execution.runners.RunContentBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -58,26 +57,7 @@ public class DefaultDebugEnvironment implements DebugEnvironment {
myRemoteConnection = remoteConnection;
myPollConnection = pollConnection;
mySearchScope = createSearchScope(project, runProfile);
}
@NotNull
public static GlobalSearchScope createSearchScope(Project project, RunProfile runProfile) {
Module[] modules = null;
if (runProfile instanceof ModuleRunProfile) {
modules = ((ModuleRunProfile)runProfile).getModules();
}
if (modules == null || modules.length == 0) {
return GlobalSearchScope.allScope(project);
}
else {
GlobalSearchScope scope = GlobalSearchScope.moduleRuntimeScope(modules[0], true);
for (int idx = 1; idx < modules.length; idx++) {
Module module = modules[idx];
scope = scope.uniteWith(GlobalSearchScope.moduleRuntimeScope(module, true));
}
return scope;
}
mySearchScope = RunContentBuilder.createSearchScope(project, runProfile);
}
@Override
@@ -87,11 +87,9 @@ public class DebuggerSessionTab extends DebuggerSessionTabBase implements Dispos
private final ThreadsPanel myThreadsPanel;
private static final String THREAD_DUMP_CONTENT_PREFIX = "Dump";
public DebuggerSessionTab(final Project project,
final String sessionName,
@NotNull final DebugUIEnvironment environment,
public DebuggerSessionTab(final Project project, final String sessionName, @NotNull final DebugUIEnvironment environment,
@NotNull DebuggerSession debuggerSession) throws ExecutionException {
super(project, "JavaDebugger", sessionName);
super(project, "JavaDebugger", sessionName, debuggerSession.getSearchScope());
myDebuggerSession = debuggerSession;
myDebugUIEnvironment = environment;
@@ -86,10 +86,8 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner {
onProcessStarted(env.getRunnerSettings(), executionResult);
final RunContentBuilder contentBuilder = new RunContentBuilder(project, this, executor);
final RunContentBuilder contentBuilder = new RunContentBuilder(project, this, executor, executionResult, env);
Disposer.register(project, contentBuilder);
contentBuilder.setExecutionResult(executionResult);
contentBuilder.setEnvironment(env);
if (shouldAddDefaultActions) {
addDefaultActions(contentBuilder);
}
@@ -37,6 +37,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.FilterComponent;
import com.intellij.util.Alarm;
import com.intellij.util.containers.ContainerUtil;
@@ -54,7 +55,6 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
/**
@@ -98,7 +98,12 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
private JComboBox myLogFilterCombo;
private JPanel myTextFilterWrapper;
public LogConsoleBase(Project project, @Nullable Reader reader, String title, final boolean buildInActions, LogFilterModel model) {
public LogConsoleBase(@NotNull Project project, @Nullable Reader reader, String title, final boolean buildInActions, LogFilterModel model) {
this(project, reader, title, buildInActions, model, GlobalSearchScope.allScope(project));
}
public LogConsoleBase(@NotNull Project project, @Nullable Reader reader, String title, final boolean buildInActions, LogFilterModel model,
@NotNull GlobalSearchScope scope) {
super(new BorderLayout());
myProject = project;
myTitle = title;
@@ -106,7 +111,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
myFilters = myModel.getLogFilters();
myReaderThread = new ReaderThread(reader);
myBuildInActions = buildInActions;
TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
TextConsoleBuilder builder = TextConsoleBuilderFactory.getInstance().createBuilder(project, scope);
myConsole = builder.getConsole();
myConsole.attachToProcess(myProcessHandler);
myDisposed = false;
@@ -18,6 +18,7 @@ package com.intellij.diagnostic.logging;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,8 +37,27 @@ public abstract class LogConsoleImpl extends LogConsoleBase {
private final Charset myCharset;
private long myOldLength = 0;
public LogConsoleImpl(Project project, @NotNull File file, @NotNull Charset charset, long skippedContents, String title, final boolean buildInActions) {
super(project, getReader(file, charset, skippedContents),title, buildInActions, new DefaultLogFilterModel(project));
/**
* @deprecated use {@link #LogConsoleImpl(com.intellij.openapi.project.Project, java.io.File, java.nio.charset.Charset, long, String, boolean, com.intellij.psi.search.GlobalSearchScope)}
*/
public LogConsoleImpl(Project project,
@NotNull File file,
@NotNull Charset charset,
long skippedContents,
String title,
final boolean buildInActions) {
this(project, file, charset, skippedContents, title, buildInActions, GlobalSearchScope.allScope(project));
}
public LogConsoleImpl(Project project,
@NotNull File file,
@NotNull Charset charset,
long skippedContents,
String title,
final boolean buildInActions,
final GlobalSearchScope searchScope) {
super(project, getReader(file, charset, skippedContents), title, buildInActions, new DefaultLogFilterModel(project),
searchScope);
myPath = file.getAbsolutePath();
myFile = file;
myCharset = charset;
@@ -23,12 +23,12 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComponentWithActions;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManagerAdapter;
import com.intellij.ui.content.ContentManagerEvent;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
@@ -48,9 +48,18 @@ public abstract class LogConsoleManagerBase implements LogConsoleManager, Dispos
private final Map<AdditionalTabComponent, Content> myAdditionalContent = new HashMap<AdditionalTabComponent, Content>();
private ExecutionEnvironment myEnvironment;
private GlobalSearchScope mySearchScope;
/**
* @deprecated use {@link #LogConsoleManagerBase(com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope)}
*/
protected LogConsoleManagerBase(@NotNull Project project) {
this(project, GlobalSearchScope.allScope(project));
}
protected LogConsoleManagerBase(@NotNull Project project, @NotNull GlobalSearchScope searchScope) {
myProject = project;
mySearchScope = searchScope;
}
protected final Project getProject() {
@@ -71,7 +80,7 @@ public abstract class LogConsoleManagerBase implements LogConsoleManager, Dispos
}
public void addLogConsole(final String name, final String path, @NotNull Charset charset, final long skippedContent, Icon icon) {
doAddLogConsole(new LogConsoleImpl(myProject, new File(path), charset, skippedContent, name, false) {
doAddLogConsole(new LogConsoleImpl(myProject, new File(path), charset, skippedContent, name, false, mySearchScope) {
@Override
public boolean isActive() {
@@ -90,7 +99,7 @@ public abstract class LogConsoleManagerBase implements LogConsoleManager, Dispos
reader,
name,
false,
new DefaultLogFilterModel(myProject)) {
new DefaultLogFilterModel(myProject), mySearchScope) {
@Override
public boolean isActive() {
@@ -35,9 +35,7 @@ public abstract class DefaultProgramRunner extends GenericProgramRunner {
ExecutionResult executionResult = state.execute(executor, this);
if (executionResult == null) return null;
final RunContentBuilder contentBuilder = new RunContentBuilder(project, this, executor);
contentBuilder.setExecutionResult(executionResult);
contentBuilder.setEnvironment(env);
final RunContentBuilder contentBuilder = new RunContentBuilder(project, this, executor, executionResult, env);
return contentBuilder.showRunContent(contentToReuse);
}
@@ -19,6 +19,7 @@ import com.intellij.diagnostic.logging.LogConsoleManagerBase;
import com.intellij.diagnostic.logging.LogFilesManager;
import com.intellij.diagnostic.logging.OutputFileUtil;
import com.intellij.execution.*;
import com.intellij.execution.configurations.ModuleRunProfile;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.configurations.RunProfile;
import com.intellij.execution.impl.ConsoleViewImpl;
@@ -31,8 +32,10 @@ import com.intellij.ide.actions.ContextHelpAction;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.tabs.PinToolwindowTabAction;
import org.jetbrains.annotations.NonNls;
@@ -57,6 +60,22 @@ public class RunContentBuilder extends LogConsoleManagerBase {
private RunnerLayoutUi myUi;
private final Executor myExecutor;
public RunContentBuilder(@NotNull Project project,
ProgramRunner runner,
Executor executor,
ExecutionResult executionResult,
@NotNull ExecutionEnvironment environment) {
super(project, createSearchScope(project, environment.getRunProfile()));
myRunner = runner;
myExecutor = executor;
myManager = new LogFilesManager(project, this, this);
myExecutionResult = executionResult;
setEnvironment(environment);
}
/**
* @deprecated use {@link #RunContentBuilder(com.intellij.openapi.project.Project, ProgramRunner, com.intellij.execution.Executor, com.intellij.execution.ExecutionResult, ExecutionEnvironment)}
*/
public RunContentBuilder(final Project project, final ProgramRunner runner, Executor executor) {
super(project);
myRunner = runner;
@@ -64,10 +83,30 @@ public class RunContentBuilder extends LogConsoleManagerBase {
myManager = new LogFilesManager(project, this, this);
}
@NotNull
public static GlobalSearchScope createSearchScope(Project project, RunProfile runProfile) {
Module[] modules = null;
if (runProfile instanceof ModuleRunProfile) {
modules = ((ModuleRunProfile)runProfile).getModules();
}
if (modules == null || modules.length == 0) {
return GlobalSearchScope.allScope(project);
}
else {
GlobalSearchScope scope = GlobalSearchScope.moduleRuntimeScope(modules[0], true);
for (int idx = 1; idx < modules.length; idx++) {
Module module = modules[idx];
scope = scope.uniteWith(GlobalSearchScope.moduleRuntimeScope(module, true));
}
return scope;
}
}
public ExecutionResult getExecutionResult() {
return myExecutionResult;
}
@Deprecated
public void setExecutionResult(final ExecutionResult executionResult) {
myExecutionResult = executionResult;
}
@@ -35,6 +35,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.AppIcon;
import com.intellij.ui.content.Content;
import com.intellij.xdebugger.XDebuggerBundle;
@@ -56,8 +57,9 @@ public abstract class DebuggerSessionTabBase extends LogConsoleManagerBase imple
protected ExecutionConsole myConsole;
protected RunContentDescriptor myRunContentDescriptor;
public DebuggerSessionTabBase(Project project, @NotNull String runnerId, @NotNull final String sessionName) {
super(project);
public DebuggerSessionTabBase(@NotNull Project project, @NotNull String runnerId, @NotNull final String sessionName,
@NotNull GlobalSearchScope searchScope) {
super(project, searchScope);
Disposer.register(project, this);
myManager = new LogFilesManager(project, this, this);
@@ -33,6 +33,7 @@ import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.tabs.PinToolwindowTabAction;
import com.intellij.xdebugger.XDebugProcess;
@@ -61,7 +62,7 @@ public class XDebugSessionTab extends DebuggerSessionTabBase {
public XDebugSessionTab(@NotNull final Project project, @NotNull final XDebugSessionImpl session, final @Nullable Icon icon,
ExecutionEnvironment environment, ProgramRunner runner) {
super(project, "Debug", session.getSessionName());
super(project, "Debug", session.getSessionName(), GlobalSearchScope.allScope(project));
if (environment != null) {
setEnvironment(environment);
}