MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / sendCompletionToClient

Method sendCompletionToClient

LLMClientInterface.cpp:393–465  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391}
392
393void LLMClientInterface::sendCompletionToClient(
394 const QString &completion, const QJsonObject &request, bool isComplete)
395{
396 auto filePath = Context::extractFilePathFromRequest(request);
397 auto documentInfo = m_documentReader.readDocument(filePath);
398 bool isPreset1Active = m_contextManager->isSpecifyCompletion(documentInfo);
399
400 auto templateName = !isPreset1Active ? m_generalSettings.ccTemplate()
401 : m_generalSettings.ccPreset1Template();
402
403 auto promptTemplate = m_promptProvider->getTemplateByName(templateName);
404
405 QJsonObject position = request["params"].toObject()["doc"].toObject()["position"].toObject();
406
407 QJsonObject response;
408 response["jsonrpc"] = "2.0";
409 response[LanguageServerProtocol::idKey] = request["id"];
410
411 QJsonObject result;
412 QJsonArray completions;
413 QJsonObject completionItem;
414
415 LOG_MESSAGE(QString("Completions before filter: \n%1").arg(completion));
416
417 QString outputHandler = m_completeSettings.modelOutputHandler.stringValue();
418 QString processedCompletion;
419
420 if (outputHandler == "Raw text") {
421 processedCompletion = completion;
422 } else if (outputHandler == "Force processing") {
423 processedCompletion = CodeHandler::processText(completion,
424 Context::extractFilePathFromRequest(request));
425 } else { // "Auto"
426 processedCompletion = CodeHandler::hasCodeBlocks(completion)
427 ? CodeHandler::processText(completion,
428 Context::extractFilePathFromRequest(
429 request))
430 : completion;
431 }
432
433 if (processedCompletion.endsWith('\n')) {
434 QString withoutTrailing = processedCompletion.chopped(1);
435 if (!withoutTrailing.contains('\n')) {
436 LOG_MESSAGE(QString("Removed trailing newline from single-line completion"));
437 processedCompletion = withoutTrailing;
438 }
439 }
440
441 completionItem[LanguageServerProtocol::textKey] = processedCompletion;
442
443 QJsonObject range;
444 range["start"] = position;
445 range["end"] = position;
446
447 completionItem[LanguageServerProtocol::rangeKey] = range;
448 completionItem[LanguageServerProtocol::positionKey] = position;
449 completions.append(completionItem);
450 result["completions"] = completions;

Callers

nothing calls this directly

Calls 8

readDocumentMethod · 0.80
isSpecifyCompletionMethod · 0.80
appendMethod · 0.80
endTimeMeasurementMethod · 0.80
getTemplateByNameMethod · 0.45
toJsonMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected