Skip to content
Snippets Groups Projects
Commit 5cff896f authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Get rid off QmlJSEditor::m_idRevisions & co.

parent e622d706
No related branches found
No related tags found
No related merge requests found
...@@ -125,13 +125,14 @@ bool shouldInsertMatchingText(const QTextCursor &tc) ...@@ -125,13 +125,14 @@ bool shouldInsertMatchingText(const QTextCursor &tc)
class FindIdDeclarations: protected Visitor class FindIdDeclarations: protected Visitor
{ {
public: public:
typedef QMap<QString, QList<AST::SourceLocation> > Result; typedef QHash<QString, QList<AST::SourceLocation> > Result;
Result operator()(AST::Node *node) Result operator()(Document::Ptr doc)
{ {
_ids.clear(); _ids.clear();
_maybeIds.clear(); _maybeIds.clear();
accept(node); if (doc && doc->qmlProgram())
doc->qmlProgram()->accept(this);
return _ids; return _ids;
} }
...@@ -428,6 +429,14 @@ protected: ...@@ -428,6 +429,14 @@ protected:
} // end of anonymous namespace } // end of anonymous namespace
int SemanticInfo::revision() const
{
if (document)
return document->documentRevision();
return 0;
}
QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditor *editor) QmlJSEditorEditable::QmlJSEditorEditable(QmlJSTextEditor *editor)
: BaseTextEditorEditable(editor) : BaseTextEditorEditable(editor)
{ {
...@@ -443,7 +452,6 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : ...@@ -443,7 +452,6 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) :
m_modelManager(0), m_modelManager(0),
m_typeSystem(0) m_typeSystem(0)
{ {
m_idsRevision = -1;
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
setMarksVisible(true); setMarksVisible(true);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
...@@ -531,10 +539,6 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc) ...@@ -531,10 +539,6 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
return; return;
} }
FindIdDeclarations updateIds;
m_idsRevision = document()->revision();
m_ids = updateIds(doc->qmlProgram());
if (doc->ast()) { if (doc->ast()) {
// got a correctly parsed (or recovered) file. // got a correctly parsed (or recovered) file.
...@@ -543,6 +547,11 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc) ...@@ -543,6 +547,11 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc)
SemanticInfo sem; SemanticInfo sem;
sem.document = doc; sem.document = doc;
sem.ranges = createRanges(document(), doc); sem.ranges = createRanges(document(), doc);
// Refresh the ids
FindIdDeclarations updateIds;
sem.idLocations = updateIds(doc);
m_semanticInfo = sem; m_semanticInfo = sem;
if (doc->isParsedCorrectly()) { if (doc->isParsedCorrectly()) {
...@@ -630,7 +639,7 @@ void QmlJSTextEditor::updateUses() ...@@ -630,7 +639,7 @@ void QmlJSTextEditor::updateUses()
void QmlJSTextEditor::updateUsesNow() void QmlJSTextEditor::updateUsesNow()
{ {
if (document()->revision() != m_idsRevision) { if (document()->revision() != m_semanticInfo.revision()) {
updateUses(); updateUses();
return; return;
} }
...@@ -638,7 +647,7 @@ void QmlJSTextEditor::updateUsesNow() ...@@ -638,7 +647,7 @@ void QmlJSTextEditor::updateUsesNow()
m_updateUsesTimer->stop(); m_updateUsesTimer->stop();
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
foreach (const AST::SourceLocation &loc, m_ids.value(wordUnderCursor())) { foreach (const AST::SourceLocation &loc, m_semanticInfo.idLocations.value(wordUnderCursor())) {
if (! loc.isValid()) if (! loc.isValid())
continue; continue;
...@@ -673,7 +682,7 @@ void QmlJSTextEditor::renameIdUnderCursor() ...@@ -673,7 +682,7 @@ void QmlJSTextEditor::renameIdUnderCursor()
if (ok) { if (ok) {
Utils::ChangeSet changeSet; Utils::ChangeSet changeSet;
foreach (const AST::SourceLocation &loc, m_ids.value(id)) { foreach (const AST::SourceLocation &loc, m_semanticInfo.idLocations.value(id)) {
changeSet.replace(loc.offset, loc.length, newId); changeSet.replace(loc.offset, loc.length, newId);
} }
...@@ -849,7 +858,7 @@ void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e) ...@@ -849,7 +858,7 @@ void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e)
} }
const QString id = wordUnderCursor(); const QString id = wordUnderCursor();
const QList<AST::SourceLocation> &locations = m_ids.value(id); const QList<AST::SourceLocation> &locations = m_semanticInfo.idLocations.value(id);
if (! locations.isEmpty()) { if (! locations.isEmpty()) {
menu->addSeparator(); menu->addSeparator();
QAction *a = menu->addAction(tr("Rename id '%1'...").arg(id)); QAction *a = menu->addAction(tr("Rename id '%1'...").arg(id));
...@@ -1013,3 +1022,4 @@ QString QmlJSTextEditor::insertParagraphSeparator(const QTextCursor &) const ...@@ -1013,3 +1022,4 @@ QString QmlJSTextEditor::insertParagraphSeparator(const QTextCursor &) const
{ {
return QLatin1String("}\n"); return QLatin1String("}\n");
} }
...@@ -107,9 +107,12 @@ class SemanticInfo ...@@ -107,9 +107,12 @@ class SemanticInfo
public: public:
SemanticInfo() {} SemanticInfo() {}
int revision() const;
public: // attributes public: // attributes
QmlJS::Document::Ptr document; QmlJS::Document::Ptr document;
QList<Range> ranges; QList<Range> ranges;
QHash<QString, QList<QmlJS::AST::SourceLocation> > idLocations;
}; };
class QmlJSTextEditor : public TextEditor::BaseTextEditor class QmlJSTextEditor : public TextEditor::BaseTextEditor
...@@ -173,8 +176,6 @@ private: ...@@ -173,8 +176,6 @@ private:
QTimer *m_updateUsesTimer; QTimer *m_updateUsesTimer;
QComboBox *m_methodCombo; QComboBox *m_methodCombo;
QList<Declaration> m_declarations; // ### remove me QList<Declaration> m_declarations; // ### remove me
QMap<QString, QList<QmlJS::AST::SourceLocation> > m_ids; // ### remove me
int m_idsRevision; // ### remove me
QmlModelManagerInterface *m_modelManager; QmlModelManagerInterface *m_modelManager;
QmlJS::TypeSystem *m_typeSystem; QmlJS::TypeSystem *m_typeSystem;
QTextCharFormat m_occurrencesFormat; QTextCharFormat m_occurrencesFormat;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment