mirror of https://github.com/buggins/dlangide.git
Implementated getting completion suggestions.
See issue #20 Suggestions is not displayed yet.
This commit is contained in:
parent
d766508c99
commit
e09844343e
|
@ -15,7 +15,8 @@ class EditorTool
|
||||||
_frame = frame;
|
_frame = frame;
|
||||||
}
|
}
|
||||||
//Since files might be unsaved, we must send all the text content.
|
//Since files might be unsaved, we must send all the text content.
|
||||||
abstract bool goToDefinition(DSourceEdit content, TextPosition caretPosition);
|
abstract bool goToDefinition(DSourceEdit editor, TextPosition caretPosition);
|
||||||
|
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition);
|
||||||
|
|
||||||
protected IDEFrame _frame;
|
protected IDEFrame _frame;
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,40 @@ class DEditorTool : EditorTool
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
|
auto content = editor.text();
|
||||||
|
auto byteOffset = caretPositionToByteOffset(content, caretPosition);
|
||||||
|
|
||||||
|
char[][] arguments = ["-c".dup];
|
||||||
|
arguments ~= [to!(char[])(byteOffset)];
|
||||||
|
arguments ~= [to!(char[])(editor.projectSourceFile.filename())];
|
||||||
|
|
||||||
|
dstring output;
|
||||||
|
_dcd.execute(arguments, output);
|
||||||
|
|
||||||
|
char[] state = "".dup;
|
||||||
|
dstring[] suggestions;
|
||||||
|
foreach(dstring outputLine ; output.splitLines()) {
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ enum IDEActions : int {
|
||||||
ProjectFolderOpenItem,
|
ProjectFolderOpenItem,
|
||||||
ProjectFolderRenameItem,
|
ProjectFolderRenameItem,
|
||||||
GoToDefinition,
|
GoToDefinition,
|
||||||
|
GetCompletionSuggestions,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Action ACTION_PROJECT_FOLDER_ADD_ITEM = new Action(IDEActions.ProjectFolderAddItem, "MENU_PROJECT_FOLDER_ADD_ITEM"c);
|
const Action ACTION_PROJECT_FOLDER_ADD_ITEM = new Action(IDEActions.ProjectFolderAddItem, "MENU_PROJECT_FOLDER_ADD_ITEM"c);
|
||||||
|
@ -87,3 +88,4 @@ const Action ACTION_WINDOW_CLOSE_ALL_DOCUMENTS = new Action(IDEActions.WindowClo
|
||||||
const Action ACTION_CREATE_NEW_WORKSPACE = new Action(IDEActions.CreateNewWorkspace, "Create new workspace"d);
|
const Action ACTION_CREATE_NEW_WORKSPACE = new Action(IDEActions.CreateNewWorkspace, "Create new workspace"d);
|
||||||
const Action ACTION_ADD_TO_CURRENT_WORKSPACE = new Action(IDEActions.AddToCurrentWorkspace, "Add to current workspace"d);
|
const Action ACTION_ADD_TO_CURRENT_WORKSPACE = new Action(IDEActions.AddToCurrentWorkspace, "Add to current workspace"d);
|
||||||
const Action ACTION_GO_TO_DEFINITION = new Action(IDEActions.GoToDefinition, "GO_TO_DEFINITION"c, "edit-cut"c, KeyCode.KEY_G, KeyFlag.Control);
|
const Action ACTION_GO_TO_DEFINITION = new Action(IDEActions.GoToDefinition, "GO_TO_DEFINITION"c, "edit-cut"c, KeyCode.KEY_G, KeyFlag.Control);
|
||||||
|
const Action ACTION_GET_COMPLETIONS = new Action(IDEActions.GetCompletionSuggestions, "GO_TO_DEFINITION"c, "edit-cut"c, KeyCode.KEY_G, KeyFlag.Shift);
|
|
@ -382,6 +382,7 @@ class IDEFrame : AppFrame {
|
||||||
tb.addButtons(ACTION_PROJECT_BUILD);
|
tb.addButtons(ACTION_PROJECT_BUILD);
|
||||||
|
|
||||||
tb.addButtons(ACTION_GO_TO_DEFINITION);
|
tb.addButtons(ACTION_GO_TO_DEFINITION);
|
||||||
|
tb.addButtons(ACTION_GET_COMPLETIONS);
|
||||||
|
|
||||||
tb = res.getOrAddToolbar("Edit");
|
tb = res.getOrAddToolbar("Edit");
|
||||||
tb.addButtons(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_SEPARATOR,
|
tb.addButtons(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_SEPARATOR,
|
||||||
|
@ -513,9 +514,13 @@ class IDEFrame : AppFrame {
|
||||||
dlg.show();
|
dlg.show();
|
||||||
return true;
|
return true;
|
||||||
case IDEActions.GoToDefinition:
|
case IDEActions.GoToDefinition:
|
||||||
Log.i("Trying to go to definition");
|
Log.d("Trying to go to definition.");
|
||||||
_editorTool.goToDefinition(currentEditor(), currentEditor.getCaretPosition());
|
_editorTool.goToDefinition(currentEditor(), currentEditor.getCaretPosition());
|
||||||
return true;
|
return true;
|
||||||
|
case IDEActions.GetCompletionSuggestions:
|
||||||
|
Log.d("Getting auto completion suggestions.");
|
||||||
|
auto results = _editorTool.getCompletions(currentEditor, currentEditor.getCaretPosition);
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.handleAction(a);
|
return super.handleAction(a);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue