From 44bcaf46f7b351be2fecfe5bbd76a47af6c22d73 Mon Sep 17 00:00:00 2001 From: antlord Date: Fri, 29 Jul 2016 03:13:50 +0800 Subject: [PATCH] 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