diff --git a/dub.json b/dub.json index 954f9e9..d381c7c 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.60", + "dlangui": "~>0.7.61", "dcd": "~>0.7.5" }, diff --git a/src/ddebug/common/queue.d b/src/ddebug/common/queue.d index 347f9ab..954c801 100644 --- a/src/ddebug/common/queue.d +++ b/src/ddebug/common/queue.d @@ -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 diff --git a/src/dlangide/tools/d/dcdinterface.d b/src/dlangide/tools/d/dcdinterface.d index c8d81c7..3f07022 100644 --- a/src/dlangide/tools/d/dcdinterface.d +++ b/src/dlangide/tools/d/dcdinterface.d @@ -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); - } - } } diff --git a/src/dlangide/tools/d/deditortool.d b/src/dlangide/tools/d/deditortool.d index 016259d..d113232 100644 --- a/src/dlangide/tools/d/deditortool.d +++ b/src/dlangide/tools/d/deditortool.d @@ -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) { diff --git a/src/dlangide/tools/editortool.d b/src/dlangide/tools/editortool.d index 88ba0ff..a7b9c7a 100644 --- a/src/dlangide/tools/editortool.d +++ b/src/dlangide/tools/editortool.d @@ -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); } - - } diff --git a/src/dlangide/ui/dsourceedit.d b/src/dlangide/ui/dsourceedit.d index a1c4ff4..bcf0f7d 100644 --- a/src/dlangide/ui/dsourceedit.d +++ b/src/dlangide/ui/dsourceedit.d @@ -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; diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index b48b6e4..a01b867 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -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.");