forked from qt-creator/qt-creator
ClangCodeModel: Keep a ref count for "extra files"
These are files that we temporarily report to the server as "open" without actually having a document for them. Since this mechanism is used in several places, we'd like to keep a consistent state even when such actions overlap. Change-Id: I0cfe3427740ec479926bc114848ad08f8866bdbb Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -295,6 +295,7 @@ public:
|
|||||||
QHash<TextDocument *, HighlightingData> highlightingData;
|
QHash<TextDocument *, HighlightingData> highlightingData;
|
||||||
QHash<Utils::FilePath, CppEditor::BaseEditorDocumentParser::Configuration> parserConfigs;
|
QHash<Utils::FilePath, CppEditor::BaseEditorDocumentParser::Configuration> parserConfigs;
|
||||||
QHash<Utils::FilePath, Tasks> issuePaneEntries;
|
QHash<Utils::FilePath, Tasks> issuePaneEntries;
|
||||||
|
QHash<Utils::FilePath, int> openedExtraFiles;
|
||||||
|
|
||||||
VersionedDataCache<const TextDocument *, ClangdAstNode> astCache;
|
VersionedDataCache<const TextDocument *, ClangdAstNode> astCache;
|
||||||
VersionedDataCache<Utils::FilePath, ClangdAstNode> externalAstCache;
|
VersionedDataCache<Utils::FilePath, ClangdAstNode> externalAstCache;
|
||||||
@@ -421,10 +422,11 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &Client::initialized, this, [] {
|
connect(this, &Client::initialized, this, [this] {
|
||||||
auto currentDocumentFilter = static_cast<ClangdCurrentDocumentFilter *>(
|
auto currentDocumentFilter = static_cast<ClangdCurrentDocumentFilter *>(
|
||||||
CppEditor::CppModelManager::instance()->currentDocumentFilter());
|
CppEditor::CppModelManager::instance()->currentDocumentFilter());
|
||||||
currentDocumentFilter->updateCurrentClient();
|
currentDocumentFilter->updateCurrentClient();
|
||||||
|
d->openedExtraFiles.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
start();
|
start();
|
||||||
@@ -444,6 +446,13 @@ bool ClangdClient::isFullyIndexed() const
|
|||||||
|
|
||||||
void ClangdClient::openExtraFile(const Utils::FilePath &filePath, const QString &content)
|
void ClangdClient::openExtraFile(const Utils::FilePath &filePath, const QString &content)
|
||||||
{
|
{
|
||||||
|
const auto it = d->openedExtraFiles.find(filePath);
|
||||||
|
if (it != d->openedExtraFiles.end()) {
|
||||||
|
QTC_CHECK(it.value() > 0);
|
||||||
|
++it.value();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QFile cxxFile(filePath.toString());
|
QFile cxxFile(filePath.toString());
|
||||||
if (content.isEmpty() && !cxxFile.open(QIODevice::ReadOnly))
|
if (content.isEmpty() && !cxxFile.open(QIODevice::ReadOnly))
|
||||||
return;
|
return;
|
||||||
@@ -454,10 +463,18 @@ void ClangdClient::openExtraFile(const Utils::FilePath &filePath, const QString
|
|||||||
item.setVersion(0);
|
item.setVersion(0);
|
||||||
sendMessage(DidOpenTextDocumentNotification(DidOpenTextDocumentParams(item)),
|
sendMessage(DidOpenTextDocumentNotification(DidOpenTextDocumentParams(item)),
|
||||||
SendDocUpdates::Ignore);
|
SendDocUpdates::Ignore);
|
||||||
|
|
||||||
|
d->openedExtraFiles.insert(filePath, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangdClient::closeExtraFile(const Utils::FilePath &filePath)
|
void ClangdClient::closeExtraFile(const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
|
const auto it = d->openedExtraFiles.find(filePath);
|
||||||
|
QTC_ASSERT(it != d->openedExtraFiles.end(), return);
|
||||||
|
QTC_CHECK(it.value() > 0);
|
||||||
|
if (--it.value() > 0)
|
||||||
|
return;
|
||||||
|
d->openedExtraFiles.erase(it);
|
||||||
sendMessage(DidCloseTextDocumentNotification(DidCloseTextDocumentParams(
|
sendMessage(DidCloseTextDocumentNotification(DidCloseTextDocumentParams(
|
||||||
TextDocumentIdentifier{DocumentUri::fromFilePath(filePath)})),
|
TextDocumentIdentifier{DocumentUri::fromFilePath(filePath)})),
|
||||||
SendDocUpdates::Ignore);
|
SendDocUpdates::Ignore);
|
||||||
|
Reference in New Issue
Block a user