diff --git a/docs/API/knut/functionsymbol.md b/docs/API/knut/functionsymbol.md
index b1b75d99..d37fdc21 100644
--- a/docs/API/knut/functionsymbol.md
+++ b/docs/API/knut/functionsymbol.md
@@ -15,7 +15,6 @@ import Knut
| | Name |
|-|-|
|vector<[FunctionArgument](../knut/functionargument.md)>|**[arguments](#arguments)**|
-|[TextRange](../knut/textrange.md)|**[range](#range)**|
|string|**[returnType](#returnType)**|
## Property Documentation
@@ -24,11 +23,6 @@ import Knut
Returns the list of arguments being passed to this function.
-#### [TextRange](../knut/textrange.md) **range**
-
-The range enclosing this function, not including leading/trailing
-whitespace but everything else like comments.
-
#### string **returnType**
Returns the return type of this function.
diff --git a/docs/API/knut/symbol.md b/docs/API/knut/symbol.md
index 4300e04a..fa724209 100644
--- a/docs/API/knut/symbol.md
+++ b/docs/API/knut/symbol.md
@@ -13,8 +13,8 @@ import Knut
|string|**[description](#description)**|
|Kind|**[kind](#kind)**|
|string|**[name](#name)**|
-|[TextRange](../knut/textrange.md)|**[range](#range)**|
-|[TextRange](../knut/textrange.md)|**[selectionRange](#selectionRange)**|
+|[RangeMark](../knut/rangemark.md)|**[range](#range)**|
+|[RangeMark](../knut/rangemark.md)|**[selectionRange](#selectionRange)**|
## Methods
@@ -65,13 +65,13 @@ Return the kind of this symbol. Available symbol kinds are:
Return the name of this symbol.
-#### [TextRange](../knut/textrange.md) **range**
+#### [RangeMark](../knut/rangemark.md) **range**
The range enclosing this symbol not including leading/trailing whitespace but everything else like comments. This
information is typically used to determine if the clients cursor is inside the symbol to reveal in the symbol in the
UI.
-#### [TextRange](../knut/textrange.md) **selectionRange**
+#### [RangeMark](../knut/rangemark.md) **selectionRange**
The range that should be selected and revealed when this symbol is being picked, e.g. the name of a function. Must be
contained by the `range`.
diff --git a/docs/API/knut/textdocument.md b/docs/API/knut/textdocument.md
index b802a83d..2d427f03 100644
--- a/docs/API/knut/textdocument.md
+++ b/docs/API/knut/textdocument.md
@@ -39,7 +39,7 @@ Inherited properties: [Document properties](../knut/document.md#properties)
||**[deleteLine](#deleteLine)**(int line = -1)|
||**[deleteNextCharacter](#deleteNextCharacter)**(int count = 1)|
||**[deletePreviousCharacter](#deletePreviousCharacter)**(int count = 1)|
-||**[deleteRange](#deleteRange)**([TextRange](../knut/textrange.md) range)|
+||**[deleteRange](#deleteRange)**([RangeMark](../knut/rangemark.md) range)|
||**[deleteRegion](#deleteRegion)**(int from, int to)|
||**[deleteSelection](#deleteSelection)**()|
||**[deleteStartOfLine](#deleteStartOfLine)**()|
@@ -74,7 +74,7 @@ Inherited properties: [Document properties](../knut/document.md#properties)
||**[remove](#remove)**(int length)|
||**[removeIndent](#removeIndent)**(int count)|
||**[replace](#replace)**(int length, string text)|
-||**[replace](#replace)**([TextRange](../knut/textrange.md) range, string text)|
+||**[replace](#replace)**([RangeMark](../knut/rangemark.md) range, string text)|
||**[replace](#replace)**(int from, int to, string text)|
|bool |**[replaceAll](#replaceAll)**(string before, string after, int options = TextDocument.NoFindFlags)|
|bool |**[replaceAllInRange](#replaceAllInRange)**(string before, string after, [RangeMark](../knut/rangemark.md) range, int options = TextDocument.NoFindFlags)|
@@ -90,7 +90,7 @@ Inherited properties: [Document properties](../knut/document.md#properties)
||**[selectPreviousChar](#selectPreviousChar)**(int count = 1)|
||**[selectPreviousLine](#selectPreviousLine)**(int count = 1)|
||**[selectPreviousWord](#selectPreviousWord)**(int count = 1)|
-||**[selectRange](#selectRange)**([TextRange](../knut/textrange.md) range)|
+||**[selectRange](#selectRange)**([RangeMark](../knut/rangemark.md) range)|
||**[selectRangeMark](#selectRangeMark)**([RangeMark](../knut/rangemark.md) mark)|
||**[selectRegion](#selectRegion)**(int from, int to)|
||**[selectStartOfLine](#selectStartOfLine)**(int count = 1)|
@@ -205,7 +205,7 @@ Deletes the next `count` characters.
Deletes the previous `count` characters.
-#### **deleteRange**([TextRange](../knut/textrange.md) range)
+#### **deleteRange**([RangeMark](../knut/rangemark.md) range)
Deletes the range passed in parameter.
@@ -364,7 +364,7 @@ Indents the current line `count` times. If there's a selection, indent all lines
Replaces `length` characters from the current position with the string `text`.
-#### **replace**([TextRange](../knut/textrange.md) range, string text)
+#### **replace**([RangeMark](../knut/rangemark.md) range, string text)
Replaces the text in the range `range` with the string `text`.
@@ -471,7 +471,7 @@ Selects the previous line, repeat the operation `count` times.
Selects the previous word, repeat the operation `count` times.
-#### **selectRange**([TextRange](../knut/textrange.md) range)
+#### **selectRange**([RangeMark](../knut/rangemark.md) range)
Selects the range passed in parameter.
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/docs/API/knut/textrange.md b/docs/API/knut/textrange.md
deleted file mode 100644
index d33709a2..00000000
--- a/docs/API/knut/textrange.md
+++ /dev/null
@@ -1,29 +0,0 @@
-# TextRange
-
-Defines a range of text in a text document [More...](#detailed-description)
-
-```qml
-import Knut
-```
-
-## Properties
-
-| | Name |
-|-|-|
-|int|**[end](#end)**|
-|int|**[length](#length)**|
-|int|**[start](#start)**|
-
-## Property Documentation
-
-#### int **end**
-
-This read-only property defines the end position of the range.
-
-#### int **length**
-
-This read-only property returns the length of the range (end - start)
-
-#### int **start**
-
-This read-only property defines the start position of the range.
diff --git a/mkdocs.yml b/mkdocs.yml
index 829ed74e..69ad79c5 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -87,8 +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
- ScriptDialog: API/knut/scriptdialog.md
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 5ab767db..e1b289ae 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -94,10 +94,6 @@ set(PROJECT_SOURCES
textdocument_p.h
texteditor.h
texteditor.cpp
- textlocation.h
- textlocation.cpp
- textrange.h
- textrange.cpp
qtuidocument.h
qtuidocument.cpp
qttsdocument.h
diff --git a/src/core/codedocument.cpp b/src/core/codedocument.cpp
index 0f6ab308..8fac2a76 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"
@@ -95,38 +94,33 @@ Symbol *CodeDocument::currentSymbol(const std::function &f
*/
void CodeDocument::deleteSymbol(const Symbol &symbol)
{
- auto range = symbol.range();
+ const auto range = symbol.range();
// Include any leading whitespace (excluding newlines).
- auto leading = Core::TextRange {range.start, range.start + 1};
- while (leading.start > 0) {
- leading.start--;
- leading.end--;
- selectRange(leading);
+ int start = range.start();
+ while (start > 0) {
+ selectRegion(start - 1, start);
if (selectedText() != " " && selectedText() != "\t") {
break;
}
- range.start--;
+ start--;
}
// Include a trailing semicolon and up to one trailing newline
- auto trailing = Core::TextRange {range.end, range.end + 1};
- selectRange(trailing);
+ int end = range.end();
+ selectRegion(end, end + 1);
if (selectedText() == ";") {
- range.end++;
-
- trailing.start++;
- trailing.end++;
- selectRange(trailing);
+ end++;
+ selectRegion(end, end + 1);
}
if (selectedText() == "\n") {
- range.end++;
+ end++;
}
- this->selectRange(range);
+ this->selectRegion(start, end);
this->deleteSelection();
}
@@ -203,8 +197,8 @@ QString CodeDocument::hover(int position, std::function a
}
}
-std::pair> CodeDocument::hoverWithRange(
- int position, std::function)> asyncCallback /* = {} */) const
+std::pair> CodeDocument::hoverWithRange(
+ int position, std::function)> asyncCallback /* = {} */) const
{
spdlog::debug("CodeDocument::hover");
@@ -217,14 +211,14 @@ std::pair> CodeDocument::hoverWithRange(
QPointer safeThis(this);
- auto convertResult = [safeThis](const auto &result) -> std::pair> {
+ auto convertResult = [safeThis](const auto &result) -> std::pair> {
if (!std::holds_alternative(result)) {
return {"", {}};
}
auto hover = std::get(result);
- std::optional range;
+ std::optional range;
if (hover.range && !safeThis.isNull()) {
range = Utils::lspToRange(*safeThis, hover.range.value());
}
@@ -261,7 +255,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 +267,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 +278,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.
@@ -374,7 +367,7 @@ Document *CodeDocument::switchDeclarationDefinition()
auto symbolList = symbols();
auto currentFunction = kdalgorithms::find_if(symbolList, [&cursor](const auto &symbol) {
- auto isInRange = symbol->range().start <= cursor.position() && cursor.position() <= symbol->range().end;
+ auto isInRange = symbol->range().contains(cursor.position());
return isInRange && symbol->isFunction();
});
@@ -383,7 +376,7 @@ Document *CodeDocument::switchDeclarationDefinition()
return nullptr;
}
- return followSymbol((*currentFunction)->selectionRange().start);
+ return followSymbol((*currentFunction)->selectionRange().start());
}
/*!
diff --git a/src/core/codedocument.h b/src/core/codedocument.h
index a30addbb..df1c476d 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;
@@ -98,9 +98,9 @@ public slots:
int revision() const;
- std::pair>
+ std::pair>
hoverWithRange(int position,
- std::function)> asyncCallback = {}) const;
+ std::function)> asyncCallback = {}) const;
private:
bool checkClient() const;
diff --git a/src/core/codedocument_p.cpp b/src/core/codedocument_p.cpp
index 5c89443c..ce0212c7 100644
--- a/src/core/codedocument_p.cpp
+++ b/src/core/codedocument_p.cpp
@@ -304,7 +304,7 @@ const QList &TreeSitterHelper::symbols()
m_symbols.append(enumSymbols());
kdalgorithms::sort_by(m_symbols, [](const auto &symbol) {
- return symbol->range().start;
+ return symbol->range().start();
});
assignSymbolContexts();
diff --git a/src/core/cppdocument.cpp b/src/core/cppdocument.cpp
index 9ddc8e51..656c9847 100644
--- a/src/core/cppdocument.cpp
+++ b/src/core/cppdocument.cpp
@@ -465,7 +465,7 @@ bool CppDocument::insertCodeInMethod(const QString &methodName, QString code, Po
}
QTextCursor cursor = textEdit()->textCursor();
- cursor.setPosition(symbol->range().end);
+ cursor.setPosition(symbol->range().end());
cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
if (cursor.selectedText() != "}") {
spdlog::warn("CppDocument::insertCodeInMethod: {} is not a function definition.", symbol->name());
@@ -474,7 +474,7 @@ bool CppDocument::insertCodeInMethod(const QString &methodName, QString code, Po
cursor.beginEditBlock();
// Goto the end and move back one character
- cursor.setPosition(symbol->range().end);
+ cursor.setPosition(symbol->range().end());
cursor.movePosition(QTextCursor::PreviousCharacter);
const QString strTab = tab();
@@ -1001,14 +1001,14 @@ void CppDocument::toggleSection()
cursor.beginEditBlock();
// Start from the end
- cursor.setPosition(symbol->range().end);
+ cursor.setPosition(symbol->range().end());
cursor.movePosition(QTextCursor::StartOfLine);
cursor.movePosition(QTextCursor::Up, QTextCursor::KeepAnchor);
if (cursor.selectedText().startsWith(endifString)) {
// The function is already commented out, remove the comments
int start = textEdit()->document()->find(elseString, cursor, QTextDocument::FindBackward).selectionStart();
- if (start > symbol->range().start)
+ if (start > symbol->range().start())
cursor.setPosition(start, QTextCursor::KeepAnchor);
cursor.removeSelectedText();
cursor.setPosition(moveBlock(cursor.position(), QTextCursor::PreviousCharacter));
@@ -1019,7 +1019,7 @@ void CppDocument::toggleSection()
cursorPos -= ifdefString.length() + 1;
} else {
// Comment out the function with #if/#def, make sure to return something if needed
- cursor.setPosition(symbol->range().end);
+ cursor.setPosition(symbol->range().end());
cursor.movePosition(QTextCursor::PreviousCharacter);
QString text = elseString + newLine;
@@ -1350,7 +1350,7 @@ void CppDocument::deleteMethodLocal(const QString &methodName, const QString &si
// That way removing a function won't change the position of the other functions.
// This assumes the ranges don't overlap.
auto byRange = [](const auto &symbol1, const auto &symbol2) {
- return symbol1->range().start > symbol2->range().start;
+ return symbol1->range().start() > symbol2->range().start();
};
std::ranges::sort(symbolList, byRange);
diff --git a/src/core/functionsymbol.cpp b/src/core/functionsymbol.cpp
index 06054914..4002520c 100644
--- a/src/core/functionsymbol.cpp
+++ b/src/core/functionsymbol.cpp
@@ -50,11 +50,6 @@ namespace Core {
* \qmlproperty vector FunctionSymbol::arguments
* Returns the list of arguments being passed to this function.
*/
-/*!
- * \qmlproperty TextRange FunctionSymbol::range
- * The range enclosing this function, not including leading/trailing
- * whitespace but everything else like comments.
- */
FunctionSymbol::FunctionSymbol(QObject *parent, const QueryMatch &match, Kind kind)
: Symbol(parent, match, kind)
diff --git a/src/core/functionsymbol.h b/src/core/functionsymbol.h
index 4d4feb9d..5d51e414 100644
--- a/src/core/functionsymbol.h
+++ b/src/core/functionsymbol.h
@@ -12,7 +12,6 @@
#include "document.h"
#include "symbol.h"
-#include "textrange.h"
#include
#include
diff --git a/src/core/lsp_utils.cpp b/src/core/lsp_utils.cpp
index 682132b0..e8137035 100644
--- a/src/core/lsp_utils.cpp
+++ b/src/core/lsp_utils.cpp
@@ -44,15 +44,17 @@ int lspToPos(const TextDocument &textDocument, const Lsp::Position &pos)
return 0;
}
-TextRange lspToRange(const TextDocument &textDocument, const Lsp::Range &range)
+RangeMark lspToRange(const TextDocument &textDocument, const Lsp::Range &range)
{
- return {lspToPos(textDocument, range.start), lspToPos(textDocument, range.end)};
+ // I know, ugly, but that's the easiest to do that here.
+ auto document = const_cast(&textDocument);
+ return document->createRangeMark(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 +63,12 @@ TextLocationList lspToTextLocationList(const std::vector &locatio
}
const auto filepath = url.toLocalFile();
- if (auto *document = qobject_cast(Project::instance()->get(filepath))) {
- const auto range = lspToRange(*document, location.range);
-
- textLocations.emplace_back(TextLocation {.document = document, .range = range});
+ if (auto document = qobject_cast(Project::instance()->get(filepath))) {
+ rangeMarks.push_back(lspToRange(*document, location.range));
}
}
- 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..bd845ed3 100644
--- a/src/core/lsp_utils.h
+++ b/src/core/lsp_utils.h
@@ -11,8 +11,7 @@
#pragma once
#include "lsp/types.h"
-#include "textlocation.h"
-#include "textrange.h"
+#include "rangemark.h"
#include
#include
@@ -27,9 +26,9 @@ Lsp::Position lspFromPos(const TextDocument &textDocument, int pos);
int lspToPos(const TextDocument &textDocument, const Lsp::Position &pos);
-TextRange lspToRange(const TextDocument &textDocument, const Lsp::Range &range);
+RangeMark 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/rangemark.cpp b/src/core/rangemark.cpp
index 0f146bcd..7f068eea 100644
--- a/src/core/rangemark.cpp
+++ b/src/core/rangemark.cpp
@@ -133,11 +133,6 @@ TextDocument *RangeMark::document() const
return d ? d->m_editor : nullptr;
}
-TextRange RangeMark::toTextRange() const
-{
- return {start(), end()};
-}
-
QString RangeMark::text() const
{
// <= here instead of < because m_end is exclusive
diff --git a/src/core/rangemark.h b/src/core/rangemark.h
index 24c5a01d..a5eb795b 100644
--- a/src/core/rangemark.h
+++ b/src/core/rangemark.h
@@ -10,8 +10,6 @@
#pragma once
-#include "textrange.h"
-
#include
#include
@@ -53,9 +51,6 @@ class RangeMark
TextDocument *document() const;
- // Casting
- TextRange toTextRange() const;
-
// Text manipulation
Q_INVOKABLE void select() const;
Q_INVOKABLE void replace(const QString &text) const;
diff --git a/src/core/scriptrunner.cpp b/src/core/scriptrunner.cpp
index ab37c799..cff0c3f5 100644
--- a/src/core/scriptrunner.cpp
+++ b/src/core/scriptrunner.cpp
@@ -26,7 +26,6 @@
#include "settings.h"
#include "symbol.h"
#include "textdocument.h"
-#include "textrange.h"
#include "userdialog.h"
#include "utils.h"
#include "utils/log.h"
@@ -66,7 +65,6 @@ ScriptRunner::ScriptRunner(QObject *parent)
qRegisterMetaType();
qRegisterMetaType();
qRegisterMetaType();
- qRegisterMetaType();
// Knut QML module
qmlRegisterSingletonType("Knut", 1, 0, "Dir", [](QQmlEngine *engine, QJSEngine *) {
@@ -158,7 +156,6 @@ ScriptRunner::ScriptRunner(QObject *parent)
addProperties(m_properties);
addProperties(m_properties);
addProperties(m_properties);
- addProperties(m_properties);
addProperties(m_properties);
addProperties(m_properties);
addProperties(m_properties);
diff --git a/src/core/symbol.cpp b/src/core/symbol.cpp
index 6ab24383..e96f2eb6 100644
--- a/src/core/symbol.cpp
+++ b/src/core/symbol.cpp
@@ -70,14 +70,14 @@ namespace Core {
*/
/*!
- * \qmlproperty TextRange Symbol::range
+ * \qmlproperty RangeMark Symbol::range
* The range enclosing this symbol not including leading/trailing whitespace but everything else like comments. This
* information is typically used to determine if the clients cursor is inside the symbol to reveal in the symbol in the
* UI.
*/
/*!
- * \qmlproperty TextRange Symbol::selectionRange
+ * \qmlproperty RangeMark Symbol::selectionRange
* The range that should be selected and revealed when this symbol is being picked, e.g. the name of a function. Must be
* contained by the `range`.
*/
@@ -86,8 +86,8 @@ Symbol::Symbol(QObject *parent, const QueryMatch &match, Kind kind)
: QObject(parent)
, m_name {match.get("name").text()}
, m_kind {kind}
- , m_range {match.get("range").toTextRange()}
- , m_selectionRange {match.get("selectionRange").toTextRange()}
+ , m_range {match.get("range")}
+ , m_selectionRange {match.get("selectionRange")}
, m_queryMatch {match}
{
}
@@ -181,24 +181,24 @@ Symbol::Kind Symbol::kind() const
return m_kind;
}
-Core::TextRange Symbol::range() const
+Core::RangeMark Symbol::range() const
{
return m_range;
}
-Core::TextRange Symbol::selectionRange() const
+Core::RangeMark 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();
+ auto references = codedocument->references(selectionRange().start());
+ kdalgorithms::erase_if(references, [this](const RangeMark &reference) {
+ return reference == m_selectionRange;
});
return references;
}
diff --git a/src/core/symbol.h b/src/core/symbol.h
index 397ff490..20ec911f 100644
--- a/src/core/symbol.h
+++ b/src/core/symbol.h
@@ -11,8 +11,7 @@
#pragma once
#include "querymatch.h"
-#include "textlocation.h"
-#include "textrange.h"
+#include "rangemark.h"
#include
@@ -28,8 +27,8 @@ class Symbol : public QObject
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(Kind kind READ kind CONSTANT)
- Q_PROPERTY(Core::TextRange range READ range CONSTANT)
- Q_PROPERTY(Core::TextRange selectionRange READ selectionRange CONSTANT)
+ Q_PROPERTY(Core::RangeMark range READ range CONSTANT)
+ Q_PROPERTY(Core::RangeMark selectionRange READ selectionRange CONSTANT)
public:
// Follow the LSP SymbolKind enum
@@ -68,8 +67,8 @@ class Symbol : public QObject
QString m_name;
Kind m_kind;
- TextRange m_range;
- TextRange m_selectionRange;
+ RangeMark m_range;
+ RangeMark m_selectionRange;
QueryMatch m_queryMatch;
CodeDocument *document() const;
@@ -86,13 +85,13 @@ class Symbol : public QObject
QString name() const;
virtual QString description() const;
Kind kind() const;
- Core::TextRange range() const;
- Core::TextRange selectionRange() const;
+ Core::RangeMark range() const;
+ Core::RangeMark selectionRange() const;
// 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/textdocument.cpp b/src/core/textdocument.cpp
index c0c98506..58f8f532 100644
--- a/src/core/textdocument.cpp
+++ b/src/core/textdocument.cpp
@@ -828,13 +828,13 @@ void TextDocument::selectRegion(int from, int to)
}
/*!
- * \qmlmethod TextDocument::selectRange(TextRange range)
+ * \qmlmethod TextDocument::selectRange(RangeMark range)
* Selects the range passed in parameter.
*/
-void TextDocument::selectRange(const TextRange &range)
+void TextDocument::selectRange(const RangeMark &range)
{
LOG("TextDocument::selectRange", range);
- selectRegion(range.start, range.end);
+ selectRegion(range.start(), range.end());
}
/*!
@@ -954,13 +954,13 @@ void TextDocument::replace(int from, int to, const QString &text)
}
/*!
- * \qmlmethod TextDocument::replace(TextRange range, string text)
+ * \qmlmethod TextDocument::replace(RangeMark range, string text)
* Replaces the text in the range `range` with the string `text`.
*/
-void TextDocument::replace(const TextRange &range, const QString &text)
+void TextDocument::replace(const RangeMark &range, const QString &text)
{
LOG("TextDocument::replace", range, text);
- replace(range.start, range.end, text);
+ replace(range.start(), range.end(), text);
}
/*!
@@ -1012,15 +1012,15 @@ void TextDocument::deleteRegion(int from, int to)
}
/*!
- * \qmlmethod TextDocument::deleteRange(TextRange range)
+ * \qmlmethod TextDocument::deleteRange(RangeMark range)
* Deletes the range passed in parameter.
*/
-void TextDocument::deleteRange(const TextRange &range)
+void TextDocument::deleteRange(const RangeMark &range)
{
LOG("TextDocument::deleteRange", range);
QTextCursor cursor(m_document->document());
- cursor.setPosition(range.start, QTextCursor::MoveAnchor);
- cursor.setPosition(range.end, QTextCursor::KeepAnchor);
+ cursor.setPosition(range.start(), QTextCursor::MoveAnchor);
+ cursor.setPosition(range.end(), QTextCursor::KeepAnchor);
cursor.removeSelectedText();
m_document->setTextCursor(cursor);
}
diff --git a/src/core/textdocument.h b/src/core/textdocument.h
index dc88ab9c..29270f94 100644
--- a/src/core/textdocument.h
+++ b/src/core/textdocument.h
@@ -12,7 +12,7 @@
#include "document.h"
#include "mark.h"
-#include "textrange.h"
+#include "rangemark.h"
#include
#include
@@ -135,7 +135,7 @@ public slots:
void selectPreviousWord(int count = 1);
void selectNextWord(int count = 1);
void selectRegion(int from, int to);
- void selectRange(const Core::TextRange &range);
+ void selectRange(const Core::RangeMark &range);
// Copy & paste
void copy();
@@ -149,7 +149,7 @@ public slots:
void insertAtPosition(const QString &text, int pos);
void replace(int length, const QString &text);
void replace(int from, int to, const QString &text);
- void replace(const Core::TextRange &range, const QString &text);
+ void replace(const Core::RangeMark &range, const QString &text);
// Deletion
void deleteLine(int line = -1);
@@ -161,7 +161,7 @@ public slots:
void deletePreviousCharacter(int count = 1);
void deleteNextCharacter(int count = 1);
void deleteRegion(int from, int to);
- void deleteRange(const Core::TextRange &range);
+ void deleteRange(const Core::RangeMark &range);
// Mark
Core::Mark createMark(int pos = -1);
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/src/core/textrange.cpp b/src/core/textrange.cpp
deleted file mode 100644
index e9622e25..00000000
--- a/src/core/textrange.cpp
+++ /dev/null
@@ -1,50 +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 "textrange.h"
-
-namespace Core {
-
-/*!
- * \qmltype TextRange
- * \brief Defines a range of text in a text document
- * \inqmlmodule Knut
- * \ingroup TextDocument
- * \sa TextDocument
- */
-/*!
- * \qmlproperty int TextRange::start
- * This read-only property defines the start position of the range.
- */
-/*!
- * \qmlproperty int TextRange::end
- * This read-only property defines the end position of the range.
- */
-/*!
- * \qmlproperty int TextRange::length
- * This read-only property returns the length of the range (end - start)
- */
-
-bool TextRange::contains(int pos) const
-{
- return (pos >= start && pos <= end);
-}
-
-bool TextRange::contains(const TextRange &range) const
-{
- return contains(range.start) && contains(range.end);
-}
-
-int TextRange::length() const
-{
- return end - start;
-}
-
-} // Core
diff --git a/src/core/textrange.h b/src/core/textrange.h
deleted file mode 100644
index 9ad68282..00000000
--- a/src/core/textrange.h
+++ /dev/null
@@ -1,39 +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
-
-namespace Core {
-
-struct TextRange
-{
- Q_GADGET
- Q_PROPERTY(int start MEMBER start CONSTANT)
- Q_PROPERTY(int end MEMBER end CONSTANT)
- Q_PROPERTY(int length READ length CONSTANT)
-
-public:
- int start;
- int end;
-
- Q_INVOKABLE QString toString() const { return QString("{%1, %2}").arg(start).arg(end); }
-
- bool contains(int pos) const;
- bool contains(const TextRange &range) const;
- int length() const;
-
- auto operator<=>(const TextRange &) const = default;
-};
-
-} // namespace Core
-
-Q_DECLARE_METATYPE(Core::TextRange)
diff --git a/tests/tst_codedocument.cpp b/tests/tst_codedocument.cpp
index fbb40c04..9fadc069 100644
--- a/tests/tst_codedocument.cpp
+++ b/tests/tst_codedocument.cpp
@@ -313,16 +313,16 @@ private slots:
QVERIFY(cppFile);
const auto before = cppFile->findSymbol("Section::bar")->range();
- QCOMPARE(before.start, 326);
- QCOMPARE(before.end, 386);
+ QCOMPARE(before.start(), 326);
+ QCOMPARE(before.end(), 386);
// Changing the code will cause the Language server to become out of sync with the
// state in Knut. Therefore the next language server call will fail.
cppFile->gotoStartOfDocument();
cppFile->insert("\n");
const auto after = cppFile->findSymbol("Section::bar")->range();
- QCOMPARE(after.start, 327);
- QCOMPARE(after.end, 387);
+ QCOMPARE(after.start(), 327);
+ QCOMPARE(after.end(), 387);
}
}
@@ -339,7 +339,7 @@ private slots:
QAction signalled;
- codedocument->hover(symbol->selectionRange().start + 1, [&signalled](const auto &) {
+ codedocument->hover(symbol->selectionRange().start() + 1, [&signalled](const auto &) {
signalled.trigger();
});
diff --git a/tests/tst_symbol.cpp b/tests/tst_symbol.cpp
index 6e6752e5..a8605fb7 100644
--- a/tests/tst_symbol.cpp
+++ b/tests/tst_symbol.cpp
@@ -37,7 +37,7 @@ class TestSymbol : public QObject
QString name;
QString returnType;
QList arguments;
- Core::TextRange range;
+ Core::RangeMark range;
bool isNull() { return name.isEmpty(); }
};
@@ -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 == symbol->selectionRange();
};
spdlog::warn("Finding references");
@@ -203,25 +203,25 @@ private slots:
spdlog::warn("Verifying document existence");
for (const auto &reference : references) {
- QVERIFY(reference.document);
+ QVERIFY(reference.document());
}
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);
}