From 3b88814754a3ed2afaca8d7556b02cb2a7ec0bc4 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 28 Jan 2016 15:51:45 +0300 Subject: [PATCH] completion list with symbol type icons - close #120 --- dub.json | 2 +- src/dlangide/tools/d/dcdinterface.d | 11 ++-- src/dlangide/tools/d/deditortool.d | 69 +++++++++++++++++++++++- src/dlangide/tools/editortool.d | 4 +- src/dlangide/ui/dsourceedit.d | 6 ++- src/dlangide/ui/frame.d | 4 +- views/res/mdpi/symbol-alias.png | Bin 0 -> 215 bytes views/res/mdpi/symbol-array.png | Bin 0 -> 212 bytes views/res/mdpi/symbol-class.png | Bin 0 -> 199 bytes views/res/mdpi/symbol-enum.png | Bin 0 -> 205 bytes views/res/mdpi/symbol-function.png | Bin 0 -> 208 bytes views/res/mdpi/symbol-interface.png | Bin 0 -> 209 bytes views/res/mdpi/symbol-keyword.png | Bin 0 -> 233 bytes views/res/mdpi/symbol-membervar.png | Bin 0 -> 214 bytes views/res/mdpi/symbol-mixintemplate.png | Bin 0 -> 224 bytes views/res/mdpi/symbol-module.png | Bin 0 -> 218 bytes views/res/mdpi/symbol-other.png | Bin 0 -> 182 bytes views/res/mdpi/symbol-package.png | Bin 0 -> 216 bytes views/res/mdpi/symbol-struct.png | Bin 0 -> 213 bytes views/res/mdpi/symbol-template.png | Bin 0 -> 203 bytes views/res/mdpi/symbol-union.png | Bin 0 -> 202 bytes views/res/mdpi/symbol-var.png | Bin 0 -> 213 bytes views/resources.list | 16 ++++++ 23 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 views/res/mdpi/symbol-alias.png create mode 100644 views/res/mdpi/symbol-array.png create mode 100644 views/res/mdpi/symbol-class.png create mode 100644 views/res/mdpi/symbol-enum.png create mode 100644 views/res/mdpi/symbol-function.png create mode 100644 views/res/mdpi/symbol-interface.png create mode 100644 views/res/mdpi/symbol-keyword.png create mode 100644 views/res/mdpi/symbol-membervar.png create mode 100644 views/res/mdpi/symbol-mixintemplate.png create mode 100644 views/res/mdpi/symbol-module.png create mode 100644 views/res/mdpi/symbol-other.png create mode 100644 views/res/mdpi/symbol-package.png create mode 100644 views/res/mdpi/symbol-struct.png create mode 100644 views/res/mdpi/symbol-template.png create mode 100644 views/res/mdpi/symbol-union.png create mode 100644 views/res/mdpi/symbol-var.png diff --git a/dub.json b/dub.json index d381c7c..31dcad5 100644 --- a/dub.json +++ b/dub.json @@ -12,7 +12,7 @@ "stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"], "dependencies": { - "dlangui": "~>0.7.61", + "dlangui": "~>0.7.62", "dcd": "~>0.7.5" }, diff --git a/src/dlangide/tools/d/dcdinterface.d b/src/dlangide/tools/d/dcdinterface.d index ddf5688..73550af 100644 --- a/src/dlangide/tools/d/dcdinterface.d +++ b/src/dlangide/tools/d/dcdinterface.d @@ -19,7 +19,7 @@ enum DCDResult : int { alias DocCommentsResultSet = Tuple!(DCDResult, "result", string[], "docComments"); alias FindDeclarationResultSet = Tuple!(DCDResult, "result", string, "fileName", ulong, "offset"); -alias CompletionResultSet = Tuple!(DCDResult, "result", dstring[], "output"); +alias CompletionResultSet = Tuple!(DCDResult, "result", dstring[], "output", char[], "completionKinds"); import server.autocomplete; import common.messages; @@ -219,9 +219,14 @@ class DCDInterface : Thread { result.result = DCDResult.SUCCESS; result.output.length = response.completions.length; + result.completionKinds.length = response.completions.length; int i=0; - foreach(s;response.completions){ - result.output[i++]=to!dstring(s); + foreach(s;response.completions) { + char type = 0; + if (i < response.completionKinds.length) + type = response.completionKinds[i]; + result.completionKinds[i] = type; + result.output[i++] = to!dstring(s); } debug(DCD) Log.d("DCD output:\n", response.completions); } diff --git a/src/dlangide/tools/d/deditortool.d b/src/dlangide/tools/d/deditortool.d index da30bdb..9e81d68 100644 --- a/src/dlangide/tools/d/deditortool.d +++ b/src/dlangide/tools/d/deditortool.d @@ -107,13 +107,78 @@ class DEditorTool : EditorTool } DCDTask _getCompletionsTask; - override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[]) callback) { + override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] completions, string[] icons) callback) { string[] importPaths = editor.importPaths(); string content = toUTF8(editor.text); auto byteOffset = caretPositionToByteOffset(content, caretPosition); _getCompletionsTask = _frame.dcdInterface.getCompletions(editor.window, importPaths, editor.filename, content, byteOffset, delegate(CompletionResultSet output) { - callback(output.output); + string[] icons; + dstring[] labels; + foreach(index, label; output.output) { + string iconId; + char ch = index < output.completionKinds.length ? output.completionKinds[index] : 0; + switch(ch) { + case 'c': // - class name + iconId = "symbol-class"; + break; + case 'i': // - interface name + iconId = "symbol-interface"; + break; + case 's': // - struct name + iconId = "symbol-struct"; + break; + case 'u': // - union name + iconId = "symbol-union"; + break; + case 'v': // - variable name + iconId = "symbol-var"; + break; + case 'm': // - member variable name + iconId = "symbol-membervar"; + break; + case 'k': // - keyword, built-in version, scope statement + iconId = "symbol-keyword"; + break; + case 'f': // - function or method + iconId = "symbol-function"; + break; + case 'g': // - enum name + iconId = "symbol-enum"; + break; + case 'e': // - enum member + iconId = "symbol-enum"; + break; + case 'P': // - package name + iconId = "symbol-package"; + break; + case 'M': // - module name + iconId = "symbol-module"; + break; + case 'a': // - array + iconId = "symbol-array"; + break; + case 'A': // - associative array + iconId = "symbol-array"; + break; + case 'l': // - alias name + iconId = "symbol-alias"; + break; + case 't': // - template name + iconId = "symbol-template"; + break; + case 'T': // - mixin template name + iconId = "symbol-mixintemplate"; + break; + default: + break; + } + if (!iconId) + iconId = "symbol-other"; + icons ~= iconId; + labels ~= label; + } + callback(labels, icons); _getCompletionsTask = null; }); } diff --git a/src/dlangide/tools/editortool.d b/src/dlangide/tools/editortool.d index 2d958f3..3110a89 100644 --- a/src/dlangide/tools/editortool.d +++ b/src/dlangide/tools/editortool.d @@ -17,7 +17,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[]) callback); + abstract void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] labels, string[] icons) callback); void cancelGoToDefinition() {} void cancelGetDocComments() {} @@ -37,7 +37,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[]) callback) { + override void getCompletions(DSourceEdit editor, TextPosition caretPosition, void delegate(dstring[] labels, string[] icons) callback) { assert(0); } diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index d8525d8..72af19e 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -499,7 +499,7 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { window.update(); } - void showCompletionPopup(dstring[] suggestions) { + void showCompletionPopup(dstring[] suggestions, string[] icons) { if(suggestions.length == 0) { setFocus(); @@ -514,7 +514,11 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener { MenuItem completionPopupItems = new MenuItem(null); //Add all the suggestions. foreach(int i, dstring suggestion ; suggestions) { + string iconId; + if (i < icons.length) + iconId = icons[i]; auto action = new Action(IDEActions.InsertCompletion, suggestion); + action.iconId = iconId; completionPopupItems.add(action); } completionPopupItems.updateActionState(this); diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index 0361e45..129d5ab 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -895,9 +895,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) { + currentEditor.editorTool.getCompletions(currentEditor, currentEditor.caretPos, delegate(dstring[] results, string[] icons) { if (currentEditor) - currentEditor.showCompletionPopup(results); + currentEditor.showCompletionPopup(results, icons); }); return true; case IDEActions.EditPreferences: diff --git a/views/res/mdpi/symbol-alias.png b/views/res/mdpi/symbol-alias.png new file mode 100644 index 0000000000000000000000000000000000000000..50d0978aa2e64b983dcb2a5fef681fecbad3b03c GIT binary patch literal 215 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7Y1I2P=>Nghur4?MK}vQ zB8wRqxP?KOkzv*x37{Z*iKnkC`vXQ99xcW~m;BIh zfAwMsNeLk64D4CcIWgj>!2y=!KT)D5KV*lhv@w+ws-<{t+wfFE>cY_(5*{oi*BVY= zKGEesX=-Y+F&x)coWFh7j5k2b7(8A5T-G@yGywo7 CjzhBm literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-class.png b/views/res/mdpi/symbol-class.png new file mode 100644 index 0000000000000000000000000000000000000000..a1ff3a404b6352ea60946b986ac248cf042cfa99 GIT binary patch literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7Y1I2G6qw2nf3fY5zYdS z$YKTtZeb8+WSBKa0w~B{;_2(k{(w=2N1a2#dUG34D8$pnF+}5ha!Lc!J)_J2c`6P( zUw65O2MBtOXt-TF(y{JG@N-QO*P5qk8Z}}iM_+JVU=(KVOt8pMu#E8R+VQ&bwd70* mAh@?xE?LEG$&*16m=d#Wzp$PyiYdI$X literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-enum.png b/views/res/mdpi/symbol-enum.png new file mode 100644 index 0000000000000000000000000000000000000000..dc341fda7b82562389a88b21509d88dbe4a0fa9f GIT binary patch literal 205 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7Y1I2G6qw2nf3fY5zYdS z$YKTtZeb8+WSBKa0w~B{;_2(k{(w=2M@7+dNrfg*D9Y2tF+}5ha!Lc!J)_J2c`6P( zUw65O2MBtOXt-TF(y``8@N-Qb*P5qk8Z}~0To)LHnL8N{vz4UtGO8O2NwXL5E^)c@ rbKOizB?ex)>QQbIEB=DV<>&pIsQHDpJ!Lq*HA1D;->EaloaXvYvf$7?X)c=wn8t$)N zEFmcY1f79BYdR-J95p!5bmr$)Euqy)+crGCVYw)BM+fACMffg}%y85}Sb4q9e0Q)CGB>(^b literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-interface.png b/views/res/mdpi/symbol-interface.png new file mode 100644 index 0000000000000000000000000000000000000000..5e741f89b15eb47576a95c6242c069319604bf32 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsQHDpu@W(QBN1#xgr;B5V#`)xw2Bv#Pm;dur9C*I& zat{v>^c>M}yLO~w-H+hsnijLy-{El<7T(3+BWQLs!c>6C*^yai$^>U_NdqBi_5$7| uE_c4}`P$<>&pIsQHDo>Rq%A=AD~c~r;B5V#`&oeH}Wh9lTvlza3{Uvyw3)Piud8!hd7Z61 zEA!F4^D|z^&%1Vj;p}xzON-qHUHUuiZZEI66uu(DN<2s_^y?1Oo<$7N<|pNEM4e{+ YCZYBBpmW&_pbHp0UHx3vIVCg!07{ron*aa+ literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-membervar.png b/views/res/mdpi/symbol-membervar.png new file mode 100644 index 0000000000000000000000000000000000000000..6a41efacad60923c381059854d6fd7b1d831e7a8 GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsQHDoegXfg~R-jO_r;B5V#`)xw2BvElQvXYSXt=+6 zv4o@q5OfCitm)*8{J1`JqD0q(qY=*2|E4D?2=Z9-<|LjDbb5Myl?U6l4NoegQb#Fn>BF0!j9u70H#TPWBSfslp?_K|X zNcE!?=UtaYrUGv>lNe7P^a?r>>#3QPl9Z5;P!W6gq(@JZrluwv!}qNkbM&~JIe`{4 Nc)I$ztaD0e0sxfSLR$a; literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-module.png b/views/res/mdpi/symbol-module.png new file mode 100644 index 0000000000000000000000000000000000000000..7ac087b6d1815d1ef0d8f3e2a2dd1e946e515f39 GIT binary patch literal 218 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7X||cABI_m7QF005zYdS z$YKTtZeb8+WSBKa0w~B{;_2(k{(w=2$3Q`Vcm6A&P`am!V~EE2<>&pIsQHDoSXwIC#MxcERRPRkqqNq-$g z)eVKD*$a4=xZIg08Q0^(0|d*js~ZU|j_~s8Vq`d)D))FrgVs5qg$$mqelF{r5}E+d Cb~zopr0O`X$ A!vFvP literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-template.png b/views/res/mdpi/symbol-template.png new file mode 100644 index 0000000000000000000000000000000000000000..688a7fc123af79434eef4edc1f5807ee509f9e12 GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7X|@_28N*UGP=u$8V~EE2bP0l+XkKEd@HY literal 0 HcmV?d00001 diff --git a/views/res/mdpi/symbol-var.png b/views/res/mdpi/symbol-var.png new file mode 100644 index 0000000000000000000000000000000000000000..7c7fde889f243a2395fe322834693a91576c796f GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsQHIAzu=wd;kWopVE{-7@=aW+!nv_1X{+ImFux~PF z4-XLZ9MN#QcBEy^j_)ouZAvK{LDDlNJXj9F29oQ(pm%*xv=8Zw>2 xeTt5Vt}RVWNlHjacwr-S)}tp$Q&W?TVcs;Qm>;{}eFxgc;OXk;vd$@?2>`6GMHT=6 literal 0 HcmV?d00001 diff --git a/views/resources.list b/views/resources.list index ffb67ad..555836e 100644 --- a/views/resources.list +++ b/views/resources.list @@ -62,6 +62,22 @@ res/mdpi/project-open.png res/mdpi/run-build.png res/mdpi/run-build-clean.png res/mdpi/run-build-configure.png +res/mdpi/symbol-function.png +res/mdpi/symbol-keyword.png +res/mdpi/symbol-var.png +res/mdpi/symbol-membervar.png +res/mdpi/symbol-other.png +res/mdpi/symbol-class.png +res/mdpi/symbol-union.png +res/mdpi/symbol-struct.png +res/mdpi/symbol-enum.png +res/mdpi/symbol-interface.png +res/mdpi/symbol-alias.png +res/mdpi/symbol-array.png +res/mdpi/symbol-template.png +res/mdpi/symbol-mixintemplate.png +res/mdpi/symbol-module.png +res/mdpi/symbol-package.png res/mdpi/text-d.png res/mdpi/text-dml.png res/mdpi/text-json.png