mirror of https://github.com/buggins/dlangide.git
pass project import paths to DCD client
This commit is contained in:
parent
4fa4bd22a6
commit
ebc9ae9d3e
|
@ -56,11 +56,17 @@ class DCDInterface {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultSet goToDefinition(in dstring content, int index) {
|
ResultSet goToDefinition(in string[] importPaths, in dstring content, int index) {
|
||||||
ResultSet result;
|
ResultSet result;
|
||||||
|
|
||||||
string[] arguments = ["-l", "-c"];
|
string[] arguments = ["-l", "-c"];
|
||||||
arguments ~= [to!string(index)];
|
arguments ~= [to!string(index)];
|
||||||
|
foreach(p; importPaths) {
|
||||||
|
arguments ~= "-I";
|
||||||
|
arguments ~= p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
dstring[] output = invokeDcd(arguments, content, success);
|
dstring[] output = invokeDcd(arguments, content, success);
|
||||||
|
@ -93,13 +99,18 @@ class DCDInterface {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultSet getCompletions(in dstring content, int index) {
|
ResultSet getCompletions(in string[] importPaths, in dstring content, int index) {
|
||||||
|
|
||||||
ResultSet result;
|
ResultSet result;
|
||||||
|
|
||||||
string[] arguments = ["-c"];
|
string[] arguments = ["-c"];
|
||||||
arguments ~= [to!string(index)];
|
arguments ~= [to!string(index)];
|
||||||
|
|
||||||
|
foreach(p; importPaths) {
|
||||||
|
arguments ~= "-I";
|
||||||
|
arguments ~= p;
|
||||||
|
}
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
dstring[] output = invokeDcd(arguments, content, success);
|
dstring[] output = invokeDcd(arguments, content, success);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@ import dlangui.core.logger;
|
||||||
|
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
|
||||||
|
// TODO: async operation in background thread
|
||||||
|
// TODO: effective caretPositionToByteOffset/byteOffsetToCaret impl
|
||||||
|
|
||||||
class DEditorTool : EditorTool
|
class DEditorTool : EditorTool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -21,9 +24,9 @@ class DEditorTool : EditorTool
|
||||||
}
|
}
|
||||||
|
|
||||||
override bool goToDefinition(DSourceEdit editor, TextPosition caretPosition) {
|
override bool goToDefinition(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
|
string[] importPaths = editor.importPaths();
|
||||||
auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition);
|
auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition);
|
||||||
ResultSet output = _dcd.goToDefinition(editor.text, byteOffset);
|
ResultSet output = _dcd.goToDefinition(importPaths, editor.text, byteOffset);
|
||||||
|
|
||||||
|
|
||||||
switch(output.result) {
|
switch(output.result) {
|
||||||
|
@ -52,9 +55,10 @@ class DEditorTool : EditorTool
|
||||||
}
|
}
|
||||||
|
|
||||||
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
|
string[] importPaths = editor.importPaths();
|
||||||
|
|
||||||
auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition);
|
auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition);
|
||||||
ResultSet output = _dcd.getCompletions(editor.text, byteOffset);
|
ResultSet output = _dcd.getCompletions(importPaths, editor.text, byteOffset);
|
||||||
switch(output.result) {
|
switch(output.result) {
|
||||||
//TODO: Show dialog
|
//TODO: Show dialog
|
||||||
case DCDResult.FAIL:
|
case DCDResult.FAIL:
|
||||||
|
@ -69,6 +73,7 @@ class DEditorTool : EditorTool
|
||||||
private:
|
private:
|
||||||
DCDInterface _dcd;
|
DCDInterface _dcd;
|
||||||
|
|
||||||
|
// TODO: non-ascii characters support
|
||||||
int caretPositionToByteOffset(dstring content, TextPosition caretPosition) {
|
int caretPositionToByteOffset(dstring content, TextPosition caretPosition) {
|
||||||
auto line = 0;
|
auto line = 0;
|
||||||
auto pos = 0;
|
auto pos = 0;
|
||||||
|
|
|
@ -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
|
/// load by project item
|
||||||
bool load(ProjectSourceFile f) {
|
bool load(ProjectSourceFile f) {
|
||||||
if (!load(f.filename)) {
|
if (!load(f.filename)) {
|
||||||
|
|
Loading…
Reference in New Issue