From 123607ad70e62ad8caa9bdfe705a7aa394778679 Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Fri, 25 Jun 2010 13:01:55 +0200
Subject: [PATCH] QmlJS: Make variables in imported JS documents show up in
 completion.

Filtering them out has long since become unnecessary. It was used back
when JS files were sourced from Script elements - there they'd only
make the functions available. Now functions and variables are imported.

Task-number: QTCREATORBUG-1735
Reviewed-by: Erik Verbruggen
---
 src/libs/qmljs/qmljsinterpreter.cpp             | 15 +--------------
 src/libs/qmljs/qmljsinterpreter.h               | 10 ----------
 src/libs/qmljs/qmljslink.cpp                    |  2 --
 src/plugins/qmljseditor/qmljscodecompletion.cpp |  4 +---
 4 files changed, 2 insertions(+), 29 deletions(-)

diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp
index a83f24141d9..c7f9b5cba50 100644
--- a/src/libs/qmljs/qmljsinterpreter.cpp
+++ b/src/libs/qmljs/qmljsinterpreter.cpp
@@ -1385,7 +1385,6 @@ QList<const ObjectValue *> ScopeChain::all() const
 
 Context::Context(Engine *engine)
     : _engine(engine),
-      _lookupMode(JSLookup),
       _qmlScopeObjectIndex(-1),
       _qmlScopeObjectSet(false)
 {
@@ -1410,16 +1409,6 @@ ScopeChain &Context::scopeChain()
     return _scopeChain;
 }
 
-Context::LookupMode Context::lookupMode() const
-{
-    return _lookupMode;
-}
-
-void Context::setLookupMode(LookupMode lookupMode)
-{
-    _lookupMode = lookupMode;
-}
-
 const ObjectValue *Context::typeEnvironment(const QmlJS::Document *doc) const
 {
     return _typeEnvironments.value(doc->fileName(), 0);
@@ -1437,9 +1426,7 @@ const Value *Context::lookup(const QString &name)
         const ObjectValue *scope = scopes.at(index);
 
         if (const Value *member = scope->lookupMember(name, this)) {
-            if (_lookupMode == JSLookup || ! dynamic_cast<const ASTVariableReference *>(member)) {
-                return member;
-            }
+            return member;
         }
     }
 
diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h
index 7ce3fcffba6..b1aed525380 100644
--- a/src/libs/qmljs/qmljsinterpreter.h
+++ b/src/libs/qmljs/qmljsinterpreter.h
@@ -270,12 +270,6 @@ private:
 
 class QMLJS_EXPORT Context
 {
-public:
-    enum LookupMode {
-        JSLookup,
-        QmlLookup
-    };
-
 public:
     Context(Engine *engine);
     ~Context();
@@ -284,9 +278,6 @@ public:
     const ScopeChain &scopeChain() const;
     ScopeChain &scopeChain();
 
-    LookupMode lookupMode() const;
-    void setLookupMode(LookupMode lookupMode);
-
     const ObjectValue *typeEnvironment(const Document *doc) const;
     void setTypeEnvironment(const Document *doc, const ObjectValue *typeEnvironment);
 
@@ -307,7 +298,6 @@ private:
     typedef QHash<QString, const Value *> Properties;
 
     Engine *_engine;
-    LookupMode _lookupMode;
     QHash<const ObjectValue *, Properties> _properties;
     QHash<QString, const ObjectValue *> _typeEnvironments;
     QSet<QString> _documentsImportingPlugins;
diff --git a/src/libs/qmljs/qmljslink.cpp b/src/libs/qmljs/qmljslink.cpp
index e562cc498d4..d9325b9d1fd 100644
--- a/src/libs/qmljs/qmljslink.cpp
+++ b/src/libs/qmljs/qmljslink.cpp
@@ -54,8 +54,6 @@ void Link::initializeScopeChain()
     QHash<Document *, ScopeChain::QmlComponentChain *> componentScopes;
 
     if (_doc->qmlProgram()) {
-        _context->setLookupMode(Context::QmlLookup);
-
         scopeChain.qmlComponentScope.clear();
         componentScopes.insert(_doc.data(), &scopeChain.qmlComponentScope);
         makeComponentChain(_doc, &scopeChain.qmlComponentScope, &componentScopes);
diff --git a/src/plugins/qmljseditor/qmljscodecompletion.cpp b/src/plugins/qmljseditor/qmljscodecompletion.cpp
index e30f3554f8b..c26c8ccc612 100644
--- a/src/plugins/qmljseditor/qmljscodecompletion.cpp
+++ b/src/plugins/qmljseditor/qmljscodecompletion.cpp
@@ -208,9 +208,7 @@ public:
 private:
     void insertProperty(const QString &name, const Interpreter::Value *value)
     {
-        if (_context->lookupMode() == Interpreter::Context::JSLookup ||
-                ! dynamic_cast<const Interpreter::ASTVariableReference *>(value))
-            _properties.insert(name, value);
+        _properties.insert(name, value);
     }
 
     virtual bool processProperty(const QString &name, const Interpreter::Value *value)
-- 
GitLab