25
25
#include <interfaces/iplugincontroller.h>
26
26
#include <interfaces/iuicontroller.h>
27
27
#include <shell/core.h>
28
#include <sublime/view.h>
30
29
#include <ktexteditor/document.h>
31
30
#include <ktexteditor/view.h>
38
37
#include <language/duchain/duchain.h>
39
38
#include <language/duchain/duchainlock.h>
40
39
#include <language/duchain/duchainutils.h>
40
#include <language/duchain/types/identifiedtype.h>
41
#include <language/duchain/types/typeutils.h>
41
42
#include <documentation/documentationview.h>
42
43
#include <KParts/MainWindow>
43
44
#include <KActionCollection>
45
46
using namespace KDevelop;
51
* Return a "more useful" declaration that documentation providers can look-up
58
* In this case, this method returns a Declaration pointer to the *type*
59
* instead of a pointer to the instance, which is more useful when looking for help
61
* @return A more appropriate Declaration pointer or the given parameter @p decl
63
Declaration* usefulDeclaration(Declaration* decl)
68
// First: Attempt to find the declaration of a definition
69
decl = DUChainUtils::declarationForDefinition(decl);
71
// Convenience feature: Retrieve the type declaration of instances,
72
// it makes no sense to pass the declaration pointer of instances of types
73
if (decl->kind() == Declaration::Instance) {
74
AbstractType::Ptr type = TypeUtils::targetTypeKeepAliases(decl->abstractType(), decl->topContext());
75
IdentifiedType* idType = dynamic_cast<IdentifiedType*>(type.unsafeData());
76
Declaration* idDecl = idType ? idType->declaration(decl->topContext()) : 0;
47
86
class DocumentationViewFactory: public KDevelop::IToolViewFactory
104
143
KDevelop::DUChainReadLocker lock( DUChain::lock() );
106
Declaration *dec = DUChainUtils::declarationForDefinition( DUChainUtils::itemUnderCursor( doc->url(), SimpleCursor(view->cursorPosition()) ) );
109
KSharedPtr< IDocumentation > documentation = documentationForDeclaration(dec);
111
showDocumentation(documentation);
145
Declaration* decl = usefulDeclaration(DUChainUtils::itemUnderCursor(doc->url(), SimpleCursor(view->cursorPosition())));
146
KSharedPtr<IDocumentation> documentation = documentationForDeclaration(decl);
148
showDocumentation(documentation);
140
176
KSharedPtr< KDevelop::IDocumentation > DocumentationController::documentationForDeclaration(Declaration* decl)
179
return KSharedPtr<IDocumentation>();
142
181
KSharedPtr<KDevelop::IDocumentation> ret;
144
182
foreach(IDocumentationProvider* doc, documentationProviders())
146
184
kDebug(9529) << "Documentation provider found:" << doc;