| 337 | } |
| 338 | |
| 339 | void QodeAssistClient::scheduleRequest(TextEditor::TextEditorWidget *editor) |
| 340 | { |
| 341 | if (m_runningRequests.contains(editor)) { |
| 342 | if (Settings::codeCompletionSettings().cancelOnInput()) |
| 343 | cancelRunningRequest(editor); |
| 344 | else |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | auto it = m_scheduledRequests.find(editor); |
| 349 | if (it == m_scheduledRequests.end()) { |
| 350 | auto timer = new QTimer(this); |
| 351 | timer->setSingleShot(true); |
| 352 | connect(timer, &QTimer::timeout, this, [this, editor]() { |
| 353 | if (!editor || m_runningRequests.contains(editor)) |
| 354 | return; |
| 355 | if (editor->textCursor().position() |
| 356 | != m_scheduledRequests[editor]->property("cursorPosition").toInt()) |
| 357 | return; |
| 358 | requestCompletions(editor); |
| 359 | }); |
| 360 | connect(editor, &TextEditorWidget::destroyed, this, [this, editor]() { |
| 361 | delete m_scheduledRequests.take(editor); |
| 362 | cancelRunningRequest(editor); |
| 363 | }); |
| 364 | it = m_scheduledRequests.insert(editor, timer); |
| 365 | } |
| 366 | |
| 367 | it.value()->setProperty("cursorPosition", editor->textCursor().position()); |
| 368 | it.value()->start(Settings::codeCompletionSettings().startSuggestionTimer()); |
| 369 | } |
| 370 | void QodeAssistClient::handleCompletions( |
| 371 | const GetCompletionRequest::Response &response, TextEditor::TextEditorWidget *editor) |
| 372 | { |