diff --git a/duchain/declarationbuilder.cpp b/duchain/declarationbuilder.cpp index 101299abb9077566cfb8e28911906e707379da45..d0f8772894f8b30112e54f5bedc166392e01ccaa 100644 --- a/duchain/declarationbuilder.cpp +++ b/duchain/declarationbuilder.cpp @@ -651,7 +651,7 @@ void DeclarationBuilder::declareComponentSubclass(QmlJS::AST::UiObjectInitialize DUChainWriteLocker lock; ClassDeclaration* decl = openDeclaration( currentContext()->type() == DUContext::Global ? - QualifiedIdentifier(m_session->urlBaseName()) : + QualifiedIdentifier(m_session->moduleName()) : name, RangeInRevision() ); diff --git a/duchain/parsesession.cpp b/duchain/parsesession.cpp index fdceb04dc20c2df9065a5d84fd854c70d4f0e802..9ef32a020724b6f33968680a6d9c103446c58854 100644 --- a/duchain/parsesession.cpp +++ b/duchain/parsesession.cpp @@ -72,6 +72,16 @@ ParseSession::ParseSession(const IndexedString& url, const QString& contents, in m_doc->setSource(contents); m_doc->parse(); Q_ASSERT(isSorted(m_doc->engine()->comments())); + + // Parse the module name and the version of url (this is used only when the file + // is a QML module, but doesn't break for JavaScript files) + QString baseName = QString::fromUtf8(m_url.byteArray()) + .section('/', -1, -1) // Base name + .section('.', 0, -2); // Without extension + QStringList nameAndVersion = baseName.split('_'); + + m_baseNameWithoutVersion = nameAndVersion.at(0); + m_version = (nameAndVersion.count() > 1 ? nameAndVersion.at(1) : QLatin1String("1.0")); } bool ParseSession::isParsedCorrectly() const @@ -89,11 +99,14 @@ IndexedString ParseSession::url() const return m_url; } -QString ParseSession::urlBaseName() const +QString ParseSession::moduleName() const + { + return m_baseNameWithoutVersion; +} + +QString ParseSession::moduleVersion() const { - return QString::fromUtf8(m_url.byteArray()) - .section('/', -1, -1) // Base name - .section('.', 0, -2); // Without its extension + return m_version; } QList ParseSession::problems() const diff --git a/duchain/parsesession.h b/duchain/parsesession.h index c4f958c29a33b08b3c099bf6adc7d778bb511bdc..d7432539f6ef332e7cd8368a2dfebb97f80748b1 100644 --- a/duchain/parsesession.h +++ b/duchain/parsesession.h @@ -66,9 +66,14 @@ public: KDevelop::IndexedString url() const; /** - * @return the basename, without its extension, of url() + * @return The module name of this file ("/foo/QtQuick_1.0.qml" yields "QtQuick") */ - QString urlBaseName() const; + QString moduleName() const; + + /** + * @return The version of this file, or QString if none ("QtQuick_1.0.qml" yields "1.0") + */ + QString moduleVersion() const; /** * @return true if the document was properly parsed, false otherwise. @@ -158,6 +163,8 @@ public: private: KDevelop::IndexedString m_url; + QString m_baseNameWithoutVersion; + QString m_version; QmlJS::Document::MutablePtr m_doc; int m_ownPriority;