Commit 831a0069 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Remove completion/textEdit support

Removing this for now because it requires changes in KTE which cause
issues such as:
- a "blink" everytime you type a character during completion
- Regresses KDevelop performance wise as it now has to do *a lot* more
  work. This isn't KTE's fault but anyhow...
parent 0233d5c5
......@@ -346,11 +346,6 @@ public:
return k == LSPCompletionItemKind::Function || k == LSPCompletionItemKind::Method;
}
static bool hasTextEdit(const LSPCompletionItem &i)
{
return !i.textEdit.newText.isEmpty();
}
void executeCompletionItem(KTextEditor::View *view, const KTextEditor::Range &word, const QModelIndex &index) const override
{
if (index.row() >= m_matches.size()) {
......@@ -359,23 +354,13 @@ public:
QChar next = peekNextChar(view->document(), word);
QString matching;
KTextEditor::Range replaceRange = word;
const auto &completionItem = m_matches.at(index.row());
if (hasTextEdit(completionItem)) {
matching = completionItem.textEdit.newText;
auto range = completionItem.textEdit.range;
replaceRange = range;
} else {
matching = m_matches.at(index.row()).insertText;
// if there is already a '"' or >, remove it, this happens with #include "xx.h"
if ((next == QLatin1Char('"') && matching.endsWith(QLatin1Char('"'))) || (next == QLatin1Char('>') && matching.endsWith(QLatin1Char('>')))) {
matching.chop(1);
}
QString matching = m_matches.at(index.row()).insertText;
// if there is already a '"' or >, remove it, this happens with #include "xx.h"
if ((next == QLatin1Char('"') && matching.endsWith(QLatin1Char('"'))) || (next == QLatin1Char('>') && matching.endsWith(QLatin1Char('>')))) {
matching.chop(1);
}
const auto kind = completionItem.kind;
const LSPCompletionItemKind kind = m_matches.at(index.row()).kind;
// Is this a function?
// add parentheses if function and guestimated meaningful for language in question
// this covers at least the common cases such as clangd, python, etc
......@@ -385,7 +370,7 @@ public:
matching += QStringLiteral("()");
}
view->document()->replaceText(replaceRange, matching);
view->document()->replaceText(word, matching);
if (addParens) {
// place the cursor in between (|)
......
......@@ -243,7 +243,9 @@ struct LSPCompletionItem {
LSPMarkupContent documentation;
QString sortText;
QString insertText;
LSPTextEdit textEdit;
// Intentionally disabled because doesn't work well
// with KTE. See: https://invent.kde.org/utilities/kate/-/merge_requests/438
// LSPTextEdit textEdit;
};
struct LSPParameterInformation {
......
......@@ -604,11 +604,11 @@ static QList<LSPCompletionItem> parseDocumentCompletion(const QJsonValue &result
items = result.toObject().value(QStringLiteral("items")).toArray();
}
auto parseTextEdit = [](const QJsonObject &obj) -> LSPTextEdit {
auto newText = obj.value(QStringLiteral("newText")).toString();
auto range = parseRange(obj.value(QStringLiteral("range")).toObject());
return LSPTextEdit{range, newText};
};
// auto parseTextEdit = [](const QJsonObject &obj) -> LSPTextEdit {
// auto newText = obj.value(QStringLiteral("newText")).toString();
// auto range = parseRange(obj.value(QStringLiteral("range")).toObject());
// return LSPTextEdit{range, newText};
// };
for (const auto &vitem : items) {
const auto &item = vitem.toObject();
......@@ -624,8 +624,8 @@ static QList<LSPCompletionItem> parseDocumentCompletion(const QJsonValue &result
insertText = label;
}
auto kind = static_cast<LSPCompletionItemKind>(item.value(MEMBER_KIND).toInt());
auto textEdit = parseTextEdit(item.value(QStringLiteral("textEdit")).toObject());
ret.push_back({label, kind, detail, doc, sortText, insertText, textEdit});
// auto textEdit = parseTextEdit(item.value(QStringLiteral("textEdit")).toObject());
ret.push_back({label, kind, detail, doc, sortText, insertText /*, textEdit*/});
}
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment