MCPcopy Create free account
hub / github.com/KDE/kdevelop / cursorContextDeclaration

Function cursorContextDeclaration

plugins/quickopen/quickopenplugin.cpp:179–213  ·  view source on GitHub ↗

The first definition that belongs to a context that surrounds the current cursor

Source from the content-addressed store, hash-verified

177
178///The first definition that belongs to a context that surrounds the current cursor
179Declaration* cursorContextDeclaration()
180{
181 KTextEditor::View* view = ICore::self()->documentController()->activeTextDocumentView();
182 if (!view) {
183 return nullptr;
184 }
185
186 KDevelop::DUChainReadLocker lock(DUChain::lock());
187
188 TopDUContext* ctx = DUChainUtils::standardContextForUrl(view->document()->url());
189 if (!ctx) {
190 return nullptr;
191 }
192
193 KTextEditor::Cursor cursor(view->cursorPosition());
194
195 DUContext* subCtx = ctx->findContext(ctx->transformToLocalRevision(cursor));
196
197 while (subCtx && !subCtx->owner())
198 subCtx = subCtx->parentContext();
199
200 Declaration* definition = nullptr;
201
202 if (!subCtx || !subCtx->owner()) {
203 definition = DUChainUtils::declarationInLine(cursor, ctx);
204 } else {
205 definition = subCtx->owner();
206 }
207
208 if (!definition) {
209 return nullptr;
210 }
211
212 return definition;
213}
214
215//Returns only the name, no template-parameters or scope
216QString cursorItemText()

Callers 1

startMethod · 0.85

Calls 9

documentControllerMethod · 0.80
findContextMethod · 0.80
urlMethod · 0.45
documentMethod · 0.45
cursorPositionMethod · 0.45
ownerMethod · 0.45
parentContextMethod · 0.45

Tested by

no test coverage detected