mirror of https://github.com/buggins/dlangide.git
DCD doc comments support, part 1
This commit is contained in:
parent
66c7e28639
commit
e83ca111fb
|
@ -13,6 +13,7 @@ enum DCDResult : int {
|
||||||
FAIL,
|
FAIL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alias DocCommentsResultSet = Tuple!(DCDResult, "result", string[], "docComments");
|
||||||
alias FindDeclarationResultSet = Tuple!(DCDResult, "result", string, "fileName", ulong, "offset");
|
alias FindDeclarationResultSet = Tuple!(DCDResult, "result", string, "fileName", ulong, "offset");
|
||||||
alias ResultSet = Tuple!(DCDResult, "result", dstring[], "output");
|
alias ResultSet = Tuple!(DCDResult, "result", dstring[], "output");
|
||||||
|
|
||||||
|
@ -37,13 +38,28 @@ class DCDInterface {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DocCommentsResultSet getDocComments(in string[] importPaths, in string filename, in string content, int index, ref ModuleCache moduleCache) {
|
||||||
|
AutocompleteRequest request;
|
||||||
|
request.sourceCode = cast(ubyte[])content;
|
||||||
|
request.fileName = filename;
|
||||||
|
request.cursorPosition = index;
|
||||||
|
|
||||||
|
AutocompleteResponse response = getDoc(request,moduleCache);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
FindDeclarationResultSet goToDefinition(in string[] importPaths, in string filename, in string content, int index, ref ModuleCache moduleCache) {
|
FindDeclarationResultSet goToDefinition(in string[] importPaths, in string filename, in string content, int index, ref ModuleCache moduleCache) {
|
||||||
|
|
||||||
version(USE_LIBDPARSE) {
|
|
||||||
import dlangide.tools.d.dparser;
|
|
||||||
DParsingService.instance.addImportPaths(importPaths);
|
|
||||||
DParsedModule m = DParsingService.instance.findDeclaration(cast(ubyte[])content, filename, index);
|
|
||||||
}
|
|
||||||
debug(DCD) Log.d("DCD Context: ", dumpContext(content, index));
|
debug(DCD) Log.d("DCD Context: ", dumpContext(content, index));
|
||||||
|
|
||||||
AutocompleteRequest request;
|
AutocompleteRequest request;
|
||||||
|
|
|
@ -24,6 +24,29 @@ class DEditorTool : EditorTool
|
||||||
super(frame);
|
super(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override string[] getDocComments(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
|
string[] importPaths = editor.importPaths();
|
||||||
|
_frame.moduleCache.addImportPaths(importPaths);
|
||||||
|
|
||||||
|
string content = toUTF8(editor.text);
|
||||||
|
auto byteOffset = caretPositionToByteOffset(content, caretPosition);
|
||||||
|
DocCommentsResultSet output = _dcd.getDocComments(importPaths, editor.filename, content, byteOffset, _frame.moduleCache);
|
||||||
|
|
||||||
|
switch(output.result) {
|
||||||
|
//TODO: Show dialog
|
||||||
|
case DCDResult.FAIL:
|
||||||
|
case DCDResult.NO_RESULT:
|
||||||
|
editor.setFocus();
|
||||||
|
return null;
|
||||||
|
case DCDResult.SUCCESS:
|
||||||
|
auto doc = output.docComments;
|
||||||
|
Log.d("Doc comments: ", doc);
|
||||||
|
return doc;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override bool goToDefinition(DSourceEdit editor, TextPosition caretPosition) {
|
override bool goToDefinition(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
string[] importPaths = editor.importPaths();
|
string[] importPaths = editor.importPaths();
|
||||||
_frame.moduleCache.addImportPaths(importPaths);
|
_frame.moduleCache.addImportPaths(importPaths);
|
||||||
|
|
|
@ -17,6 +17,7 @@ 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 bool goToDefinition(DSourceEdit editor, TextPosition caretPosition);
|
abstract bool goToDefinition(DSourceEdit editor, TextPosition caretPosition);
|
||||||
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition);
|
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition);
|
||||||
|
abstract string[] getDocComments(DSourceEdit editor, TextPosition caretPosition);
|
||||||
|
|
||||||
protected IDEFrame _frame;
|
protected IDEFrame _frame;
|
||||||
|
|
||||||
|
@ -35,4 +36,8 @@ class DefaultEditorTool : EditorTool
|
||||||
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override string[] getDocComments(DSourceEdit editor, TextPosition caretPosition) {
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue