extragear/sdk/kdevplatform/language/backgroundparser

Milian Wolff mail at milianw.de
Sat Feb 20 16:12:01 UTC 2010


SVN commit 1093315 by mwolff:

Introduce new cleanupSmartRevision() method which must be called before
exiting the run() method if contentsAvailableFromEditor() returned true.

I could sadly not find a better place to do that in the ThreadWeaver API
which would not require it to be called manually. Now every language ParseJob
has to care about that themselfes - a PITA but neccessary. abortJob() will
cleanup the revision automatically.

So to each language plugin developer:

if ( abortRequested() ) return abortJob();

void ::run() { ... /* everything else */ cleanupSmartRevision(); }

CCMAIL: kdevelop-devel at kdevelop.org
CCMAIL: zwabel at googlemail.com

 M  +22 -10    parsejob.cpp  
 M  +9 -0      parsejob.h  


--- trunk/extragear/sdk/kdevplatform/language/backgroundparser/parsejob.cpp #1093314:1093315
@@ -105,21 +105,16 @@
 
 ParseJob::~ParseJob()
 {
-    //Here we release the revision
-    EditorIntegrator editor;
-    editor.setCurrentUrl(d->document);
-    
-    if(KDevelop::LockedSmartInterface smart = editor.smart()) {
-        smart->releaseRevision(d->revisionToken);
-        smart->clearRevision();
-        ///@todo We need to know here what the currently used revision is, and assert that it still is being used
+    if ( d->revisionToken != -1 ) {
+        kWarning() << "You must call cleanupSmartRevision() when your run() method has finished!";
+        cleanupSmartRevision();
     }
-    
+
     typedef QPointer<QObject> QObjectPointer;
     foreach(const QObjectPointer &p, d->notify)
         if(p)
             QMetaObject::invokeMethod(p, "updateReady", Qt::QueuedConnection, Q_ARG(KDevelop::IndexedString, d->document), Q_ARG(KDevelop::ReferencedTopDUContext, d->duContext));
-    
+
     delete d;
 }
 
@@ -197,6 +192,22 @@
     return true;
 }
 
+void ParseJob::cleanupSmartRevision()
+{
+    if ( d->revisionToken != -1 ) {
+        //Here we release the revision
+        EditorIntegrator editor;
+        editor.setCurrentUrl(d->document);
+
+        if(KDevelop::LockedSmartInterface smart = editor.smart()) {
+            smart->releaseRevision(d->revisionToken);
+            smart->clearRevision();
+            d->revisionToken = -1;
+            ///@todo We need to know here what the currently used revision is, and assert that it still is being used
+        }
+    }
+}
+
 int ParseJob::revisionToken() const
 {
     return d->revisionToken;
@@ -278,6 +289,7 @@
 {
     d->aborted = true;
     setFinished(true);
+    cleanupSmartRevision();
 }
 
 void ParseJob::setNotifyWhenReady(QList<QPointer<QObject> > notify) {
--- trunk/extragear/sdk/kdevplatform/language/backgroundparser/parsejob.h #1093314:1093315
@@ -59,9 +59,18 @@
      * be made to the changedRanges().
      * You can then just call KTextEditor::SmartRange::text() on each of the changedRanges().
      * Or, you can parse the whole document, the text of which is available from contentsFromEditor().
+     *
+     * @NOTE: When this is called, make sure you call @p cleanupSmartRevision() properly.
      */
     Q_SCRIPTABLE bool contentsAvailableFromEditor();
 
+    /**
+     * Cleanup SmartRange revision after the job has run. 
+     * You must call this before exiting your @p run() method.
+     * @p abortJob() will call this automatically.
+     */
+    virtual void cleanupSmartRevision();
+
     /// Retrieve the contents of the file from the currently open editor.
     /// Ensure it is loaded by calling editorLoaded() first.
     /// The editor integrator seamlessly saves the revision token and applies it




More information about the KDevelop-devel mailing list