Changeset View
Changeset View
Standalone View
Standalone View
language/codecompletion/codecompletionmodel.cpp
Show First 20 Lines • Show All 167 Lines • ▼ Show 20 Line(s) | 164 | { | |||
---|---|---|---|---|---|
168 | DUChainReadLocker lock(DUChain::lock(), 400); | 168 | DUChainReadLocker lock(DUChain::lock(), 400); | ||
169 | if( !lock.locked() ) { | 169 | if( !lock.locked() ) { | ||
170 | qCDebug(LANGUAGE) << "could not lock du-chain in time"; | 170 | qCDebug(LANGUAGE) << "could not lock du-chain in time"; | ||
171 | return; | 171 | return; | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | TopDUContext* top = DUChainUtils::standardContextForUrl( url ); | 174 | TopDUContext* top = DUChainUtils::standardContextForUrl( url ); | ||
175 | if(!top) { | 175 | if(!top) { | ||
176 | qCDebug(LANGUAGE) << "================== NO CONTEXT FOUND ======================="; | ||||
177 | beginResetModel(); | ||||
178 | m_completionItems.clear(); | ||||
179 | m_navigationWidgets.clear(); | ||||
180 | endResetModel(); | ||||
181 | | ||||
182 | qCDebug(LANGUAGE) << "Completion invoked for unknown context. Document:" << url << ", Known documents:" << DUChain::self()->documents(); | ||||
183 | | ||||
176 | return; | 184 | return; | ||
177 | } | 185 | } | ||
186 | | ||||
178 | setCurrentTopContext(TopDUContextPointer(top)); | 187 | setCurrentTopContext(TopDUContextPointer(top)); | ||
179 | 188 | | |||
180 | RangeInRevision rangeInRevision = top->transformToLocalRevision(KTextEditor::Range(range)); | 189 | RangeInRevision rangeInRevision = top->transformToLocalRevision(KTextEditor::Range(range)); | ||
181 | 190 | | |||
182 | if (top) { | | |||
183 | qCDebug(LANGUAGE) << "completion invoked for context" << (DUContext*)top; | 191 | qCDebug(LANGUAGE) << "completion invoked for context" << (DUContext*)top; | ||
184 | 192 | | |||
185 | if( top->parsingEnvironmentFile() && top->parsingEnvironmentFile()->modificationRevision() != ModificationRevision::revisionForFile(IndexedString(url.toString())) ) { | 193 | if( top->parsingEnvironmentFile() && top->parsingEnvironmentFile()->modificationRevision() != ModificationRevision::revisionForFile(IndexedString(url.toString())) ) { | ||
186 | qCDebug(LANGUAGE) << "Found context is not current. Its revision is " /*<< top->parsingEnvironmentFile()->modificationRevision() << " while the document-revision is " << ModificationRevision::revisionForFile(IndexedString(url.toString()))*/; | 194 | qCDebug(LANGUAGE) << "Found context is not current. Its revision is " /*<< top->parsingEnvironmentFile()->modificationRevision() << " while the document-revision is " << ModificationRevision::revisionForFile(IndexedString(url.toString()))*/; | ||
187 | } | 195 | } | ||
188 | 196 | | |||
189 | DUContextPointer thisContext; | 197 | DUContextPointer thisContext; | ||
190 | { | 198 | { | ||
191 | qCDebug(LANGUAGE) << "apply specialization:" << range.start(); | 199 | qCDebug(LANGUAGE) << "apply specialization:" << range.start(); | ||
192 | thisContext = SpecializationStore::self().applySpecialization(top->findContextAt(rangeInRevision.start), top); | 200 | thisContext = SpecializationStore::self().applySpecialization(top->findContextAt(rangeInRevision.start), top); | ||
193 | 201 | | |||
194 | if ( thisContext ) { | 202 | if ( thisContext ) { | ||
195 | qCDebug(LANGUAGE) << "after specialization:" << thisContext->localScopeIdentifier().toString() << thisContext->rangeInCurrentRevision(); | 203 | qCDebug(LANGUAGE) << "after specialization:" << thisContext->localScopeIdentifier().toString() << thisContext->rangeInCurrentRevision(); | ||
196 | } | 204 | } else { | ||
197 | | ||||
198 | if(!thisContext) | | |||
199 | thisContext = top; | 205 | thisContext = top; | ||
206 | } | ||||
200 | 207 | | |||
201 | qCDebug(LANGUAGE) << "context is set to" << thisContext.data(); | 208 | qCDebug(LANGUAGE) << "context is set to" << thisContext.data(); | ||
202 | if( !thisContext ) { | | |||
203 | qCDebug(LANGUAGE) << "================== NO CONTEXT FOUND ======================="; | | |||
204 | beginResetModel(); | | |||
205 | m_completionItems.clear(); | | |||
206 | m_navigationWidgets.clear(); | | |||
207 | endResetModel(); | | |||
208 | return; | | |||
209 | } | | |||
210 | } | 209 | } | ||
211 | 210 | | |||
212 | lock.unlock(); | 211 | lock.unlock(); | ||
213 | 212 | | |||
214 | if(m_forceWaitForModel) | 213 | if(m_forceWaitForModel) | ||
215 | emit waitForReset(); | 214 | emit waitForReset(); | ||
216 | 215 | | |||
217 | emit completionsNeeded(thisContext, range.start(), view); | 216 | emit completionsNeeded(thisContext, range.start(), view); | ||
218 | } else { | | |||
219 | qCDebug(LANGUAGE) << "Completion invoked for unknown context. Document:" << url << ", Known documents:" << DUChain::self()->documents(); | | |||
220 | } | | |||
221 | } | 217 | } | ||
222 | 218 | | |||
223 | 219 | | |||
224 | void CodeCompletionModel::completionInvoked(KTextEditor::View* view, const KTextEditor::Range& range, InvocationType invocationType) | 220 | void CodeCompletionModel::completionInvoked(KTextEditor::View* view, const KTextEditor::Range& range, InvocationType invocationType) | ||
225 | { | 221 | { | ||
226 | //If this triggers, initialize() has not been called after creation. | 222 | //If this triggers, initialize() has not been called after creation. | ||
227 | Q_ASSERT(m_thread); | 223 | Q_ASSERT(m_thread); | ||
228 | 224 | | |||
▲ Show 20 Lines • Show All 226 Lines • Show Last 20 Lines |