diff --git a/docs/API/knut/textlocation.md b/docs/API/knut/textlocation.md
deleted file mode 100644
index 620f8642..00000000
--- a/docs/API/knut/textlocation.md
+++ /dev/null
@@ -1,28 +0,0 @@
-# TextLocation
-
-Defines a range of text in a file. [More...](#detailed-description)
-
-```qml
-import Knut
-```
-
-## Properties
-
-| | Name |
-|-|-|
-|[CodeDocument](../knut/codedocument.md)|**[document](#document)**|
-|[TextRange](../knut/textrange.md)|**[range](#range)**|
-
-## Detailed Description
-
-A mark is always created by a [CodeDocument](codedocument.md).
-
-## Property Documentation
-
-#### [CodeDocument](../knut/codedocument.md) **document**
-
-This read-only property contains the source document for this text location.
-
-#### [TextRange](../knut/textrange.md) **range**
-
-This read-only property contains the range of text in the document.
diff --git a/mkdocs.yml b/mkdocs.yml
index 829ed74e..c3714206 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -87,7 +87,6 @@ nav:
- TextDocument: API/knut/textdocument.md
- Mark: API/knut/mark.md
- RangeMark: API/knut/rangemark.md
- - TextLocation: API/knut/textlocation.md
- TextRange: API/knut/textrange.md
- Items:
- Script: API/knut/script.md
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 5ab767db..bd1d64fc 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -94,8 +94,6 @@ set(PROJECT_SOURCES
textdocument_p.h
texteditor.h
texteditor.cpp
- textlocation.h
- textlocation.cpp
textrange.h
textrange.cpp
qtuidocument.h
diff --git a/src/core/codedocument.cpp b/src/core/codedocument.cpp
index 0f6ab308..5f964144 100644
--- a/src/core/codedocument.cpp
+++ b/src/core/codedocument.cpp
@@ -17,7 +17,6 @@
#include "querymatch.h"
#include "rangemark.h"
#include "symbol.h"
-#include "textlocation.h"
#include "treesitter/predicates.h"
#include "utils/json.h"
#include "utils/log.h"
@@ -261,7 +260,7 @@ std::pair> CodeDocument::hoverWithRange(
return {"", {}};
}
-Core::TextLocationList CodeDocument::references(int position) const
+RangeMarkList CodeDocument::references(int position) const
{
spdlog::debug("CodeDocument::references");
@@ -273,11 +272,10 @@ Core::TextLocationList CodeDocument::references(int position) const
params.textDocument.uri = toUri();
params.position = Utils::lspFromPos(*this, position);
- Core::TextLocationList textLocations;
if (auto result = client()->references(std::move(params))) {
const auto &value = result.value();
if (const auto *locations = std::get_if>(&value)) {
- return Utils::lspToTextLocationList(*locations);
+ return Utils::lspToRangeMarkList(*locations);
} else {
spdlog::warn("CodeDocument::references: Language server returned unsupported references type!");
}
@@ -285,7 +283,7 @@ Core::TextLocationList CodeDocument::references(int position) const
spdlog::warn("CodeDocument::references: LSP call to references returned nothing!");
}
- return textLocations;
+ return {};
}
// Follows the symbol under the cursor.
diff --git a/src/core/codedocument.h b/src/core/codedocument.h
index a30addbb..f6c98bc8 100644
--- a/src/core/codedocument.h
+++ b/src/core/codedocument.h
@@ -73,7 +73,7 @@ class CodeDocument : public TextDocument
// As they rely on the clangd LSP, they are not reliable enough to use for scripting.
Core::Document *switchDeclarationDefinition();
Core::Document *followSymbol();
- Core::TextLocationList references(int position) const;
+ Core::RangeMarkList references(int position) const;
QString hover(int position, std::function asyncCallback = {}) const;
diff --git a/src/core/lsp_utils.cpp b/src/core/lsp_utils.cpp
index 682132b0..ad6f5dcc 100644
--- a/src/core/lsp_utils.cpp
+++ b/src/core/lsp_utils.cpp
@@ -49,10 +49,10 @@ TextRange lspToRange(const TextDocument &textDocument, const Lsp::Range &range)
return {lspToPos(textDocument, range.start), lspToPos(textDocument, range.end)};
}
-TextLocationList lspToTextLocationList(const std::vector &locations)
+RangeMarkList lspToRangeMarkList(const std::vector &locations)
{
- TextLocationList textLocations;
- textLocations.reserve(locations.size());
+ RangeMarkList rangeMarks;
+ rangeMarks.reserve(locations.size());
for (const auto &location : locations) {
const auto url = QUrl::fromEncoded(QByteArray::fromStdString(location.uri));
@@ -61,14 +61,13 @@ TextLocationList lspToTextLocationList(const std::vector &locatio
}
const auto filepath = url.toLocalFile();
- if (auto *document = qobject_cast(Project::instance()->get(filepath))) {
+ if (auto document = qobject_cast(Project::instance()->get(filepath))) {
const auto range = lspToRange(*document, location.range);
-
- textLocations.emplace_back(TextLocation {.document = document, .range = range});
+ rangeMarks.push_back(document->createRangeMark(range.start, range.end));
}
}
- return textLocations;
+ return rangeMarks;
}
QString removeTypeAliasInformation(const QString &typeInfo)
diff --git a/src/core/lsp_utils.h b/src/core/lsp_utils.h
index 7fa7eeca..b96f5c7b 100644
--- a/src/core/lsp_utils.h
+++ b/src/core/lsp_utils.h
@@ -11,7 +11,7 @@
#pragma once
#include "lsp/types.h"
-#include "textlocation.h"
+#include "rangemark.h"
#include "textrange.h"
#include
@@ -29,7 +29,7 @@ int lspToPos(const TextDocument &textDocument, const Lsp::Position &pos);
TextRange lspToRange(const TextDocument &textDocument, const Lsp::Range &range);
-TextLocationList lspToTextLocationList(const std::vector &locations);
+RangeMarkList lspToRangeMarkList(const std::vector &locations);
QString removeTypeAliasInformation(const QString &typeInfo);
diff --git a/src/core/symbol.cpp b/src/core/symbol.cpp
index 6ab24383..3e24388e 100644
--- a/src/core/symbol.cpp
+++ b/src/core/symbol.cpp
@@ -191,14 +191,14 @@ Core::TextRange Symbol::selectionRange() const
return m_selectionRange;
}
-QList Symbol::references() const
+RangeMarkList Symbol::references() const
{
LOG("Symbol::references");
if (const auto codedocument = document()) {
auto references = codedocument->references(selectionRange().start);
- kdalgorithms::erase_if(references, [this](const auto &reference) {
- return reference.range == this->selectionRange();
+ kdalgorithms::erase_if(references, [this](const RangeMark &reference) {
+ return reference.toTextRange() == m_selectionRange;
});
return references;
}
diff --git a/src/core/symbol.h b/src/core/symbol.h
index 397ff490..b4279d74 100644
--- a/src/core/symbol.h
+++ b/src/core/symbol.h
@@ -11,7 +11,7 @@
#pragma once
#include "querymatch.h"
-#include "textlocation.h"
+#include "rangemark.h"
#include "textrange.h"
#include
@@ -92,7 +92,7 @@ class Symbol : public QObject
// As per KNUT-163, these are no longer public API.
// They are only used internally by the editor/GUI and not available from QML/JS.
// As this relies on the clangd LSP, it is not reliable enough to use for scripting.
- QList references() const;
+ Core::RangeMarkList references() const;
Q_INVOKABLE void select();
diff --git a/src/core/textlocation.cpp b/src/core/textlocation.cpp
deleted file mode 100644
index 1182ef97..00000000
--- a/src/core/textlocation.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- This file is part of Knut.
-
- SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company
-
- SPDX-License-Identifier: GPL-3.0-only
-
- Contact KDAB at for commercial licensing options.
-*/
-
-#include "textlocation.h"
-#include "codedocument.h"
-#include "project.h"
-
-namespace Core {
-
-/*!
- * \qmltype TextLocation
- * \brief Defines a range of text in a file.
- * \inqmlmodule Knut
- * \ingroup TextDocument
- * \sa CodeDocument
- *
- * A mark is always created by a [CodeDocument](codedocument.md).
- */
-
-/*!
- * \qmlproperty CodeDocument TextLocation::document
- * This read-only property contains the source document for this text location.
- */
-/*!
- * \qmlproperty TextRange TextLocation::range
- * This read-only property contains the range of text in the document.
- */
-
-QString TextLocation::toString() const
-{
- return QString("{'%1', %2}").arg(document->fileName(), range.toString());
-}
-
-} // namespace Core
diff --git a/src/core/textlocation.h b/src/core/textlocation.h
deleted file mode 100644
index 055eb382..00000000
--- a/src/core/textlocation.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- This file is part of Knut.
-
- SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company
-
- SPDX-License-Identifier: GPL-3.0-only
-
- Contact KDAB at for commercial licensing options.
-*/
-
-#pragma once
-
-#include "textrange.h"
-
-#include
-
-namespace Core {
-
-class CodeDocument;
-
-struct TextLocation
-{
- Q_GADGET
- Q_PROPERTY(Core::CodeDocument *document MEMBER document CONSTANT)
- Q_PROPERTY(Core::TextRange range MEMBER range CONSTANT)
-
-public:
- CodeDocument *document;
- TextRange range;
-
- Q_INVOKABLE QString toString() const;
-
- auto operator<=>(const TextLocation &) const = default;
-};
-
-using TextLocationList = QList;
-
-} // namespace Core
-
-Q_DECLARE_METATYPE(Core::TextLocation)
diff --git a/tests/tst_symbol.cpp b/tests/tst_symbol.cpp
index 6e6752e5..d963d94a 100644
--- a/tests/tst_symbol.cpp
+++ b/tests/tst_symbol.cpp
@@ -191,7 +191,7 @@ private slots:
QCOMPARE(symbol->kind(), Core::Symbol::Class);
const auto isSymbolRange = [&symbol](const auto &loc) {
- return loc.range == symbol->selectionRange();
+ return loc.toTextRange() == symbol->selectionRange();
};
spdlog::warn("Finding references");
@@ -209,19 +209,19 @@ private slots:
spdlog::warn("Counting documents");
QCOMPARE(std::ranges::count_if(references,
[](const auto &location) {
- return location.document->fileName().endsWith("main.cpp");
+ return location.document()->fileName().endsWith("main.cpp");
}),
1);
QCOMPARE(std::ranges::count_if(references,
[](const auto &location) {
- return location.document->fileName().endsWith("myobject.h");
+ return location.document()->fileName().endsWith("myobject.h");
}),
2);
QCOMPARE(std::ranges::count_if(references,
[](const auto &location) {
- return location.document->fileName().endsWith("myobject.cpp");
+ return location.document()->fileName().endsWith("myobject.cpp");
}),
6);
}