DCD doc comments support, part 1

This commit is contained in:
Vadim Lopatin 2016-01-26 10:30:20 +03:00
parent 66c7e28639
commit e83ca111fb
3 changed files with 49 additions and 5 deletions

View File

@ -13,6 +13,7 @@ enum DCDResult : int {
FAIL,
}
alias DocCommentsResultSet = Tuple!(DCDResult, "result", string[], "docComments");
alias FindDeclarationResultSet = Tuple!(DCDResult, "result", string, "fileName", ulong, "offset");
alias ResultSet = Tuple!(DCDResult, "result", dstring[], "output");
@ -37,13 +38,28 @@ class DCDInterface {
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) {
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));
AutocompleteRequest request;

View File

@ -24,6 +24,29 @@ class DEditorTool : EditorTool
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) {
string[] importPaths = editor.importPaths();
_frame.moduleCache.addImportPaths(importPaths);

View File

@ -17,6 +17,7 @@ class EditorTool
//Since files might be unsaved, we must send all the text content.
abstract bool goToDefinition(DSourceEdit editor, TextPosition caretPosition);
abstract dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition);
abstract string[] getDocComments(DSourceEdit editor, TextPosition caretPosition);
protected IDEFrame _frame;
@ -35,4 +36,8 @@ class DefaultEditorTool : EditorTool
override dstring[] getCompletions(DSourceEdit editor, TextPosition caretPosition) {
assert(0);
}
override string[] getDocComments(DSourceEdit editor, TextPosition caretPosition) {
assert(0);
}
}