diff --git a/src/dlangide/tools/d/dcdinterface.d b/src/dlangide/tools/d/dcdinterface.d index c7d33d0..ff34394 100644 --- a/src/dlangide/tools/d/dcdinterface.d +++ b/src/dlangide/tools/d/dcdinterface.d @@ -56,11 +56,17 @@ class DCDInterface { return output; } - ResultSet goToDefinition(in dstring content, int index) { + ResultSet goToDefinition(in string[] importPaths, in dstring content, int index) { ResultSet result; - + string[] arguments = ["-l", "-c"]; arguments ~= [to!string(index)]; + foreach(p; importPaths) { + arguments ~= "-I"; + arguments ~= p; + } + + bool success = false; dstring[] output = invokeDcd(arguments, content, success); @@ -93,13 +99,18 @@ class DCDInterface { return result; } - ResultSet getCompletions(in dstring content, int index) { + ResultSet getCompletions(in string[] importPaths, in dstring content, int index) { ResultSet result; string[] arguments = ["-c"]; arguments ~= [to!string(index)]; + foreach(p; importPaths) { + arguments ~= "-I"; + arguments ~= p; + } + bool success = false; dstring[] output = invokeDcd(arguments, content, success); diff --git a/src/dlangide/tools/d/deditortool.d b/src/dlangide/tools/d/deditortool.d index 2a14d6d..eb3ca66 100644 --- a/src/dlangide/tools/d/deditortool.d +++ b/src/dlangide/tools/d/deditortool.d @@ -11,6 +11,9 @@ import dlangui.core.logger; import std.conv; +// TODO: async operation in background thread +// TODO: effective caretPositionToByteOffset/byteOffsetToCaret impl + class DEditorTool : EditorTool { @@ -21,9 +24,9 @@ class DEditorTool : EditorTool } override bool goToDefinition(DSourceEdit editor, TextPosition caretPosition) { - + string[] importPaths = editor.importPaths(); auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition); - ResultSet output = _dcd.goToDefinition(editor.text, byteOffset); + ResultSet output = _dcd.goToDefinition(importPaths, editor.text, byteOffset); switch(output.result) { @@ -52,9 +55,10 @@ class DEditorTool : EditorTool } override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) { + string[] importPaths = editor.importPaths(); auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition); - ResultSet output = _dcd.getCompletions(editor.text, byteOffset); + ResultSet output = _dcd.getCompletions(importPaths, editor.text, byteOffset); switch(output.result) { //TODO: Show dialog case DCDResult.FAIL: @@ -69,6 +73,7 @@ class DEditorTool : EditorTool private: DCDInterface _dcd; + // TODO: non-ascii characters support int caretPositionToByteOffset(dstring content, TextPosition caretPosition) { auto line = 0; auto pos = 0; diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index fbd85c1..891561c 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -58,6 +58,13 @@ class DSourceEdit : SourceEdit { } } + /// returns project import paths - if file from project is opened in current editor + string[] importPaths() { + if (_projectSourceFile) + return _projectSourceFile.project.sourcePaths; + return null; + } + /// load by project item bool load(ProjectSourceFile f) { if (!load(f.filename)) {