From 823b93f0f787a18ef1a745b028787ec47dc0240b Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Thu, 7 Jan 2016 20:58:39 -0800 Subject: [PATCH] Update deps to get doc comment parsing fixes --- dsymbol | 2 +- libdparse | 2 +- src/server/autocomplete.d | 71 +++++++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/dsymbol b/dsymbol index 5232fcc..0605a90 160000 --- a/dsymbol +++ b/dsymbol @@ -1 +1 @@ -Subproject commit 5232fcc3cae19f2776073590d9c972eefedbca96 +Subproject commit 0605a90a84ac287f879530420c7046cded566b74 diff --git a/libdparse b/libdparse index 8230f20..65d771b 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit 8230f207912b40a46e5eae84e50ee59215b7c67f +Subproject commit 65d771b81240683511c868e0ba05590c6e66bf16 diff --git a/src/server/autocomplete.d b/src/server/autocomplete.d index af126c8..4a23c14 100644 --- a/src/server/autocomplete.d +++ b/src/server/autocomplete.d @@ -65,8 +65,48 @@ public AutocompleteResponse getDoc(const AutocompleteRequest request, allocator, cache, moduleCache); if (stuff.symbols.length == 0) warning("Could not find symbol"); - else foreach (symbol; stuff.symbols.filter!(a => !a.doc.empty)) - response.docComments ~= formatComment(symbol.doc); + else + { + struct Escaper(O) + { + this(O* or) + { + this.outputRange = or; + } + + void put(string s) + { + foreach (c; s) + put(c); + } + + void put(char c) + { + switch (c) + { + case '\n': + outputRange.put('\\'); + outputRange.put('n'); + break; + default: + outputRange.put(c); + break; + } + } + + O* outputRange; + } + + auto app = appender!(char[])(); + auto e = Escaper!(typeof(app))(&app); + foreach (symbol; stuff.symbols.filter!(a => !a.doc.empty)) + { + app.clear(); + foreach(c; symbol.doc) + e.put(c); + response.docComments ~= cast(string) app.data; + } + } return response; } @@ -1258,33 +1298,6 @@ bool shouldSwapWithType(CompletionType completionType, CompletionKind kind, || (completionType == completionType.calltips && kind == CompletionKind.variableName)) ; } -/** - * Params: - * comment = the comment to format - * Returns - * the comment with the comment characters removed - */ -string formatComment(string comment) -{ - import std.regex : replaceFirst, replaceAll, regex; - enum tripleSlashRegex = `(?:\t )*///`; - enum slashStarRegex = `(?:^/\*\*+)|(?:\n?\s*\*+/$)|(?:(?<=\n)\s*\* ?)`; - enum slashPlusRegex = `(?:^/\+\++)|(?:\n?\s*\++/$)|(?:(?<=\n)\s*\+ ?)`; - if (comment.length < 3) - return null; - string re; - if (comment[0 .. 3] == "///") - re = tripleSlashRegex; - else if (comment[1] == '+') - re = slashPlusRegex; - else - re = slashStarRegex; - return (comment.replaceAll(regex(re), "")) - .replaceFirst(regex("^\n"), "") - .replaceAll(regex(`\\`), `\\`) - .replaceAll(regex("\n"), `\n`).outdent(); -} - istring stringToken()(auto ref const Token a) { return internString(a.text is null ? str(a.type) : a.text);