Merge pull request #560 from BBasile/reg-558
fix #558 - regression in import completion due to FQN autocomplete merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
commit
80be02adb3
|
@ -77,35 +77,45 @@ public AutocompleteResponse complete(const AutocompleteRequest request,
|
||||||
if (tokenArray.length >= 3 && tokenArray[0] == tok!"module" && beforeTokens.length &&
|
if (tokenArray.length >= 3 && tokenArray[0] == tok!"module" && beforeTokens.length &&
|
||||||
(beforeTokens[$-1] == tok!"." || dotId))
|
(beforeTokens[$-1] == tok!"." || dotId))
|
||||||
{
|
{
|
||||||
const upper = tokenArray.countUntil!(a => a.type == tok!";" &&
|
const moduleDeclEndIndex = tokenArray.countUntil!(a => a.type == tok!";");
|
||||||
a.index < beforeTokens[$-1].index);
|
bool beginsWithModuleName;
|
||||||
bool isSame = upper != -1;
|
|
||||||
// enough room for the module decl and the fqn...
|
// enough room for the module decl and the fqn...
|
||||||
if (isSame && beforeTokens.length >= upper * 2)
|
if (moduleDeclEndIndex != -1 && beforeTokens.length >= moduleDeclEndIndex * 2)
|
||||||
foreach (immutable i; 0 .. upper)
|
foreach (immutable i; 0 .. moduleDeclEndIndex)
|
||||||
{
|
{
|
||||||
const j = beforeTokens.length - upper + i - 1 - ubyte(dotId);
|
const expectIdt = bool(i & 1);
|
||||||
|
const expectDot = !expectIdt;
|
||||||
|
const j = beforeTokens.length - moduleDeclEndIndex + i - 1 - ubyte(dotId);
|
||||||
|
|
||||||
// verify that the chain is well located after an expr or a decl
|
// verify that the chain is well located after an expr or a decl
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
if (beforeTokens[j].type.among(tok!"{", tok!"}", tok!";", tok!"[",
|
if (!beforeTokens[j].type.among(tok!"{", tok!"}", tok!";",
|
||||||
tok!"(", tok!",", tok!":"))
|
tok!"[", tok!"(", tok!",", tok!":"))
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// compare the end of the "before tokens" (access chain)
|
|
||||||
// with the firsts (ModuleDeclaration)
|
|
||||||
else if ((tokenArray[i].type == tok!"." && beforeTokens[j].type == tok!".") ||
|
|
||||||
(tokenArray[i].type == tok!"identifier" && tokenArray[i].text == beforeTokens[j].text))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
isSame = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// then compare the end of the "before tokens" (access chain)
|
||||||
|
// with the firsts (ModuleDeclaration)
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// even index : must be a dot
|
||||||
|
if (expectDot &&
|
||||||
|
(tokenArray[i].type != tok!"." || beforeTokens[j].type != tok!"."))
|
||||||
|
break;
|
||||||
|
// odd index : identifiers must match
|
||||||
|
else if (expectIdt &&
|
||||||
|
(tokenArray[i].type != tok!"identifier" || beforeTokens[j].type != tok!"identifier" ||
|
||||||
|
tokenArray[i].text != beforeTokens[j].text))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == moduleDeclEndIndex - 1)
|
||||||
|
beginsWithModuleName = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// replace the "before tokens" with a pattern making the remaining
|
// replace the "before tokens" with a pattern making the remaining
|
||||||
// parts of the completion process think that it's a "Module Scope Operator".
|
// parts of the completion process think that it's a "Module Scope Operator".
|
||||||
if (isSame)
|
if (beginsWithModuleName)
|
||||||
{
|
{
|
||||||
if (dotId)
|
if (dotId)
|
||||||
beforeTokens = assumeSorted([const Token(tok!"{"), const Token(tok!"."),
|
beforeTokens = assumeSorted([const Token(tok!"{"), const Token(tok!"."),
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
identifiers
|
||||||
|
bar M
|
||||||
|
module1 M
|
|
@ -0,0 +1 @@
|
||||||
|
module foo.foo.test; import package1.; int x; void y() {}
|
|
@ -0,0 +1,5 @@
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
../../bin/dcd-client $1 file.d -c37 > actual.txt
|
||||||
|
diff actual.txt expected.txt
|
Loading…
Reference in New Issue