diff --git a/src/dlangide/tools/EditorTool.d b/src/dlangide/tools/EditorTool.d index a04299f..ee84c8f 100644 --- a/src/dlangide/tools/EditorTool.d +++ b/src/dlangide/tools/EditorTool.d @@ -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; diff --git a/src/dlangide/tools/d/DEditorTool.d b/src/dlangide/tools/d/DEditorTool.d index 7ff6db8..6d3e731 100644 --- a/src/dlangide/tools/d/DEditorTool.d +++ b/src/dlangide/tools/d/DEditorTool.d @@ -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; diff --git a/src/dlangide/ui/commands.d b/src/dlangide/ui/commands.d index b011599..0fc3ec2 100644 --- a/src/dlangide/ui/commands.d +++ b/src/dlangide/ui/commands.d @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index d12a5ad..f4399f2 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -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); }