diff --git a/navigation/railsdataprovider.cpp b/navigation/railsdataprovider.cpp index e50fa41..be9ce5d 100644 --- a/navigation/railsdataprovider.cpp +++ b/navigation/railsdataprovider.cpp @@ -1,172 +1,174 @@ /* * This file is part of KDevelop * * Copyright 2010 Alexander Dymo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "railsdataprovider.h" #include #include #include #include #include #include #include #include #include "railsswitchers.h" namespace Ruby { RailsQuickOpenData::RailsQuickOpenData(const RailsQuickOpenItem& item, const QString &explanation) : QuickOpenDataBase(), m_item(item), m_explanation(explanation) { } QString RailsQuickOpenData::text() const { KUrl u(m_item.url.url()); return KUrl::relativeUrl( RailsSwitchers::findRailsRoot(m_item.url.url()), u ); } QString RailsQuickOpenData::htmlDescription() const { return "" + m_explanation + ' ' + m_item.originUrl.fileName() + ""; } -bool RailsQuickOpenData::execute(QString& filterText) +/* TODO: to adymo from mssola: what is this parameter ? */ +bool RailsQuickOpenData::execute(QString & filterText) { + Q_UNUSED(filterText); KDevelop::ICore::self()->documentController()->openDocument( m_item.url ); return true; } bool RailsQuickOpenData::isExpandable() const { return false; } QWidget* RailsQuickOpenData::expandingWidget() const { return KDevelop::QuickOpenDataBase::expandingWidget(); } QIcon RailsQuickOpenData::icon() const { return KDevelop::QuickOpenDataBase::icon(); } QList RailsQuickOpenData::highlighting() const { QTextCharFormat boldFormat; boldFormat.setFontWeight(QFont::Bold); QTextCharFormat normalFormat; QString txt = text(); QList ret; int fileNameLength = m_item.url.fileName().length(); ret << 0; ret << txt.length() - fileNameLength; ret << QVariant(normalFormat); ret << txt.length() - fileNameLength; ret << fileNameLength; ret << QVariant(boldFormat); return ret; } RailsDataProvider::RailsDataProvider(Ruby::RailsDataProvider::Kind kind): m_kind(kind) { reset(); } QList RailsDataProvider::data(uint start, uint end) const { if( end > (uint)Base::filteredItems().count() ) end = Base::filteredItems().count(); QList ret; for( uint a = start; a < end; a++ ) { RailsQuickOpenItem f( Base::filteredItems()[a] ); QString dataExplanation = m_kind == Views ? i18n("View for:") : i18n("Test for:"); ret << KDevelop::QuickOpenDataPointer( new RailsQuickOpenData( Base::filteredItems()[a], dataExplanation ) ); } return ret; } void RailsDataProvider::enableData(const QStringList& items, const QStringList& scopes) { KDevelop::QuickOpenDataProviderBase::enableData(items, scopes); } uint RailsDataProvider::itemCount() const { return Base::filteredItems().count(); } void RailsDataProvider::reset() { Base::clearFilter(); KDevelop::IDocument *activeDocument = KDevelop::ICore::self()->documentController()->activeDocument(); QList items; KUrl::List urlsToSwitch; if (m_kind == Views) urlsToSwitch = RailsSwitchers::viewsToSwitch(); else if (m_kind == Tests) urlsToSwitch = RailsSwitchers::testsToSwitch(); foreach (const KUrl &url, urlsToSwitch) { RailsQuickOpenItem item; item.url = url; if (activeDocument) item.originUrl = activeDocument->url(); items << item; } setItems(items); } QStringList RailsDataProvider::scopes() { return QStringList() << "Project"; } void RailsDataProvider::setFilterText(const QString& text) { Base::setFilter( text.split('/'), QChar('/') ); } QString RailsDataProvider::itemText(const RailsQuickOpenItem& data) const { return data.url.fileName(); } QSet< KDevelop::IndexedString > RailsDataProvider::files() const { return QSet< KDevelop::IndexedString >(); } } diff --git a/parsejob.cpp b/parsejob.cpp index 5b6ba52..a5b8a39 100644 --- a/parsejob.cpp +++ b/parsejob.cpp @@ -1,183 +1,171 @@ /* This file is part of KDevelop * * Copyright 2008-2010 Alexander Dymo * Copyright 2011 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* TODO: Clean This mess */ -#include "parsejob.h" - -#include -#include -#include -#include - -#include "Thread.h" - -#include -#include -#include #include - -#include -#include - -#include +#include #include - -#include -#include -#include -#include -#include -#include - #include +#include "parsejob.h" #include "rubylanguagesupport.h" -// #include "parser/parser.h" #include -// #include -#include "duchain/declarationbuilder.h" -#include "duchain/editorintegrator.h" +#include +#include + using namespace KDevelop; namespace Ruby { ParseJob::ParseJob(const KUrl & url, RubyLanguageSupport * parent) : KDevelop::ParseJob(url) , m_parser (new RubyParser) , m_lastAst(NULL) + , m_top (NULL) { m_parent = parent; m_url = url; } ParseJob::~ParseJob() { /* There's nothing to do here */ } RubyLanguageSupport * ParseJob::ruby() const { return RubyLanguageSupport::self(); } void ParseJob::run() { //Happens during shutdown if (!ruby()) return abortJob(); if (abortRequested()) return abortJob(); KDevelop::UrlParseLock urlLock(document()); { DUChainReadLocker lock(DUChain::lock()); bool needsUpdate = true; static const IndexedString langString("Ruby"); foreach(const ParsingEnvironmentFilePointer & file, DUChain::self()->allEnvironmentFiles(document())) { if (file->language() != langString) continue; if (file->needsUpdate()) { needsUpdate = true; break; } else needsUpdate = false; } if (!(minimumFeatures() & TopDUContext::ForceUpdate || minimumFeatures() & Resheduled) && !needsUpdate) { kDebug() << "Already up to date" << document().str(); return; } } QReadLocker parseLock(ruby()->language()->parseLock()); KDevelop::ProblemPointer p = readContents(); if (p || abortRequested()) return abortJob(); /* * NOTE: Although the parser can retrieve the contents on its own, * it's better to use contents().contents because this way the contents * are converted in utf8 format always. */ m_parser->setContents(contents().contents); m_parser->setCurrentDocument(m_url); - parse(); - - if ( abortRequested() ) - return abortJob(); -} - -void ParseJob::parse() -{ - m_parser->freeAst(m_lastAst); /* TODO: It may go after the builder */ m_lastAst = m_parser->parse(); +/* TODO: I'm not sure about the code below ;) + KDevelop::ReferencedTopDUContext top; + { + KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock()); + top = KDevelop::DUChain::self()->chainForDocument(document()); + } + if (top) { + kDebug() << "re-compiling" << document().str(); + KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock()); + top->clearImportedParentContexts(); + top->parsingEnvironmentFile()->clearModificationRevisions(); + top->clearProblems(); + } else + kDebug() << "compiling" << document().str();*/ if (m_lastAst != NULL) { - kDebug() << "Everything is fine " << m_lastAst->tree->kind << endl; + if (abortRequested()) + return abortJob(); + + EditorIntegrator editor; + DeclarationBuilder builder(&editor); +// m_top = builder.build(document(), m_lastAst, m_top); + m_parser->freeAst(m_lastAst); + setDuChain(m_top); + + DUChainWriteLocker lock(DUChain::lock()); + m_top->setFeatures(minimumFeatures()); + KDevelop::ParsingEnvironmentFilePointer file = m_top->parsingEnvironmentFile(); + file->setModificationRevision(contents().modification); + KDevelop::DUChain::self()->updateContextEnvironment(m_top->topContext(), file.data()); + kDebug() << "**** Parsing Succeeded ****"; + + /* TODO: Here will go highlighting handling ;) */ } else { - kDebug() << "Failed\n"; - foreach (ProblemPointer p, m_parser->m_problems) { - kDebug() << p->range(); - kDebug() << p->description(); + kWarning() << "**** Parsing Failed ****"; + DUChainWriteLocker lock; + m_top = DUChain::self()->chainForDocument(document()); + if ( m_top ) { + m_top->parsingEnvironmentFile()->clearModificationRevisions(); + m_top->clearProblems(); + } + else { + ParsingEnvironmentFile * file = new ParsingEnvironmentFile(document()); + static const IndexedString langString("Ruby"); + file->setLanguage(langString); + m_top = new TopDUContext(document(), RangeInRevision(0, 0, INT_MAX, INT_MAX), file); + DUChain::self()->addDocumentChain(m_top); } + + setDuChain(m_top); } -// KDevelop::ReferencedTopDUContext top; -// { -// KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock()); -// top = KDevelop::DUChain::self()->chainForDocument(document()); -// } -// if (top) { -// kDebug() << "re-compiling" << document().str(); -// KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock()); -// top->clearImportedParentContexts(); -// top->parsingEnvironmentFile()->clearModificationRevisions(); -// top->clearProblems(); -// } else -// kDebug() << "compiling" << document().str(); -// -// QReadLocker parseLock(ruby()->language()->parseLock()); -// -// EditorIntegrator editor; -// editor.setUrl(document()); -// DeclarationBuilder builder; -// builder.setEditor(&editor); -// top = builder.build(document(), programAST, top); -// delete programAST; -// -// setDuChain(top); -// -// KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock()); -// -// top->setFeatures(minimumFeatures()); -// KDevelop::ParsingEnvironmentFilePointer file = top->parsingEnvironmentFile(); -// -// file->setModificationRevision(contents().modification); -// KDevelop::DUChain::self()->updateContextEnvironment( top->topContext(), file.data() ); + DUChainWriteLocker lock(DUChain::lock()); + foreach (ProblemPointer p, m_parser->m_problems) { + kDebug() << "Added problem to context"; + m_top->addProblem(p); + } + setDuChain(m_top); + + if (abortRequested()) + return abortJob(); } -} // end of namespace ruby +} // End of namespace ruby + #include "parsejob.moc" + diff --git a/parsejob.h b/parsejob.h index 262102c..685d609 100644 --- a/parsejob.h +++ b/parsejob.h @@ -1,87 +1,82 @@ /* This file is part of KDevelop * * Copyright 2008-2010 Alexander Dymo * Copyright (C) 2011 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef RUBY_PARSEJOB_H #define RUBY_PARSEJOB_H #include #include #include class RubyLanguageSupport; namespace Ruby { class RubyParser; class ParseJob : public KDevelop::ParseJob { Q_OBJECT public: enum { Resheduled = KDevelop::TopDUContext::LastFeature }; /** * Constructor. * * @param url the url of the file to parse. * @param parent the RubyLanguageSupport this ParseJob is parented to. */ ParseJob(const KUrl & url, RubyLanguageSupport * parent); /** * Destructor. */ virtual ~ParseJob(); protected: /** * Runs this ParseJob. */ virtual void run(); private: /** * @return static accessor to avoid casting. */ RubyLanguageSupport * ruby() const; - /** - * @internal Called by the run() method. It's used to do the - * parsing magic. - */ - void parse(); - private: const RubyLanguageSupport * m_parent; KUrl m_url; RubyParser * m_parser; RubyAst * m_lastAst; + KDevelop::ReferencedTopDUContext m_top; }; -} // end of namespace ruby +} // End of namespace ruby #endif