Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended mode ditto comment support #562

Merged
merged 3 commits into from
Dec 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dsymbol
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"license": "GPL-3.0",
"dependencies": {
"dsymbol": "~>0.5.5",
"dsymbol": "~>0.5.6",
"libdparse": "~>0.10.10",
"msgpack-d": "~>1.0.0-beta.7",
"stdx-allocator": "~>2.77.5"
Expand Down
17 changes: 8 additions & 9 deletions src/dcd/server/autocomplete/doc.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,16 @@ public AutocompleteResponse getDoc(const AutocompleteRequest request,
warning("Could not find symbol");
else
{
bool isDitto(string s)
// first symbol allows ditto if it's the first documentation,
// because then it takes documentation from a symbol with different name
// which isn't inside the stuff.symbols range.
bool firstSymbol = true;
foreach(ref symbol; stuff.symbols.filter!(a => !a.doc.empty))
{
import std.uni : icmp;
if (s.length > 5)
return false;
else
return s.icmp("ditto") == 0;
}
if (!firstSymbol && symbol.doc.ditto)
continue;
firstSymbol = false;

foreach(ref symbol; stuff.symbols.filter!(a => !a.doc.empty && !isDitto(a.doc)))
{
AutocompleteResponse.Completion c;
c.documentation = symbol.doc;
response.completions ~= c;
Expand Down
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for a; b has no documentation
Empty file.
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for c and d\nmore documentation for c and d
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for c and d\nmore documentation for c and d
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for e and f
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for e and f
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for g\nmore documentation for g
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected8.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for C.x
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected8.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for C.y and C.z
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected8.3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for C.y and C.z
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for C and D
1 change: 1 addition & 0 deletions tests/tc_ditto_scopes/expected9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
documentation for C and D
27 changes: 27 additions & 0 deletions tests/tc_ditto_scopes/file.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
int a; /// documentation for a; b has no documentation
int b;

/** documentation for c and d */
/** more documentation for c and d */
int c;
/** ditto */
int d;

/** documentation for e and f */ int e;
int f; /// ditto

/** documentation for g */
int g; /// more documentation for g

/// documentation for C and D
class C
{
int x; /// documentation for C.x

/** documentation for C.y and C.z */
int y;
int z; /// ditto
}

/// ditto
class D { }
39 changes: 39 additions & 0 deletions tests/tc_ditto_scopes/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
set -e
set -u

../../bin/dcd-client $1 file.d -d -c5 > actual1.txt
diff actual1.txt expected1.txt

../../bin/dcd-client $1 file.d -d -c61 > actual2.txt
diff actual2.txt expected2.txt

../../bin/dcd-client $1 file.d -d -c140 > actual3.txt
diff actual3.txt expected3.txt

../../bin/dcd-client $1 file.d -d -c160 > actual4.txt
diff actual4.txt expected4.txt

../../bin/dcd-client $1 file.d -d -c201 > actual5.txt
diff actual5.txt expected5.txt

../../bin/dcd-client $1 file.d -d -c208 > actual6.txt
diff actual6.txt expected6.txt

../../bin/dcd-client $1 file.d -d -c254 > actual7.txt
diff actual7.txt expected7.txt

../../bin/dcd-client $1 file.d -d -c323 > actual8.txt
diff actual8.txt expected8.txt

../../bin/dcd-client $1 file.d -d -c335 > actual8.1.txt
diff actual8.1.txt expected8.1.txt

../../bin/dcd-client $1 file.d -d -c414 > actual8.2.txt
diff actual8.2.txt expected8.2.txt

../../bin/dcd-client $1 file.d -d -c425 > actual8.3.txt
diff actual8.3.txt expected8.3.txt

../../bin/dcd-client $1 file.d -d -c457 > actual9.txt
diff actual9.txt expected9.txt

3 changes: 3 additions & 0 deletions tests/tc_extended_ditto/expected1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
identifiers
foo f void foo() stdin 26 my documentation
foo f void foo(int i) stdin 49 my documentation
9 changes: 9 additions & 0 deletions tests/tc_extended_ditto/file.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// my documentation
void foo(){}
/// ditto
void foo(int i){}

void test()
{
fo
}
5 changes: 5 additions & 0 deletions tests/tc_extended_ditto/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set -e
set -u

../../bin/dcd-client $1 file.d -x -c80 > actual1.txt
diff actual1.txt expected1.txt