From 44bcaf46f7b351be2fecfe5bbd76a47af6c22d73 Mon Sep 17 00:00:00 2001 From: antlord Date: Fri, 29 Jul 2016 03:13:50 +0800 Subject: [PATCH 1/2] Fixed determination of type of array identified by auto --- src/server/autocomplete.d | 13 ++++++++++++- tests/tc038/expected1.txt | 8 ++++++++ tests/tc038/expected2.txt | 12 ++++++++++++ tests/tc038/file.d | 3 +++ tests/tc038/run.sh | 11 +++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/tc038/expected1.txt create mode 100644 tests/tc038/expected2.txt create mode 100644 tests/tc038/file.d create mode 100755 tests/tc038/run.sh diff --git a/src/server/autocomplete.d b/src/server/autocomplete.d index 9c0af1e..f88c21a 100644 --- a/src/server/autocomplete.d +++ b/src/server/autocomplete.d @@ -801,9 +801,20 @@ DSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, if (shouldSwapWithType(completionType, symbols[0].kind, 0, tokens.length - 1)) { - symbols = symbols[0].type is null || symbols[0].type is symbols[0] ? [] : [symbols[0].type]; if (symbols.length == 0) return []; + if (symbols[0].type is null || symbols[0].type is symbols[0]) + { + symbols = []; + } + else if (symbols[0].type.kind == CompletionKind.functionName) + { + symbols = [symbols[0].type.type]; + } + else + { + symbols = [symbols[0].type]; + } } loop: for (size_t i = 1; i < tokens.length; i++) diff --git a/tests/tc038/expected1.txt b/tests/tc038/expected1.txt new file mode 100644 index 0000000..9a132a4 --- /dev/null +++ b/tests/tc038/expected1.txt @@ -0,0 +1,8 @@ +identifiers +alignof k +init k +mangleof k +max k +min k +sizeof k +stringof k diff --git a/tests/tc038/expected2.txt b/tests/tc038/expected2.txt new file mode 100644 index 0000000..c7f4f34 --- /dev/null +++ b/tests/tc038/expected2.txt @@ -0,0 +1,12 @@ +identifiers +alignof k +dup k +idup k +init k +length k +mangleof k +ptr k +reverse k +sizeof k +sort k +stringof k diff --git a/tests/tc038/file.d b/tests/tc038/file.d new file mode 100644 index 0000000..87025ba --- /dev/null +++ b/tests/tc038/file.d @@ -0,0 +1,3 @@ +int[] func(){ return [1,2]; } int main() { auto arr = func(); arr[0]. } +int[] func(){ return [1,2]; } int main() { int[] arr = func(); arr[0]. } +struct pair { int a; int b; }; pair func(){ return pair(); } int main() { auto var = func(); var. } diff --git a/tests/tc038/run.sh b/tests/tc038/run.sh new file mode 100755 index 0000000..723802b --- /dev/null +++ b/tests/tc038/run.sh @@ -0,0 +1,11 @@ +set -e +set -u + +../../bin/dcd-client $1 file.d -c70 > actual.txt +diff actual.txt expected1.txt + +../../bin/dcd-client $1 file.d -c143 > actual.txt +diff actual.txt expected1.txt + +../../bin/dcd-client $1 file.d -c242 > actual.txt +diff actual.txt expected2.txt From ab82590bb6e82c26449af6369558475033555924 Mon Sep 17 00:00:00 2001 From: antlord Date: Sat, 30 Jul 2016 22:51:43 +0800 Subject: [PATCH 2/2] tests have been corrected --- tests/tc038/excplicit_array.d | 2 ++ tests/tc038/expected1.txt | 5 +++-- tests/tc038/expected2.txt | 12 ------------ tests/tc038/file.d | 3 --- tests/tc038/implicit_array.d | 2 ++ tests/tc038/implicit_var.d | 2 ++ tests/tc038/run.sh | 8 ++++---- 7 files changed, 13 insertions(+), 21 deletions(-) create mode 100644 tests/tc038/excplicit_array.d delete mode 100644 tests/tc038/expected2.txt delete mode 100644 tests/tc038/file.d create mode 100644 tests/tc038/implicit_array.d create mode 100644 tests/tc038/implicit_var.d diff --git a/tests/tc038/excplicit_array.d b/tests/tc038/excplicit_array.d new file mode 100644 index 0000000..ae902ab --- /dev/null +++ b/tests/tc038/excplicit_array.d @@ -0,0 +1,2 @@ +struct pair { int a; int b; }; +pair func(){ return pair(); } int main() { auto var = func(); var. } diff --git a/tests/tc038/expected1.txt b/tests/tc038/expected1.txt index 9a132a4..551a093 100644 --- a/tests/tc038/expected1.txt +++ b/tests/tc038/expected1.txt @@ -1,8 +1,9 @@ identifiers +a v alignof k +b v init k mangleof k -max k -min k sizeof k stringof k +tupleof k diff --git a/tests/tc038/expected2.txt b/tests/tc038/expected2.txt deleted file mode 100644 index c7f4f34..0000000 --- a/tests/tc038/expected2.txt +++ /dev/null @@ -1,12 +0,0 @@ -identifiers -alignof k -dup k -idup k -init k -length k -mangleof k -ptr k -reverse k -sizeof k -sort k -stringof k diff --git a/tests/tc038/file.d b/tests/tc038/file.d deleted file mode 100644 index 87025ba..0000000 --- a/tests/tc038/file.d +++ /dev/null @@ -1,3 +0,0 @@ -int[] func(){ return [1,2]; } int main() { auto arr = func(); arr[0]. } -int[] func(){ return [1,2]; } int main() { int[] arr = func(); arr[0]. } -struct pair { int a; int b; }; pair func(){ return pair(); } int main() { auto var = func(); var. } diff --git a/tests/tc038/implicit_array.d b/tests/tc038/implicit_array.d new file mode 100644 index 0000000..c6fa5ee --- /dev/null +++ b/tests/tc038/implicit_array.d @@ -0,0 +1,2 @@ +struct pair { int a; int b; }; +pair[] func(){ return [pair(1,2)]; } int main() { auto arr = func(); arr[0]. } diff --git a/tests/tc038/implicit_var.d b/tests/tc038/implicit_var.d new file mode 100644 index 0000000..c6fa5ee --- /dev/null +++ b/tests/tc038/implicit_var.d @@ -0,0 +1,2 @@ +struct pair { int a; int b; }; +pair[] func(){ return [pair(1,2)]; } int main() { auto arr = func(); arr[0]. } diff --git a/tests/tc038/run.sh b/tests/tc038/run.sh index 723802b..a57b860 100755 --- a/tests/tc038/run.sh +++ b/tests/tc038/run.sh @@ -1,11 +1,11 @@ set -e set -u -../../bin/dcd-client $1 file.d -c70 > actual.txt +../../bin/dcd-client $1 implicit_array.d -c108 > actual.txt diff actual.txt expected1.txt -../../bin/dcd-client $1 file.d -c143 > actual.txt +../../bin/dcd-client $1 excplicit_array.d -c98 > actual.txt diff actual.txt expected1.txt -../../bin/dcd-client $1 file.d -c242 > actual.txt -diff actual.txt expected2.txt +../../bin/dcd-client $1 implicit_var.d -c108 > actual.txt +diff actual.txt expected1.txt