mirror of https://github.com/buggins/dlangide.git
Cleaned up Show completions
This commit is contained in:
parent
747cb61fee
commit
158d1f1442
|
@ -72,6 +72,60 @@ class DCDInterface {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultSet getCompletions(in dstring content, int index) {
|
||||||
|
ExternalProcess dcdProcess = new ExternalProcess();
|
||||||
|
|
||||||
|
ResultSet result;
|
||||||
|
if(dcdProcess.state != ExternalProcessState.None) {
|
||||||
|
result.result = DCDResult.FAIL;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
char[][] arguments = ["-c".dup];
|
||||||
|
arguments ~= [to!(char[])(index)];
|
||||||
|
ProtectedTextStorage stdoutTarget = new ProtectedTextStorage();
|
||||||
|
|
||||||
|
dcdProcess.run("dcd-client".dup, arguments, "/usr/bin".dup, stdoutTarget);
|
||||||
|
dcdProcess.write(content);
|
||||||
|
dcdProcess.wait();
|
||||||
|
|
||||||
|
dstring[] output = stdoutTarget.readText.splitLines();
|
||||||
|
|
||||||
|
if(dcdProcess.poll() == ExternalProcessState.Stopped) {
|
||||||
|
result.result = DCDResult.SUCCESS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.result = DCDResult.FAIL;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(output.length == 0) {
|
||||||
|
result.result = DCDResult.NO_RESULT;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum State : int {None = 0, Identifiers, Calltips}
|
||||||
|
State state = State.None;
|
||||||
|
foreach(dstring outputLine ; output) {
|
||||||
|
if(outputLine == "identifiers") {
|
||||||
|
state = State.Identifiers;
|
||||||
|
}
|
||||||
|
else if(outputLine == "calltips") {
|
||||||
|
state = State.Calltips;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto split = outputLine.indexOf("\t");
|
||||||
|
if(split < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(state == State.Identifiers) {
|
||||||
|
result.output ~= outputLine[0 .. split];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool execute(char[][] arguments ,ref dstring output, dstring input) {
|
bool execute(char[][] arguments ,ref dstring output, dstring input) {
|
||||||
//TODO: Working Directory, where is that?
|
//TODO: Working Directory, where is that?
|
||||||
//TODO: Inform user when dcd-client is not available.
|
//TODO: Inform user when dcd-client is not available.
|
||||||
|
|
|
@ -52,39 +52,20 @@ class DEditorTool : EditorTool
|
||||||
}
|
}
|
||||||
|
|
||||||
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
auto content = editor.text();
|
|
||||||
auto byteOffset = caretPositionToByteOffset(content, caretPosition);
|
|
||||||
|
|
||||||
char[][] arguments = ["-c".dup];
|
auto byteOffset = caretPositionToByteOffset(editor.text, caretPosition);
|
||||||
arguments ~= [to!(char[])(byteOffset)];
|
ResultSet output = _dcd.getCompletions(editor.text, byteOffset);
|
||||||
//arguments ~= [to!(char[])(editor.projectSourceFile.filename())];
|
switch(output.result) {
|
||||||
|
//TODO: Show dialog
|
||||||
dstring output;
|
case DCDResult.FAIL:
|
||||||
_dcd.execute(arguments, output, content);
|
case DCDResult.DCD_NOT_RUNNING:
|
||||||
|
case DCDResult.NO_RESULT:
|
||||||
char[] state = "".dup;
|
case DCDResult.SUCCESS:
|
||||||
dstring[] suggestions;
|
default:
|
||||||
foreach(dstring outputLine ; output.splitLines()) {
|
return output.output;
|
||||||
if(outputLine == "identifiers") {
|
|
||||||
state = "identifiers".dup;
|
|
||||||
}
|
|
||||||
else if(outputLine == "calltips") {
|
|
||||||
state = "calltips".dup;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
auto split = outputLine.indexOf("\t");
|
|
||||||
if(split < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(state == "identifiers") {
|
|
||||||
suggestions ~= outputLine[0 .. split];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return suggestions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DCDInterface _dcd;
|
DCDInterface _dcd;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue