pass project import paths to DCD client

This commit is contained in:
Vadim Lopatin 2015-02-17 14:09:28 +03:00
parent 4fa4bd22a6
commit ebc9ae9d3e
3 changed files with 29 additions and 6 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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)) {