This commit is contained in:
Vadim Lopatin 2017-09-22 14:21:51 +03:00
parent 732044c229
commit ce26caa73e
5 changed files with 41 additions and 15 deletions

View File

@ -35,9 +35,11 @@ struct CompletionSymbol {
char kind;
}
import dlangide.tools.editortool : CompletionTypes;
alias DocCommentsResultSet = Tuple!(DCDResult, "result", string[], "docComments");
alias FindDeclarationResultSet = Tuple!(DCDResult, "result", string, "fileName", ulong, "offset");
alias CompletionResultSet = Tuple!(DCDResult, "result", CompletionSymbol[], "output");
alias CompletionResultSet = Tuple!(DCDResult, "result", CompletionSymbol[], "output", CompletionTypes, "type");
class DCDTask {
@ -315,7 +317,12 @@ class DCDInterface : Thread {
result.output[i].name = to!dstring(s);
i++;
}
postProcessCompletions(result.output);
if (response.completionType == "calltips") {
result.type = CompletionTypes.CallTips;
} else {
result.type = CompletionTypes.IdentifierList;
postProcessCompletions(result.output);
}
debug(DCD) Log.d("DCD response:\n", response, "\nCompletion result:\n", result.output);
}
override void postResults() {

View File

@ -1,6 +1,6 @@
module dlangide.tools.d.deditorTool;
module dlangide.tools.d.deditortool;
import dlangide.tools.editorTool;
import dlangide.tools.editortool;
import dlangide.tools.d.dcdinterface;
import dlangide.ui.dsourceedit;
import dlangui.widgets.editors;
@ -127,7 +127,7 @@ class DEditorTool : EditorTool
}
DCDTask _getCompletionsTask;
override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] completions, string[] icons) callback) {
override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] completions, string[] icons, CompletionTypes type) callback) {
cancelGetCompletions();
string[] importPaths = editor.importPaths();
@ -198,7 +198,7 @@ class DEditorTool : EditorTool
icons ~= iconId;
labels ~= label.name;
}
callback(labels, icons);
callback(labels, icons, output.type);
_getCompletionsTask = null;
});
}

View File

@ -1,4 +1,4 @@
module dlangide.tools.editorTool;
module dlangide.tools.editortool;
@ -7,7 +7,12 @@ import dlangui.core.types;
import dlangide.ui.frame;
import dlangide.ui.dsourceedit;
public import dlangide.tools.d.deditorTool;
public import dlangide.tools.d.deditortool;
enum CompletionTypes : int {
IdentifierList,
CallTips,
}
class EditorTool
{
@ -17,7 +22,7 @@ class EditorTool
//Since files might be unsaved, we must send all the text content.
abstract void goToDefinition(DSourceEdit editor, TextPosition caretPosition);
abstract void getDocComments(DSourceEdit editor, TextPosition caretPosition, void delegate(string[]) callback);
abstract void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] labels, string[] icons) callback);
abstract void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] labels, string[] icons, CompletionTypes type) callback);
void cancelGoToDefinition() {}
void cancelGetDocComments() {}
@ -37,7 +42,7 @@ class DefaultEditorTool : EditorTool
//assert(0); //Go To Definition should not be called for normal files.
}
override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] labels, string[] icons) callback) {
override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] labels, string[] icons, CompletionTypes type) callback) {
//assert(0);
}

View File

@ -21,7 +21,7 @@ import dlangide.workspace.project;
import dlangide.ui.commands;
import dlangide.ui.settings;
import dlangide.tools.d.dsyntax;
import dlangide.tools.editorTool;
import dlangide.tools.editortool;
import ddebug.common.debugger;
import std.algorithm;
@ -619,13 +619,27 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener {
_completionPopupMenu = null;
}
void showCompletionPopup(dstring[] suggestions, string[] icons) {
void showCallTipsPopup(dstring[] suggestions) {
// TODO: replace this temp solution
string[] list;
foreach(s; suggestions) {
list ~= s.toUTF8;
}
showDocCommentsPopup(list);
}
void showCompletionPopup(dstring[] suggestions, string[] icons, CompletionTypes type) {
if(suggestions.length == 0) {
setFocus();
return;
}
if (type == CompletionTypes.CallTips) {
showCallTipsPopup(suggestions);
return;
}
if (suggestions.length == 1) {
insertCompletion(suggestions[0]);
return;

View File

@ -30,7 +30,7 @@ import dlangide.ui.debuggerui;
import dlangide.workspace.workspace;
import dlangide.workspace.project;
import dlangide.builders.builder;
import dlangide.tools.editorTool;
import dlangide.tools.editortool;
import ddebug.common.execution;
import ddebug.common.nodebug;
@ -1176,9 +1176,9 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
return true;
case IDEActions.GetCompletionSuggestions:
Log.d("Getting auto completion suggestions.");
currentEditor.editorTool.getCompletions(currentEditor, currentEditor.caretPos, delegate(dstring[] results, string[] icons) {
currentEditor.editorTool.getCompletions(currentEditor, currentEditor.caretPos, delegate(dstring[] results, string[] icons, CompletionTypes type) {
if (currentEditor)
currentEditor.showCompletionPopup(results, icons);
currentEditor.showCompletionPopup(results, icons, type);
});
return true;
case IDEActions.EditPreferences: