From 1afdec1c630f46a2ad92646cb8485357b94e24b5 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Thu, 10 Jul 2014 13:30:53 -0700 Subject: [PATCH] Properly resolve symbols with the global-scope operator --- actypes.d | 18 ++++++++++-------- autocomplete.d | 12 ++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/actypes.d b/actypes.d index 541a2bc..608331b 100644 --- a/actypes.d +++ b/actypes.d @@ -233,14 +233,9 @@ struct Scope { import std.range; ACSymbol s = ACSymbol(name); - auto r = array(symbols.equalRange(&s)); - foreach (i; r) - { - import std.string; - assert (i.name == name, format("%s %s %d", i.name, name, r.length)); - } - if (r.length > 0) - return cast(typeof(return)) r; + auto er = symbols.equalRange(&s); + if (!er.empty) + return cast(typeof(return)) array(er); if (parent is null) return []; return parent.getSymbolsByName(name); @@ -262,6 +257,13 @@ struct Scope return s.getSymbolsByName(name); } + ACSymbol*[] getSymbolsAtGlobalScope(string name) + { + if (parent !is null) + return parent.getSymbolsAtGlobalScope(name); + return getSymbolsByName(name); + } + /// Imports contained in this scope UnrolledList!(ImportInformation*) importInformation; diff --git a/autocomplete.d b/autocomplete.d index c91968f..d19c38b 100644 --- a/autocomplete.d +++ b/autocomplete.d @@ -299,8 +299,16 @@ ACSymbol*[] getSymbolsByTokenChain(T)(Scope* completionScope, Log.trace("Getting symbols from token chain", tokens.map!stringToken); // Find the symbol corresponding to the beginning of the chain - ACSymbol*[] symbols = completionScope.getSymbolsByNameAndCursor( - stringToken(tokens[0]), cursorPosition); + ACSymbol*[] symbols; + if (tokens[0] == tok!"." && tokens.length > 1) + { + tokens = tokens[1 .. $]; + Log.info("Looking for ", stringToken(tokens[0]), " at global scope"); + symbols = completionScope.getSymbolsAtGlobalScope(stringToken(tokens[0])); + } + else + symbols = completionScope.getSymbolsByNameAndCursor(stringToken(tokens[0]), cursorPosition); + if (symbols.length == 0) { Log.error("Could not find declaration of ", stringToken(tokens[0]),