Fix project detection for error location handling #337

This commit is contained in:
Vadim Lopatin 2017-10-02 13:07:10 +03:00
parent 325915097a
commit ba97194bb3
4 changed files with 32 additions and 56 deletions

View File

@ -171,7 +171,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
protected void handleBuildError(int result, Project project) { protected void handleBuildError(int result, Project project) {
ErrorPosition err = _logPanel.firstError; ErrorPosition err = _logPanel.firstError;
if (err) { if (err) {
onCompilerLogIssueClick(err.filename, err.line, err.pos); onCompilerLogIssueClick(err.projectname, err.filename, err.line, err.pos);
} }
} }
@ -387,16 +387,21 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
@property IDESettings settings() { return _settings; } @property IDESettings settings() { return _settings; }
/// ///
bool onCompilerLogIssueClick(dstring filename, int line, int column) bool onCompilerLogIssueClick(dstring projectname, dstring filename, int line, int column)
{ {
Log.d("onCompilerLogIssueClick ", filename); Log.d("onCompilerLogIssueClick project=", projectname, " file=", filename, " line=", line, " column=", column);
import std.conv:to; import std.conv:to;
openSourceFile(to!string(filename)); string fname = to!string(filename);
//import std.path : isAbsolute;
ProjectSourceFile sourceFile = _wsPanel.findSourceFileItem(fname, isAbsolute(fname) ? true : false, projectname);
if (openSourceFile(fname, sourceFile)) {
Log.d("found source file");
if (sourceFile)
_wsPanel.selectItem(sourceFile);
currentEditor().setCaretPos(line, 0); currentEditor().setCaretPos(line, 0);
currentEditor().setCaretPos(line, column); currentEditor().setCaretPos(line, column);
}
return true; return true;
} }

View File

@ -25,14 +25,16 @@ enum ENABLE_INTERNAL_TERMINAL_TEST = false;
/// event listener to navigate by error/warning position /// event listener to navigate by error/warning position
interface CompilerLogIssueClickHandler { interface CompilerLogIssueClickHandler {
bool onCompilerLogIssueClick(dstring filename, int line, int column); bool onCompilerLogIssueClick(dstring projectname, dstring filename, int line, int column);
} }
class ErrorPosition { class ErrorPosition {
dstring projectname;
dstring filename; dstring filename;
int line; int line;
int pos; int pos;
this(dstring fn, int l, int p) { this(dstring pname, dstring fn, int l, int p) {
projectname = pname;
filename = fn; filename = fn;
line = l; line = l;
pos = p; pos = p;
@ -182,14 +184,16 @@ class CompilerLogWidget : LogWidget {
if (col < 0) if (col < 0)
col = 0; col = 0;
} }
dstring projectname = findProjectForLine(line).to!dstring;
if (filename.startsWith("../") || filename.startsWith("..\\")) { if (filename.startsWith("../") || filename.startsWith("..\\")) {
import dlangui.core.types : toUTF8; import dlangui.core.types : toUTF8;
string fn = filename.toUTF8; string fn = filename.toUTF8;
resolveRelativePath(fn, line); resolveRelativePath(fn, line);
filename = fn.toUTF32; filename = fn.toUTF32;
} }
return new ErrorPosition(filename, row, col); return new ErrorPosition(projectname, filename, row, col);
} }
return null; return null;
} }
@ -242,49 +246,11 @@ class CompilerLogWidget : LogWidget {
auto errorPos = errorFromLine(_caretPos.line); auto errorPos = errorFromLine(_caretPos.line);
if (errorPos) { if (errorPos) {
if (compilerLogIssueClickHandler.assigned) { if (compilerLogIssueClickHandler.assigned) {
compilerLogIssueClickHandler(errorPos.filename, errorPos.line, errorPos.pos); compilerLogIssueClickHandler(errorPos.projectname, errorPos.filename, errorPos.line, errorPos.pos);
} }
} }
return false;
auto logLine = this.content.line(this._caretPos.line);
//src\tetris.d(49): Error: found 'return' when expecting ';' following statement
auto match = matchFirst(logLine, ctr);
if(!match.empty) {
if (compilerLogIssueClickHandler.assigned) {
import std.conv:to;
int row = 0;
try {
row = to!int(match[2]) - 1;
} catch (Exception e) {
row = 0;
} }
if (row < 0)
row = 0;
int col = 0;
if (match[3]) {
try {
col = to!int(match[3]) - 1;
} catch (Exception e) {
col = 0;
}
if (col < 0)
col = 0;
}
import dlangui.core.types : toUTF8;
string filename = match[1].toUTF8;
if (filename.startsWith("../") || filename.startsWith("..\\")) {
resolveRelativePath(filename, _caretPos.line);
}
compilerLogIssueClickHandler(filename.toUTF32, row, col);
}
}
return true;
}
return super.onMouseEvent(event); return super.onMouseEvent(event);
} }
} }
@ -457,10 +423,10 @@ class OutputPanel : DockWindow {
_logWidget.text = ""d; _logWidget.text = ""d;
} }
private bool onIssueClick(dstring fn, int line, int column) private bool onIssueClick(dstring projectname, dstring fn, int line, int column)
{ {
if (compilerLogIssueClickHandler.assigned) { if (compilerLogIssueClickHandler.assigned) {
compilerLogIssueClickHandler(fn, line, column); compilerLogIssueClickHandler(projectname, fn, line, column);
} }
return true; return true;

View File

@ -44,6 +44,9 @@ class WorkspacePanel : DockWindow {
if (projectItem) { if (projectItem) {
TreeItem item = _tree.findItemById(projectItem.filename); TreeItem item = _tree.findItemById(projectItem.filename);
if (item) { if (item) {
if (item.parent && !item.parent.isFullyExpanded)
item.parent.toggleExpand();
_tree.makeItemVisible(item);
_tree.selectItem(item); _tree.selectItem(item);
return true; return true;
} }
@ -182,9 +185,9 @@ class WorkspacePanel : DockWindow {
return cast(ProjectItem)obj; return cast(ProjectItem)obj;
} }
ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true) { ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true, dstring projectName=null) {
if (_workspace) if (_workspace)
return _workspace.findSourceFileItem(filename, fullFileName); return _workspace.findSourceFileItem(filename, fullFileName, projectName);
return null; return null;
} }

View File

@ -198,8 +198,10 @@ class Workspace : WorkspaceItem {
} }
/// tries to find source file in one of projects, returns found project source file item, or null if not found /// tries to find source file in one of projects, returns found project source file item, or null if not found
ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true) { ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true, dstring projectName = null) {
foreach (Project p; _projects) { foreach (Project p; _projects) {
if (projectName && p.name != projectName)
continue;
ProjectSourceFile res = p.findSourceFileItem(filename, fullFileName); ProjectSourceFile res = p.findSourceFileItem(filename, fullFileName);
if (res) if (res)
return res; return res;