completion list with symbol type icons - close #120

This commit is contained in:
Vadim Lopatin 2016-01-28 15:51:45 +03:00
parent 13f2656550
commit 3b88814754
23 changed files with 101 additions and 11 deletions

View File

@ -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"
},

View File

@ -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);
}

View File

@ -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;
});
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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:

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

View File

@ -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