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