~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to phpparsejob.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-12-20 14:59:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101220145902-a6cmovse1qmue52p
Tags: 1.1.80-0ubuntu1
* New upstream release
* Build-dep on kdevplatform >= 1.1.80
* Get rid of l10n packages, not relevant in Ubuntu, put locale files into main package

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <QReadWriteLock>
23
23
 
24
24
#include <ktexteditor/document.h>
25
 
#include <ktexteditor/smartinterface.h>
26
25
 
27
26
#include <kdebug.h>
28
27
#include <klocale.h>
94
93
            if (!file->needsUpdate() && file->featuresSatisfied(minimumFeatures())) {
95
94
                kDebug() << "Already up to date" << document().str();
96
95
                setDuChain(file->topContext());
 
96
                if (php() && php()->codeHighlighting()
 
97
                    && ICore::self()->languageController()->backgroundParser()->trackerForUrl(document()))
 
98
                {
 
99
                    php()->codeHighlighting()->highlightDUChain(duChain());
 
100
                }
97
101
                return;
98
102
            }
99
103
            break;
102
106
 
103
107
    kDebug() << "parsing" << document().str();
104
108
 
105
 
    bool readFromDisk = !contentsAvailableFromEditor();
 
109
    KDevelop::ProblemPointer p = readContents();
 
110
    if (p) {
 
111
        //TODO: associate problem with topducontext
 
112
        return abortJob();;
 
113
    }
106
114
 
107
115
    ParseSession session;
108
 
 
109
 
    QString fileName = document().str();
110
 
 
111
 
    if (readFromDisk) {
112
 
        session.readFile(fileName);
113
 
    } else {
114
 
        session.setContents(contentsFromEditor());
115
 
        session.setCurrentDocument(document().str());
116
 
    }
 
116
    //TODO: support different charsets
 
117
    session.setContents(QString::fromUtf8(contents().contents));
 
118
    session.setCurrentDocument(document());
117
119
 
118
120
    // 2) parse
119
121
    StartAst* ast = 0;
181
183
            return abortJob();
182
184
        }
183
185
 
184
 
        if (editor.smart() && KDevelop::EditorIntegrator::documentForUrl(document())) {
185
 
            if (php() && php()->codeHighlighting()) {
186
 
                php()->codeHighlighting()->highlightDUChain(chain);
187
 
            }
188
 
        }
189
 
 
190
186
        if (abortRequested()) {
191
187
            return abortJob();
192
188
        }
199
195
 
200
196
        chain->setFeatures(newFeatures);
201
197
        ParsingEnvironmentFilePointer file = chain->parsingEnvironmentFile();
202
 
 
203
 
        QFileInfo fileInfo(fileName);
204
 
        QDateTime lastModified = fileInfo.lastModified();
205
 
        if (readFromDisk) {
206
 
            file->setModificationRevision(KDevelop::ModificationRevision(lastModified));
207
 
        } else {
208
 
            file->setModificationRevision(KDevelop::ModificationRevision(lastModified, revisionToken()));
209
 
        }
210
 
 
 
198
        file->setModificationRevision(contents().modification);
211
199
        DUChain::self()->updateContextEnvironment( chain->topContext(), file.data() );
 
200
 
 
201
        if (php() && php()->codeHighlighting()
 
202
            && ICore::self()->languageController()->backgroundParser()->trackerForUrl(document()))
 
203
        {
 
204
            php()->codeHighlighting()->highlightDUChain(chain);
 
205
        }
212
206
    } else {
213
207
        ReferencedTopDUContext top;
 
208
        DUChainWriteLocker lock;
214
209
        {
215
 
            DUChainReadLocker lock(DUChain::lock());
216
210
            top = DUChain::self()->chainForDocument(document());
217
211
        }
218
212
        if (top) {
219
 
            DUChainWriteLocker lock(DUChain::lock());
220
213
            ///NOTE: if we clear the imported parent contexts, autocompletion of built-in PHP stuff won't work!
221
214
            //top->clearImportedParentContexts();
222
215
            top->parsingEnvironmentFile()->clearModificationRevisions();
223
216
            top->clearProblems();
224
217
        } else {
225
 
            DUChainWriteLocker lock(DUChain::lock());
226
218
            ParsingEnvironmentFile *file = new ParsingEnvironmentFile(document());
227
219
            /// Indexed string for 'Php', identifies environment files from this language plugin
228
220
            static const IndexedString phpLangString("Php");
229
221
            file->setLanguage(phpLangString);
230
 
            top = new TopDUContext(document(), SimpleRange(SimpleCursor(0, 0), SimpleCursor(INT_MAX, INT_MAX)), file);
 
222
            top = new TopDUContext(document(), RangeInRevision(0, 0, INT_MAX, INT_MAX), file);
231
223
            DUChain::self()->addDocumentChain(top);
232
224
        }
 
225
        foreach(const ProblemPointer &p, session.problems()) {
 
226
            top->addProblem(p);
 
227
        }
233
228
        setDuChain(top);
234
 
        foreach(const ProblemPointer &p, session.problems()) {
235
 
            DUChainWriteLocker lock(DUChain::lock());
236
 
            top->addProblem(p);
237
 
        }
238
229
        kDebug() << "===Failed===" << document().str();
239
230
    }
240
 
 
241
 
    cleanupSmartRevision();
242
231
}
243
232
 
244
233
void ParseJob::setParentJob(ParseJob *job)
263
252
    p->setSource(source);
264
253
    p->setSeverity(severity);
265
254
    p->setDescription(description);
266
 
    p->setFinalLocation(DocumentRange(document().str(), editor->findRange(node).textRange()));
 
255
    p->setFinalLocation(DocumentRange(document(), editor->findRange(node).castToSimpleRange()));
267
256
    kDebug() << p->description();
268
257
    return p;
269
258
}