| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qqmldocumentsymbolsupport_p.h" |
| 5 | #include "documentSymbolSupport/documentsymbolutils_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | using namespace Qt::StringLiterals; |
| 10 | QQmlDocumentSymbolSupport::QQmlDocumentSymbolSupport(QmlLsp::QQmlCodeModel *model) |
| 11 | : BaseT(model) { } |
| 12 | |
| 13 | QString QQmlDocumentSymbolSupport::name() const |
| 14 | { |
| 15 | return u"QQmlDocumentSymbolSupport"_s; |
| 16 | } |
| 17 | |
| 18 | void QQmlDocumentSymbolSupport::setupCapabilities( |
| 19 | const QLspSpecification::InitializeParams &, |
| 20 | QLspSpecification::InitializeResult &serverCapabilities) |
| 21 | { |
| 22 | serverCapabilities.capabilities.documentSymbolProvider = true; |
| 23 | } |
| 24 | |
| 25 | void QQmlDocumentSymbolSupport::registerHandlers(QLanguageServer *, |
| 26 | QLanguageServerProtocol *protocol) |
| 27 | { |
| 28 | protocol->registerDocumentSymbolRequestHandler(handler: getRequestHandler()); |
| 29 | } |
| 30 | |
| 31 | void QQmlDocumentSymbolSupport::process(QQmlDocumentSymbolSupport::RequestPointerArgument request) |
| 32 | { |
| 33 | const auto doc = m_codeModel->openDocumentByUrl( |
| 34 | url: QQmlLSUtils::lspUriToQmlUrl(uri: request->m_parameters.textDocument.uri)); |
| 35 | const auto qmlFileItem = doc.snapshot.validDoc.fileObject(option: QQmlJS::Dom::GoTo::MostLikely); |
| 36 | QList<QLspSpecification::DocumentSymbol> results; |
| 37 | ResponseScopeGuard guard(results, request->m_response); |
| 38 | if (qmlFileItem.internalKind() != QQmlJS::Dom::DomType::QmlFile) |
| 39 | return; |
| 40 | results = DocumentSymbolUtils::assembleSymbolsForQmlFile(item: qmlFileItem); |
| 41 | DocumentSymbolUtils::reorganizeForOutlineView(symbols&: results); |
| 42 | } |
| 43 | |
| 44 | QT_END_NAMESPACE |
| 45 |
