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

Method switchUse

plugins/contextbrowser/contextbrowser.cpp:1035–1219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1033}
1034
1035void ContextBrowserPlugin::switchUse(bool forward)
1036{
1037 View* view = core()->documentController()->activeTextDocumentView();
1038 if (view) {
1039 KTextEditor::Document* doc = view->document();
1040 KDevelop::DUChainReadLocker lock(DUChain::lock());
1041 KDevelop::TopDUContext* chosen = DUChainUtils::standardContextForUrl(doc->url());
1042
1043 if (chosen) {
1044 KTextEditor::Cursor cCurrent(view->cursorPosition());
1045 KDevelop::CursorInRevision c = chosen->transformToLocalRevision(cCurrent);
1046
1047 Declaration* decl = nullptr;
1048 //If we have a locked declaration, use that for jumping
1049 for (ContextBrowserView* view : std::as_const(m_views)) {
1050 decl = view->lockedDeclaration().data(); ///@todo Somehow match the correct context-browser view if there is multiple
1051 if (decl)
1052 break;
1053 }
1054
1055 if (!decl) //Try finding a declaration under the cursor
1056 decl = DUChainUtils::itemUnderCursor(doc->url(), cCurrent).declaration;
1057
1058 if (decl && decl->kind() == Declaration::Alias) {
1059 auto* alias = dynamic_cast<AliasDeclaration*>(decl);
1060 Q_ASSERT(alias);
1061 decl = alias->aliasedDeclaration().declaration();
1062 }
1063
1064 if (decl) {
1065 Declaration* target = nullptr;
1066 if (forward)
1067 //Try jumping from definition to declaration
1068 target = DUChainUtils::declarationForDefinition(decl, chosen);
1069 else if (decl->url().toUrl() == doc->url() && decl->range().contains(c))
1070 //Try jumping from declaration to definition
1071 target = FunctionDefinition::definition(decl);
1072
1073 if (target && target != decl) {
1074 KTextEditor::Cursor jumpTo = target->rangeInCurrentRevision().start();
1075 QUrl document = target->url().toUrl();
1076 lock.unlock();
1077 core()->documentController()->openDocument(document, cursorToRange(jumpTo));
1078 return;
1079 } else {
1080 //Always work with the declaration instead of the definition
1081 decl = DUChainUtils::declarationForDefinition(decl, chosen);
1082 }
1083 }
1084
1085 if (!decl) {
1086 //Pick the last use we have highlighted
1087 decl = m_lastHighlightedDeclaration.data();
1088 }
1089
1090 if (decl) {
1091 KDevVarLengthArray<IndexedTopDUContext> usingFiles = DUChain::uses()->uses(decl->id());
1092

Callers

nothing calls this directly

Calls 15

cursorToRangeFunction · 0.85
sortFunction · 0.85
documentControllerMethod · 0.80
lockedDeclarationMethod · 0.80
aliasedDeclarationMethod · 0.80
allUsesFunction · 0.50
documentMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected