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;
|
||||
}
|
||||
//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;
|
||||
|
||||
|
|
|
@ -66,6 +66,40 @@ class DEditorTool : EditorTool
|
|||
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:
|
||||
DCDInterface _dcd;
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ enum IDEActions : int {
|
|||
ProjectFolderOpenItem,
|
||||
ProjectFolderRenameItem,
|
||||
GoToDefinition,
|
||||
GetCompletionSuggestions,
|
||||
}
|
||||
|
||||
const Action ACTION_PROJECT_FOLDER_ADD_ITEM = new Action(IDEActions.ProjectFolderAddItem, "MENU_PROJECT_FOLDER_ADD_ITEM"c);
|
||||
|
@ -86,4 +87,5 @@ const Action ACTION_HELP_ABOUT = new Action(IDEActions.HelpAbout, "MENU_HELP_ABO
|
|||
const Action ACTION_WINDOW_CLOSE_ALL_DOCUMENTS = new Action(IDEActions.WindowCloseAllDocuments, "MENU_WINDOW_CLOSE_ALL_DOCUMENTS"c);
|
||||
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_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_GO_TO_DEFINITION);
|
||||
tb.addButtons(ACTION_GET_COMPLETIONS);
|
||||
|
||||
tb = res.getOrAddToolbar("Edit");
|
||||
tb.addButtons(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_SEPARATOR,
|
||||
|
@ -513,9 +514,13 @@ class IDEFrame : AppFrame {
|
|||
dlg.show();
|
||||
return true;
|
||||
case IDEActions.GoToDefinition:
|
||||
Log.i("Trying to go to definition");
|
||||
Log.d("Trying to go to definition.");
|
||||
_editorTool.goToDefinition(currentEditor(), currentEditor.getCaretPosition());
|
||||
return true;
|
||||
case IDEActions.GetCompletionSuggestions:
|
||||
Log.d("Getting auto completion suggestions.");
|
||||
auto results = _editorTool.getCompletions(currentEditor, currentEditor.getCaretPosition);
|
||||
return true;
|
||||
default:
|
||||
return super.handleAction(a);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue