diff --git a/src/server/autocomplete/localuse.d b/src/server/autocomplete/localuse.d index b09816b..65ae294 100644 --- a/src/server/autocomplete/localuse.d +++ b/src/server/autocomplete/localuse.d @@ -41,81 +41,81 @@ import common.messages; * the autocompletion response. */ public AutocompleteResponse findLocalUse(AutocompleteRequest request, - ref ModuleCache moduleCache) + ref ModuleCache moduleCache) { - AutocompleteResponse response; - RollbackAllocator rba; - auto allocator = scoped!(ASTAllocator)(); - auto cache = StringCache(StringCache.defaultBucketCount); + AutocompleteResponse response; + RollbackAllocator rba; + auto allocator = scoped!(ASTAllocator)(); + auto cache = StringCache(StringCache.defaultBucketCount); - // patchs the original request for the subsequent requests - request.kind = RequestKind.symbolLocation; + // patchs the original request for the subsequent requests + request.kind = RequestKind.symbolLocation; - // getSymbolsForCompletion() copy to avoid repetitive parsing - LexerConfig config; - config.fileName = ""; - const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode, - config, &cache); - SymbolStuff getSymbolsAtCursor(size_t cursorPosition) - { - auto sortedTokens = assumeSorted(tokenArray); - auto beforeTokens = sortedTokens.lowerBound(cursorPosition); - ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, allocator, - &rba, request.cursorPosition, moduleCache); - auto expression = getExpression(beforeTokens); - return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, - cursorPosition, CompletionType.location), pair.symbol, pair.scope_); - } + // getSymbolsForCompletion() copy to avoid repetitive parsing + LexerConfig config; + config.fileName = ""; + const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode, + config, &cache); + SymbolStuff getSymbolsAtCursor(size_t cursorPosition) + { + auto sortedTokens = assumeSorted(tokenArray); + auto beforeTokens = sortedTokens.lowerBound(cursorPosition); + ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, allocator, + &rba, request.cursorPosition, moduleCache); + auto expression = getExpression(beforeTokens); + return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, + cursorPosition, CompletionType.location), pair.symbol, pair.scope_); + } - // gets the symbol matching to cursor pos - SymbolStuff stuff = getSymbolsAtCursor(cast(size_t)request.cursorPosition); - scope(exit) stuff.destroy(); + // gets the symbol matching to cursor pos + SymbolStuff stuff = getSymbolsAtCursor(cast(size_t)request.cursorPosition); + scope(exit) stuff.destroy(); - // starts searching only if no ambiguity with the symbol - if (stuff.symbols.length == 1) - { - const(DSymbol*) sourceSymbol = stuff.symbols[0]; - response.symbolLocation = sourceSymbol.location; - response.symbolFilePath = sourceSymbol.symbolFile.idup; + // starts searching only if no ambiguity with the symbol + if (stuff.symbols.length == 1) + { + const(DSymbol*) sourceSymbol = stuff.symbols[0]; + response.symbolLocation = sourceSymbol.location; + response.symbolFilePath = sourceSymbol.symbolFile.idup; - // gets the source token to avoid too much getSymbolsAtCursor() - const(Token)* sourceToken; - foreach(i, t; tokenArray) - { - if (t.type != tok!"identifier") - continue; - if (request.cursorPosition >= t.index && - request.cursorPosition < t.index + t.text.length) - { - sourceToken = tokenArray.ptr + i; - break; - } - } + // gets the source token to avoid too much getSymbolsAtCursor() + const(Token)* sourceToken; + foreach(i, t; tokenArray) + { + if (t.type != tok!"identifier") + continue; + if (request.cursorPosition >= t.index && + request.cursorPosition < t.index + t.text.length) + { + sourceToken = tokenArray.ptr + i; + break; + } + } - // finds the tokens that match to the source symbol - if (sourceToken != null) foreach (t; tokenArray) - { - if (t.type == tok!"identifier" && t.text == sourceToken.text) - { - size_t pos = cast(size_t) t.index + 1; // place cursor inside the token - SymbolStuff candidate = getSymbolsAtCursor(pos); - scope(exit) candidate.destroy(); - if (candidate.symbols.length == 1 && - candidate.symbols[0].location == sourceSymbol.location && - candidate.symbols[0].symbolFile == sourceSymbol.symbolFile) - { - response.locations ~= t.index; - } - } - } - else - { - warning("The source token is not an identifier"); - } - } - else - { - warning("No or ambiguous symbol for the identifier at cursor"); - } - return response; + // finds the tokens that match to the source symbol + if (sourceToken != null) foreach (t; tokenArray) + { + if (t.type == tok!"identifier" && t.text == sourceToken.text) + { + size_t pos = cast(size_t) t.index + 1; // place cursor inside the token + SymbolStuff candidate = getSymbolsAtCursor(pos); + scope(exit) candidate.destroy(); + if (candidate.symbols.length == 1 && + candidate.symbols[0].location == sourceSymbol.location && + candidate.symbols[0].symbolFile == sourceSymbol.symbolFile) + { + response.locations ~= t.index; + } + } + } + else + { + warning("The source token is not an identifier"); + } + } + else + { + warning("No or ambiguous symbol for the identifier at cursor"); + } + return response; } diff --git a/tests/imports/b.d b/tests/imports/b.d index 31f1335..ead5b61 100644 --- a/tests/imports/b.d +++ b/tests/imports/b.d @@ -2,5 +2,5 @@ module b; string BAR; struct S { - int x; + int x; } diff --git a/tests/tc003/file.d b/tests/tc003/file.d index 00b6f7a..43356f6 100644 --- a/tests/tc003/file.d +++ b/tests/tc003/file.d @@ -1,39 +1,39 @@ abstract class InheritMe(T) { - final abstract class GrandChild(U, V) - { - /// I am uvalue - static U uvalue; + final abstract class GrandChild(U, V) + { + /// I am uvalue + static U uvalue; - /// I am vvalue - static V vvalue; + /// I am vvalue + static V vvalue; - /// I am setGrandChild - static void setGrandChild(alias X, alias Y)() - { - X = Y; - } - } + /// I am setGrandChild + static void setGrandChild(alias X, alias Y)() + { + X = Y; + } + } } final abstract class Parent(T) { - /// I am stringChild - final abstract class StringChild : InheritMe!(string) - { - /// I am a string GrandChild - alias s = GrandChild!(T, string); + /// I am stringChild + final abstract class StringChild : InheritMe!(string) + { + /// I am a string GrandChild + alias s = GrandChild!(T, string); - /// I am an int GrandChild - alias i = GrandChild!(T, int); - } + /// I am an int GrandChild + alias i = GrandChild!(T, int); + } - /// I am a parentF - static void parentF() - { + /// I am a parentF + static void parentF() + { - } + } } /// I am stringParent @@ -41,11 +41,11 @@ alias stringParent = Parent!string; void main(string[] args) { - with(stringParent.StringChild.s) - { - setGrandChild - !( - uvalue, "test", - )(); - } + with(stringParent.StringChild.s) + { + setGrandChild + !( + uvalue, "test", + )(); + } } diff --git a/tests/tc003/run.sh b/tests/tc003/run.sh index 24f3602..0dc8e0e 100755 --- a/tests/tc003/run.sh +++ b/tests/tc003/run.sh @@ -1,8 +1,8 @@ set -e set -u -../../bin/dcd-client $1 file.d -c839 > actual1.txt +../../bin/dcd-client $1 file.d -c696 > actual1.txt diff actual1.txt expected1.txt -../../bin/dcd-client $1 file.d -c862 > actual2.txt +../../bin/dcd-client $1 file.d -c713 > actual2.txt diff actual2.txt expected2.txt diff --git a/tests/tc005/file.d b/tests/tc005/file.d index 2d8e9da..a85e2fa 100644 --- a/tests/tc005/file.d +++ b/tests/tc005/file.d @@ -2,14 +2,14 @@ import std.stdio; final abstract class ABC { - static @property bool mybool() - { - return true; - } + static @property bool mybool() + { + return true; + } } void main(string[] s) { - while(!ABC.mybool) {} + while(!ABC.mybool) {} } // Regression test for issue 182 diff --git a/tests/tc005/run.sh b/tests/tc005/run.sh index c3b3062..e32dbae 100755 --- a/tests/tc005/run.sh +++ b/tests/tc005/run.sh @@ -1,5 +1,5 @@ set -e set -u -../../bin/dcd-client $1 file.d -c154 > actual.txt +../../bin/dcd-client $1 file.d -c136 > actual.txt diff actual.txt expected.txt diff --git a/tests/tc028/file.d b/tests/tc028/file.d index ac3e7fe..8713a55 100644 --- a/tests/tc028/file.d +++ b/tests/tc028/file.d @@ -1,14 +1,14 @@ struct Bob { - version (all) - { - } - else - { - @disable this(); - } + version (all) + { + } + else + { + @disable this(); + } - int abcde; + int abcde; } unittest diff --git a/tests/tc029/file.d b/tests/tc029/file.d index 343fe1c..c05a656 100644 --- a/tests/tc029/file.d +++ b/tests/tc029/file.d @@ -1,6 +1,6 @@ unittest { - int car; - alias complicatedLess = (a, b) => a.c.d < b.c.d; + int car; + alias complicatedLess = (a, b) => a.c.d < b.c.d; c } diff --git a/tests/tc029/run.sh b/tests/tc029/run.sh index 3bf0d12..99b7a09 100755 --- a/tests/tc029/run.sh +++ b/tests/tc029/run.sh @@ -1,5 +1,5 @@ set -e set -u -../../bin/dcd-client $1 file.d -c79 > actual1.txt +../../bin/dcd-client $1 file.d -c73 > actual1.txt diff actual1.txt expected1.txt diff --git a/tests/tc041/file.d b/tests/tc041/file.d index 9d89d27..95acf83 100644 --- a/tests/tc041/file.d +++ b/tests/tc041/file.d @@ -1,15 +1,15 @@ /// A enum A { - none, /// A.none - one, /// A.one + none, /// A.none + one, /// A.one } /// B enum B { - none, /// B.none - one, /// B.one + none, /// B.none + one, /// B.one } void main() diff --git a/tests/tc041/run.sh b/tests/tc041/run.sh index 8e51d1c..77c1c8a 100755 --- a/tests/tc041/run.sh +++ b/tests/tc041/run.sh @@ -1,15 +1,15 @@ set -e set -u -../../bin/dcd-client $1 file.d -d -c161 > actual1.txt +../../bin/dcd-client $1 file.d -d -c149 > actual1.txt diff actual1.txt expected1.txt -../../bin/dcd-client $1 file.d -d -c170 > actual2.txt +../../bin/dcd-client $1 file.d -d -c158 > actual2.txt diff actual2.txt expected2.txt -../../bin/dcd-client $1 file.d -d -c178 > actual3.txt +../../bin/dcd-client $1 file.d -d -c166 > actual3.txt diff actual3.txt expected3.txt -../../bin/dcd-client $1 file.d -d -c187 > actual4.txt +../../bin/dcd-client $1 file.d -d -c175 > actual4.txt diff actual4.txt expected4.txt diff --git a/tests/tc042/file.d b/tests/tc042/file.d index 382064b..29fba70 100644 --- a/tests/tc042/file.d +++ b/tests/tc042/file.d @@ -1,13 +1,13 @@ /// A enum A { - none, /// A.none - one, /// A.one + none, /// A.none + one, /// A.one } /// B enum B { - none, /// B.none - one, /// B.one + none, /// B.none + one, /// B.one } diff --git a/tests/tc042/run.sh b/tests/tc042/run.sh index 850a5d6..c92ca75 100755 --- a/tests/tc042/run.sh +++ b/tests/tc042/run.sh @@ -1,8 +1,8 @@ set -e set -u -../../bin/dcd-client $1 file.d -d -c21 > actual1.txt +../../bin/dcd-client $1 file.d -d -c18 > actual1.txt diff actual1.txt expected1.txt -../../bin/dcd-client $1 file.d -d -c119 > actual2.txt +../../bin/dcd-client $1 file.d -d -c107 > actual2.txt diff actual2.txt expected2.txt diff --git a/tests/tc045/file.d b/tests/tc045/file.d index b40ab01..d75eb61 100644 --- a/tests/tc045/file.d +++ b/tests/tc045/file.d @@ -1,5 +1,5 @@ this() { - new class C {}; - XX + new class C {}; + XX } diff --git a/tests/tc045/run.sh b/tests/tc045/run.sh index 96da67d..815d319 100755 --- a/tests/tc045/run.sh +++ b/tests/tc045/run.sh @@ -1,5 +1,5 @@ set -e set -u -../../bin/dcd-client $1 file.d -c29 > actual.txt +../../bin/dcd-client $1 file.d -c26 > actual.txt # segfault if -c29 (" XX|"), bug! diff actual.txt expected.txt diff --git a/tests/tc047/file.d b/tests/tc047/file.d index fdb8620..2ef59fe 100644 --- a/tests/tc047/file.d +++ b/tests/tc047/file.d @@ -1,9 +1,9 @@ struct Foo { - /// Sets or gets prop - void prop(int t); - /// ditto - int prop(); + /// Sets or gets prop + void prop(int t); + /// ditto + int prop(); } void main(string[] args) diff --git a/tests/tc047/run.sh b/tests/tc047/run.sh index 411756a..2648522 100755 --- a/tests/tc047/run.sh +++ b/tests/tc047/run.sh @@ -1,5 +1,5 @@ set -e set -u -../../bin/dcd-client $1 file.d -d -c136 > actual.txt +../../bin/dcd-client $1 file.d -d -c124 > actual.txt diff actual.txt expected.txt diff --git a/tests/tc048/file.d b/tests/tc048/file.d index 7ade9fb..a17b63e 100644 --- a/tests/tc048/file.d +++ b/tests/tc048/file.d @@ -1,9 +1,9 @@ template Foo(T) { - void bar(); + void bar(); } void main(string[] args) { - (Foo!int). + (Foo!int). } diff --git a/tests/tc048/run.sh b/tests/tc048/run.sh index fe4ee35..eb80165 100755 --- a/tests/tc048/run.sh +++ b/tests/tc048/run.sh @@ -1,5 +1,5 @@ set -e set -u -../../bin/dcd-client $1 file.d -c78 > actual.txt +../../bin/dcd-client $1 file.d -c72 > actual.txt diff actual.txt expected.txt diff --git a/tests/tc049/expected3.txt b/tests/tc049/expected3.txt index ca1d93b..6e9edf3 100644 --- a/tests/tc049/expected3.txt +++ b/tests/tc049/expected3.txt @@ -1 +1 @@ -stdin 143 +stdin 140 diff --git a/tests/tc049/file.d b/tests/tc049/file.d index 6d6605d..1c072f7 100644 --- a/tests/tc049/file.d +++ b/tests/tc049/file.d @@ -5,13 +5,13 @@ alias bar = T!foo; // doesn't work final class ABC { - static @property bool mybool() - { - return true; - } + static @property bool mybool() + { + return true; + } } void main() { - while(!ABC.mybool) {} + while(!ABC.mybool) {} } diff --git a/tests/tc049/run.sh b/tests/tc049/run.sh index 3e11a79..b175673 100755 --- a/tests/tc049/run.sh +++ b/tests/tc049/run.sh @@ -7,5 +7,5 @@ diff actual1.txt expected1.txt ../../bin/dcd-client $1 file.d -l -c47 > actual2.txt diff actual2.txt expected2.txt -../../bin/dcd-client $1 file.d -l -c218 > actual3.txt +../../bin/dcd-client $1 file.d -l -c200 > actual3.txt diff actual3.txt expected3.txt diff --git a/tests/tc050/file.d b/tests/tc050/file.d index 95a1df5..fc98b14 100644 --- a/tests/tc050/file.d +++ b/tests/tc050/file.d @@ -2,5 +2,5 @@ auto a = [[[0]]]; void main(string[] args) { - a[0][0][0]. + a[0][0][0]. } diff --git a/tests/tc050/run.sh b/tests/tc050/run.sh index ac655b4..f14a51c 100755 --- a/tests/tc050/run.sh +++ b/tests/tc050/run.sh @@ -1,5 +1,5 @@ set -e set -u -../../bin/dcd-client $1 file.d -c61 > actual.txt +../../bin/dcd-client $1 file.d -c58 > actual.txt diff actual.txt expected.txt