|
6 | 6 | #include <QJsonDocument> |
7 | 7 | #include <QJsonObject> |
8 | 8 |
|
9 | | -AngelLsp::AngelLsp() { |
10 | | - // create a single timer reused for completion debounce |
11 | | - m_completionTimer = new QTimer(this); |
12 | | - m_completionTimer->setSingleShot(true); |
13 | | - connect(m_completionTimer, &QTimer::timeout, this, [this]() { |
14 | | - // before sending new completion, cancel previous pending request if any |
15 | | - if (m_lastCompletionRequestId != 0) { |
16 | | - sendCancelRequest(m_lastCompletionRequestId); |
17 | | - // do not reset id here; server may already have processed it |
18 | | - } |
19 | | - // send actual completion request (async, id returned) |
20 | | - QJsonObject pos; |
21 | | - pos["line"] = m_pendingCompletion.line; |
22 | | - pos["character"] = m_pendingCompletion.character; |
23 | | - QJsonObject p; |
24 | | - p["textDocument"] = QJsonObject{{"uri", m_pendingCompletion.uri}}; |
25 | | - p["position"] = pos; |
26 | | - int id = sendRequest("textDocument/completion", p); |
27 | | - m_lastCompletionRequestId = id; |
28 | | - // response will be delivered to handleIncomingMessage -> |
29 | | - // requestFinished signal |
30 | | - }); |
31 | | -} |
| 9 | +AngelLsp::AngelLsp() {} |
32 | 10 |
|
33 | 11 | AngelLsp &AngelLsp::instance() { |
34 | 12 | static AngelLsp ins; |
@@ -227,9 +205,9 @@ QJsonValue AngelLsp::requestResolve(const QJsonValue &symbol, int timeoutMs) { |
227 | 205 | return sendRequestSync("completionItem/resolve", symbol, timeoutMs); |
228 | 206 | } |
229 | 207 |
|
230 | | -int AngelLsp::sendRequest(const QString &method, const QJsonValue ¶ms, |
231 | | - int) { |
232 | | - int id = m_nextId++; |
| 208 | +qint64 AngelLsp::sendRequest(const QString &method, const QJsonValue ¶ms, |
| 209 | + int) { |
| 210 | + qint64 id = m_nextId++; |
233 | 211 | QJsonObject obj; |
234 | 212 | obj["jsonrpc"] = "2.0"; |
235 | 213 | obj["id"] = id; |
@@ -261,7 +239,7 @@ void AngelLsp::changeDocument(const QString &uri, qint64 version, |
261 | 239 |
|
262 | 240 | QJsonValue AngelLsp::sendRequestSync(const QString &method, |
263 | 241 | const QJsonValue ¶ms, int timeoutMs) { |
264 | | - int id = m_nextId++; |
| 242 | + qint64 id = m_nextId++; |
265 | 243 | QJsonObject obj; |
266 | 244 | obj["jsonrpc"] = "2.0"; |
267 | 245 | obj["id"] = id; |
@@ -480,20 +458,6 @@ void AngelLsp::handleIncomingMessage(const QJsonObject &msg) { |
480 | 458 | m_outstandingRequests.remove(id); |
481 | 459 | } |
482 | 460 |
|
483 | | - // if this response is for a completion request, emit completionReceived |
484 | | - if (!method.isEmpty() && |
485 | | - method == QStringLiteral("textDocument/completion")) { |
486 | | - Q_EMIT completionReceived(payload); |
487 | | - // if it matches the last completion id, clear it |
488 | | - if (m_lastCompletionRequestId == id) |
489 | | - m_lastCompletionRequestId = 0; |
490 | | - } |
491 | | - // if response matches lastCompletionRequestId but method mapping not |
492 | | - // present, still check and clear |
493 | | - if (m_lastCompletionRequestId == id) { |
494 | | - m_lastCompletionRequestId = 0; |
495 | | - } |
496 | | - |
497 | 461 | if (m_pendingLoops.contains(id)) { |
498 | 462 | QEventLoop *loop = m_pendingLoops[id]; |
499 | 463 | if (loop) |
@@ -640,14 +604,3 @@ QJsonObject AngelLsp::jsonLSPDocLocation(const LSP::Location &loc) { |
640 | 604 | r["character"] = loc.character; |
641 | 605 | return r; |
642 | 606 | } |
643 | | - |
644 | | -void AngelLsp::requestCompletionDebounced(const QString &uri, int line, |
645 | | - int character, int debounceMs) { |
646 | | - // store latest requested position |
647 | | - m_pendingCompletion.uri = uri; |
648 | | - m_pendingCompletion.line = line; |
649 | | - m_pendingCompletion.character = character; |
650 | | - // restart debounce timer |
651 | | - m_completionTimer->stop(); |
652 | | - m_completionTimer->start(debounceMs); |
653 | | -} |
0 commit comments