|
31 | 31 | #include "context/DocumentContextReader.hpp"
|
32 | 32 | #include "llmcore/PromptTemplateManager.hpp"
|
33 | 33 | #include "llmcore/ProvidersManager.hpp"
|
| 34 | +#include "llmcore/Utils.hpp" |
34 | 35 | #include "logger/Logger.hpp"
|
35 | 36 | #include "settings/CodeCompletionSettings.hpp"
|
36 | 37 | #include "settings/GeneralSettings.hpp"
|
37 | 38 |
|
38 | 39 | namespace QodeAssist {
|
39 | 40 |
|
40 |
| -QString extractFilePathFromRequest(const QJsonObject &request) |
41 |
| -{ |
42 |
| - QJsonObject params = request["params"].toObject(); |
43 |
| - QJsonObject doc = params["doc"].toObject(); |
44 |
| - QString uri = doc["uri"].toString(); |
45 |
| - return QUrl(uri).toLocalFile(); |
46 |
| -} |
47 |
| - |
48 | 41 | LLMClientInterface::LLMClientInterface(
|
49 | 42 | const Settings::GeneralSettings &generalSettings,
|
50 | 43 | const Settings::CodeCompletionSettings &completeSettings)
|
@@ -263,20 +256,20 @@ LLMCore::ContextData LLMClientInterface::prepareContext(
|
263 | 256 | QJsonObject doc = params["doc"].toObject();
|
264 | 257 | QJsonObject position = doc["position"].toObject();
|
265 | 258 |
|
266 |
| - Utils::FilePath filePath = Utils::FilePath::fromString(extractFilePathFromRequest(request)); |
| 259 | + auto filePath = LLMCore::extractFilePathFromRequest(request); |
267 | 260 | TextEditor::TextDocument *textDocument = TextEditor::TextDocument::textDocumentForFilePath(
|
268 |
| - filePath); |
| 261 | + Utils::FilePath::fromString(filePath)); |
269 | 262 |
|
270 | 263 | if (!textDocument) {
|
271 |
| - LOG_MESSAGE("Error: Document is not available for" + filePath.toString()); |
| 264 | + LOG_MESSAGE("Error: Document is not available for" + filePath); |
272 | 265 | return LLMCore::ContextData{};
|
273 | 266 | }
|
274 | 267 |
|
275 | 268 | int cursorPosition = position["character"].toInt();
|
276 | 269 | int lineNumber = position["line"].toInt();
|
277 | 270 |
|
278 |
| - Context::DocumentContextReader reader( |
279 |
| - textDocument->document(), textDocument->mimeType(), textDocument->filePath().toString()); |
| 271 | + Context::DocumentContextReader |
| 272 | + reader(textDocument->document(), textDocument->mimeType(), filePath); |
280 | 273 | return reader.prepareContext(lineNumber, cursorPosition, m_completeSettings);
|
281 | 274 | }
|
282 | 275 |
|
@@ -306,7 +299,7 @@ void LLMClientInterface::sendCompletionToClient(
|
306 | 299 | QString processedCompletion
|
307 | 300 | = promptTemplate->type() == LLMCore::TemplateType::Chat
|
308 | 301 | && m_completeSettings.smartProcessInstuctText()
|
309 |
| - ? CodeHandler::processText(completion, extractFilePathFromRequest(request)) |
| 302 | + ? CodeHandler::processText(completion, LLMCore::extractFilePathFromRequest(request)) |
310 | 303 | : completion;
|
311 | 304 |
|
312 | 305 | completionItem[LanguageServerProtocol::textKey] = processedCompletion;
|
|
0 commit comments