File indexing completed on 2024-04-14 14:47:45
0001 /* 0002 SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef COMPLETIONCODEMODEL_H 0008 #define COMPLETIONCODEMODEL_H 0009 0010 #include "phpduchainexport.h" 0011 #include <language/duchain/identifier.h> 0012 #include <serialization/indexedstring.h> 0013 0014 namespace KDevelop { 0015 0016 class Declaration; 0017 class IndexedDeclaration; 0018 class DeclarationId; 0019 class TopDUContext; 0020 class QualifiedIdentifier; 0021 class IndexedString; 0022 class IndexedQualifiedIdentifier; 0023 } 0024 0025 namespace Php { 0026 struct CompletionCodeModelItem { 0027 CompletionCodeModelItem() : referenceCount(0), kind(Unknown) { 0028 } 0029 enum Kind { 0030 Unknown = 0, 0031 Exception = 1 0032 }; 0033 KDevelop::IndexedQualifiedIdentifier id; 0034 KDevelop::IndexedString prettyName; 0035 uint referenceCount; 0036 union { 0037 Kind kind; 0038 uint uKind; 0039 }; 0040 bool operator<(const CompletionCodeModelItem& rhs) const { 0041 return id < rhs.id; 0042 } 0043 }; 0044 0045 /** 0046 * Persistent store that efficiently holds a list of identifiers and their kind for each declaration-string. 0047 * */ 0048 class KDEVPHPDUCHAIN_EXPORT CompletionCodeModel { 0049 public: 0050 /// Constructor. 0051 CompletionCodeModel(); 0052 /// Destructor. 0053 ~CompletionCodeModel(); 0054 0055 ///There can only be one item for each identifier. If an item with this identifier already exists, 0056 ///the kind is updated. 0057 void addItem(const KDevelop::IndexedString& file, const KDevelop::IndexedQualifiedIdentifier& id, const KDevelop::IndexedString & prettyName, CompletionCodeModelItem::Kind kind); 0058 0059 void removeItem(const KDevelop::IndexedString& file, const KDevelop::IndexedQualifiedIdentifier& id); 0060 0061 ///Updates the kind for the given item. The item must already be in the symbol table. 0062 void updateItem(const KDevelop::IndexedString& file, const KDevelop::IndexedQualifiedIdentifier& id, const KDevelop::IndexedString & prettyName, CompletionCodeModelItem::Kind kind); 0063 0064 ///Retrieves all the global identifiers for a file-name in an efficient way. 0065 ///@param count A reference that will be filled with the count of retrieved items 0066 ///@param items A reference to a pointer, that will represent the array of items. 0067 /// The array may contain items with an invalid identifier, those should be ignored. 0068 /// The list is sorted by identifier-index(except for the invalid identifiers in between). 0069 void items(const KDevelop::IndexedString& file, uint& count, const CompletionCodeModelItem*& items) const; 0070 0071 static CompletionCodeModel& self(); 0072 }; 0073 } 0074 0075 #endif