diff options
| author | Semih Yavuz <semih.yavuz@qt.io> | 2024-10-11 12:37:46 +0200 |
|---|---|---|
| committer | Semih Yavuz <semih.yavuz@qt.io> | 2024-10-24 09:41:36 +0200 |
| commit | a68c36300eb693fd9e0dc0f3923dd1084c6cbb14 (patch) | |
| tree | 24c8f3bcf857de01f53f5affdd0b0e28d6452a7b | |
| parent | 6d921e2d0ec6bec154ee03bbf70b882117bfcb2d (diff) | |
qmlls: Fix crash on editing file
DocumentSymbols should work on the valid document.
Also, we might get invalid file, so we should check the validity of qml
dom file item before dereferencing it. This happens although we check
the validity of a file in the language server module before processing
the request. This is probably caused by a synchronization problem on
editing the file and creating the dom for that file. This should be
further investigated with QTBUG-121171.
Change-Id: I4a2582210deb8da78ee1400a9f2f3c84b3ecbbae
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
| -rw-r--r-- | src/qmlls/documentSymbolSupport/qqmldocumentsymbolsupport.cpp | 5 | ||||
| -rw-r--r-- | src/qmlls/qqmllsutils.cpp | 6 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/qmlls/documentSymbolSupport/qqmldocumentsymbolsupport.cpp b/src/qmlls/documentSymbolSupport/qqmldocumentsymbolsupport.cpp index 15cff0c3c6..4c0c102b2a 100644 --- a/src/qmlls/documentSymbolSupport/qqmldocumentsymbolsupport.cpp +++ b/src/qmlls/documentSymbolSupport/qqmldocumentsymbolsupport.cpp @@ -32,8 +32,9 @@ void QQmlDocumentSymbolSupport::process(QQmlDocumentSymbolSupport::RequestPointe { const auto doc = m_codeModel->openDocumentByUrl( QQmlLSUtils::lspUriToQmlUrl(request->m_parameters.textDocument.uri)); - const auto qmlFileItem = doc.snapshot.doc.fileObject(QQmlJS::Dom::GoTo::MostLikely); - + const auto qmlFileItem = doc.snapshot.validDoc.fileObject(QQmlJS::Dom::GoTo::MostLikely); + if (!qmlFileItem) + return; auto results = DocumentSymbolUtils::assembleSymbolsForQmlFile(qmlFileItem); DocumentSymbolUtils::reorganizeForOutlineView(results); ResponseScopeGuard guard(results, request->m_response); diff --git a/src/qmlls/qqmllsutils.cpp b/src/qmlls/qqmllsutils.cpp index e665682978..ce5ff04516 100644 --- a/src/qmlls/qqmllsutils.cpp +++ b/src/qmlls/qqmllsutils.cpp @@ -1550,7 +1550,11 @@ static std::optional<ExpressionType> resolveIdentifierExpressionType(const DomIt if (auto scope = methodFromReferrerScope(referrerScope, name, options)) return scope; - const auto resolver = item.containingFile().ownerAs<QmlFile>()->typeResolver(); + const auto qmlFile = item.containingFile().ownerAs<QmlFile>(); + if (!qmlFile) + return {}; + + const auto resolver = qmlFile->typeResolver(); if (!resolver) return {}; |
