From ba97194bb334fb34b0fc2c4a3a84d082624a2fd1 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 2 Oct 2017 13:07:10 +0300 Subject: [PATCH] Fix project detection for error location handling #337 --- src/dlangide/ui/frame.d | 21 ++++++----- src/dlangide/ui/outputpanel.d | 56 ++++++------------------------ src/dlangide/ui/wspanel.d | 7 ++-- src/dlangide/workspace/workspace.d | 4 ++- 4 files changed, 32 insertions(+), 56 deletions(-) diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index e15a749..e5fb850 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -171,7 +171,7 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL protected void handleBuildError(int result, Project project) { ErrorPosition err = _logPanel.firstError; 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; } /// - 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; - openSourceFile(to!string(filename)); - - currentEditor().setCaretPos(line, 0); - currentEditor().setCaretPos(line, column); - + 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, column); + } return true; } diff --git a/src/dlangide/ui/outputpanel.d b/src/dlangide/ui/outputpanel.d index d3baa08..feb143b 100644 --- a/src/dlangide/ui/outputpanel.d +++ b/src/dlangide/ui/outputpanel.d @@ -25,14 +25,16 @@ enum ENABLE_INTERNAL_TERMINAL_TEST = false; /// event listener to navigate by error/warning position interface CompilerLogIssueClickHandler { - bool onCompilerLogIssueClick(dstring filename, int line, int column); + bool onCompilerLogIssueClick(dstring projectname, dstring filename, int line, int column); } class ErrorPosition { + dstring projectname; dstring filename; int line; int pos; - this(dstring fn, int l, int p) { + this(dstring pname, dstring fn, int l, int p) { + projectname = pname; filename = fn; line = l; pos = p; @@ -182,14 +184,16 @@ class CompilerLogWidget : LogWidget { if (col < 0) col = 0; } + dstring projectname = findProjectForLine(line).to!dstring; if (filename.startsWith("../") || filename.startsWith("..\\")) { import dlangui.core.types : toUTF8; string fn = filename.toUTF8; resolveRelativePath(fn, line); filename = fn.toUTF32; } - return new ErrorPosition(filename, row, col); + return new ErrorPosition(projectname, filename, row, col); } + return null; } @@ -242,49 +246,11 @@ class CompilerLogWidget : LogWidget { auto errorPos = errorFromLine(_caretPos.line); if (errorPos) { if (compilerLogIssueClickHandler.assigned) { - compilerLogIssueClickHandler(errorPos.filename, errorPos.line, errorPos.pos); + compilerLogIssueClickHandler(errorPos.projectname, errorPos.filename, errorPos.line, errorPos.pos); } } - - 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 false; } - return super.onMouseEvent(event); } } @@ -457,10 +423,10 @@ class OutputPanel : DockWindow { _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) { - compilerLogIssueClickHandler(fn, line, column); + compilerLogIssueClickHandler(projectname, fn, line, column); } return true; diff --git a/src/dlangide/ui/wspanel.d b/src/dlangide/ui/wspanel.d index c011ed9..7741e07 100644 --- a/src/dlangide/ui/wspanel.d +++ b/src/dlangide/ui/wspanel.d @@ -44,6 +44,9 @@ class WorkspacePanel : DockWindow { if (projectItem) { TreeItem item = _tree.findItemById(projectItem.filename); if (item) { + if (item.parent && !item.parent.isFullyExpanded) + item.parent.toggleExpand(); + _tree.makeItemVisible(item); _tree.selectItem(item); return true; } @@ -182,9 +185,9 @@ class WorkspacePanel : DockWindow { return cast(ProjectItem)obj; } - ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true) { + ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true, dstring projectName=null) { if (_workspace) - return _workspace.findSourceFileItem(filename, fullFileName); + return _workspace.findSourceFileItem(filename, fullFileName, projectName); return null; } diff --git a/src/dlangide/workspace/workspace.d b/src/dlangide/workspace/workspace.d index 1ba6b70..f8002e9 100644 --- a/src/dlangide/workspace/workspace.d +++ b/src/dlangide/workspace/workspace.d @@ -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 - ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true) { + ProjectSourceFile findSourceFileItem(string filename, bool fullFileName=true, dstring projectName = null) { foreach (Project p; _projects) { + if (projectName && p.name != projectName) + continue; ProjectSourceFile res = p.findSourceFileItem(filename, fullFileName); if (res) return res;