mirror of https://github.com/buggins/dlangide.git
DCD async call for getDocComments - #93
This commit is contained in:
parent
f4d1a8ec7f
commit
7ba06e6bfe
2
dub.json
2
dub.json
|
@ -12,7 +12,7 @@
|
||||||
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"],
|
"stringImportPaths": ["views", "views/res", "views/res/i18n", "views/res/mdpi", "views/res/hdpi"],
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dlangui": "~>0.7.60",
|
"dlangui": "~>0.7.61",
|
||||||
"dcd": "~>0.7.5"
|
"dcd": "~>0.7.5"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -19,16 +19,8 @@ class BlockingQueue(T) {
|
||||||
_writePos = 0;
|
_writePos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void close() {
|
~this() {
|
||||||
if (_mutex && !_closed) {
|
close();
|
||||||
synchronized(_mutex) {
|
|
||||||
_closed = true;
|
|
||||||
if (_condition !is null)
|
|
||||||
_condition.notifyAll();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_closed = true;
|
|
||||||
}
|
|
||||||
if (_condition) {
|
if (_condition) {
|
||||||
destroy(_condition);
|
destroy(_condition);
|
||||||
_condition = null;
|
_condition = null;
|
||||||
|
@ -39,16 +31,23 @@ class BlockingQueue(T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
if (_mutex && !_closed) {
|
||||||
|
synchronized(_mutex) {
|
||||||
|
_closed = true;
|
||||||
|
if (_condition !is null)
|
||||||
|
_condition.notifyAll();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_closed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// returns true if queue is closed
|
/// returns true if queue is closed
|
||||||
@property bool closed() {
|
@property bool closed() {
|
||||||
return _closed;
|
return _closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
~this() {
|
|
||||||
// TODO: destroy mutex?
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void move() {
|
private void move() {
|
||||||
if (_readPos > 1024 && _readPos > _buffer.length * 3 / 4) {
|
if (_readPos > 1024 && _readPos > _buffer.length * 3 / 4) {
|
||||||
// move buffer data
|
// move buffer data
|
||||||
|
|
|
@ -127,16 +127,20 @@ class DCDInterface : Thread {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
DocCommentsResultSet getDocComments(CustomEventTarget guiExecutor, in string[] importPaths, in string filename, in string content, int index) {
|
/// DCD doc comments task
|
||||||
debug(DCD) Log.d("getDocComments: ", dumpContext(content, index));
|
class DocCommentsTask : DCDTask {
|
||||||
AutocompleteRequest request;
|
|
||||||
request.sourceCode = cast(ubyte[])content;
|
|
||||||
request.fileName = filename;
|
|
||||||
request.cursorPosition = index;
|
|
||||||
|
|
||||||
AutocompleteResponse response = getDoc(request, *getModuleCache(importPaths));
|
protected void delegate(DocCommentsResultSet output) _callback;
|
||||||
|
protected DocCommentsResultSet result;
|
||||||
|
|
||||||
|
this(CustomEventTarget guiExecutor, string[] importPaths, in string filename, in string content, int index, void delegate(DocCommentsResultSet output) callback) {
|
||||||
|
super(guiExecutor, importPaths, filename, content, index);
|
||||||
|
_callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
override void performRequest() {
|
||||||
|
AutocompleteResponse response = getDoc(request, *getModuleCache(_importPaths));
|
||||||
|
|
||||||
DocCommentsResultSet result;
|
|
||||||
result.docComments = response.docComments;
|
result.docComments = response.docComments;
|
||||||
result.result = DCDResult.SUCCESS;
|
result.result = DCDResult.SUCCESS;
|
||||||
|
|
||||||
|
@ -145,7 +149,17 @@ class DCDInterface : Thread {
|
||||||
if (result.docComments is null) {
|
if (result.docComments is null) {
|
||||||
result.result = DCDResult.NO_RESULT;
|
result.result = DCDResult.NO_RESULT;
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
override void postResults() {
|
||||||
|
_callback(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DCDTask getDocComments(CustomEventTarget guiExecutor, string[] importPaths, string filename, string content, int index, void delegate(DocCommentsResultSet output) callback) {
|
||||||
|
debug(DCD) Log.d("getDocComments: ", dumpContext(content, index));
|
||||||
|
DocCommentsTask task = new DocCommentsTask(guiExecutor, importPaths, filename, content, index, callback);
|
||||||
|
_queue.put(task);
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// DCD go to definition task
|
/// DCD go to definition task
|
||||||
|
@ -212,37 +226,5 @@ class DCDInterface : Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// DCD doc comments task
|
|
||||||
class DocCommentsTask : DCDTask {
|
|
||||||
|
|
||||||
protected void delegate(DocCommentsResultSet output) _callback;
|
|
||||||
protected DocCommentsResultSet result;
|
|
||||||
|
|
||||||
this(CustomEventTarget guiExecutor, string[] importPaths, in string filename, in string content, int index, void delegate(DocCommentsResultSet output) callback) {
|
|
||||||
super(guiExecutor, importPaths, filename, content, index);
|
|
||||||
_callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
override void performRequest() {
|
|
||||||
AutocompleteRequest request;
|
|
||||||
request.sourceCode = cast(ubyte[])_content;
|
|
||||||
request.fileName = _filename;
|
|
||||||
request.cursorPosition = _index;
|
|
||||||
|
|
||||||
AutocompleteResponse response = getDoc(request, *getModuleCache(_importPaths));
|
|
||||||
|
|
||||||
result.docComments = response.docComments;
|
|
||||||
result.result = DCDResult.SUCCESS;
|
|
||||||
|
|
||||||
debug(DCD) Log.d("DCD doc comments:\n", result.docComments);
|
|
||||||
|
|
||||||
if (result.docComments is null) {
|
|
||||||
result.result = DCDResult.NO_RESULT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
override void postResults() {
|
|
||||||
_callback(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,30 +23,35 @@ class DEditorTool : EditorTool
|
||||||
|
|
||||||
~this() {
|
~this() {
|
||||||
cancelGoToDefinition();
|
cancelGoToDefinition();
|
||||||
|
cancelGetDocComments();
|
||||||
}
|
}
|
||||||
|
|
||||||
override string[] getDocComments(DSourceEdit editor, TextPosition caretPosition) {
|
DCDTask _getDocCommentsTask;
|
||||||
|
override void getDocComments(DSourceEdit editor, TextPosition caretPosition, void delegate(string[]) callback) {
|
||||||
|
cancelGetDocComments();
|
||||||
string[] importPaths = editor.importPaths();
|
string[] importPaths = editor.importPaths();
|
||||||
|
|
||||||
string content = toUTF8(editor.text);
|
string content = toUTF8(editor.text);
|
||||||
auto byteOffset = caretPositionToByteOffset(content, caretPosition);
|
auto byteOffset = caretPositionToByteOffset(content, caretPosition);
|
||||||
DocCommentsResultSet output = _frame.dcdInterface.getDocComments(editor.window, importPaths, editor.filename, content, byteOffset);
|
_getDocCommentsTask = _frame.dcdInterface.getDocComments(editor.window, importPaths, editor.filename, content, byteOffset, delegate(DocCommentsResultSet output) {
|
||||||
|
if(output.result == DCDResult.SUCCESS) {
|
||||||
switch(output.result) {
|
|
||||||
//TODO: Show dialog
|
|
||||||
case DCDResult.FAIL:
|
|
||||||
case DCDResult.NO_RESULT:
|
|
||||||
editor.setFocus();
|
|
||||||
return null;
|
|
||||||
case DCDResult.SUCCESS:
|
|
||||||
auto doc = output.docComments;
|
auto doc = output.docComments;
|
||||||
Log.d("Doc comments: ", doc);
|
Log.d("Doc comments: ", doc);
|
||||||
return doc;
|
if (doc.length)
|
||||||
default:
|
callback(doc);
|
||||||
return null;
|
_getDocCommentsTask = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
override void cancelGetDocComments() {
|
||||||
|
// override it
|
||||||
|
if (_getDocCommentsTask) {
|
||||||
|
_getDocCommentsTask.cancel();
|
||||||
|
_getDocCommentsTask = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override void cancelGoToDefinition() {
|
override void cancelGoToDefinition() {
|
||||||
// override it
|
// override it
|
||||||
if (_goToDefinitionTask) {
|
if (_goToDefinitionTask) {
|
||||||
|
|
|
@ -16,11 +16,11 @@ class EditorTool
|
||||||
}
|
}
|
||||||
//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 void goToDefinition(DSourceEdit editor, TextPosition caretPosition);
|
abstract void goToDefinition(DSourceEdit editor, TextPosition caretPosition);
|
||||||
void cancelGoToDefinition() {
|
abstract void getDocComments(DSourceEdit editor, TextPosition caretPosition, void delegate(string[]) callback);
|
||||||
// override it
|
|
||||||
}
|
|
||||||
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition);
|
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition);
|
||||||
abstract string[] getDocComments(DSourceEdit editor, TextPosition caretPosition);
|
|
||||||
|
void cancelGoToDefinition() {}
|
||||||
|
void cancelGetDocComments() {}
|
||||||
|
|
||||||
protected IDEFrame _frame;
|
protected IDEFrame _frame;
|
||||||
|
|
||||||
|
@ -40,9 +40,7 @@ class DefaultEditorTool : EditorTool
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
override string[] getDocComments(DSourceEdit editor, TextPosition caretPosition) {
|
override void getDocComments(DSourceEdit editor, TextPosition caretPosition, void delegate(string[]) callback) {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,8 +429,9 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener {
|
||||||
Log.d("onHoverTimeout ", pos);
|
Log.d("onHoverTimeout ", pos);
|
||||||
if (!isDSourceFile)
|
if (!isDSourceFile)
|
||||||
return;
|
return;
|
||||||
auto results = editorTool.getDocComments(this, pos);
|
editorTool.getDocComments(this, pos, delegate(string[]results) {
|
||||||
showDocCommentsPopup(results, pt);
|
showDocCommentsPopup(results, pt);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupWidget _docsPopup;
|
PopupWidget _docsPopup;
|
||||||
|
|
|
@ -884,9 +884,10 @@ class IDEFrame : AppFrame, ProgramExecutionStatusListener, BreakpointListChangeL
|
||||||
return true;
|
return true;
|
||||||
case IDEActions.GetDocComments:
|
case IDEActions.GetDocComments:
|
||||||
Log.d("Trying to get doc comments.");
|
Log.d("Trying to get doc comments.");
|
||||||
auto results = currentEditor.editorTool.getDocComments(currentEditor, currentEditor.caretPos);
|
currentEditor.editorTool.getDocComments(currentEditor, currentEditor.caretPos, delegate(string[] results) {
|
||||||
if (results.length)
|
if (results.length)
|
||||||
currentEditor.showDocCommentsPopup(results);
|
currentEditor.showDocCommentsPopup(results);
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
case IDEActions.GetParenCompletion:
|
case IDEActions.GetParenCompletion:
|
||||||
Log.d("Trying to get paren completion.");
|
Log.d("Trying to get paren completion.");
|
||||||
|
|
Loading…
Reference in New Issue