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

Method prepareContext

QuickRefactorHandler.cpp:184–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184PluginLLMCore::ContextData QuickRefactorHandler::prepareContext(
185 TextEditor::TextEditorWidget *editor,
186 const Utils::Text::Range &range,
187 const QString &instructions)
188{
189 PluginLLMCore::ContextData context;
190
191 auto textDocument = editor->textDocument();
192 Context::DocumentReaderQtCreator documentReader;
193 auto documentInfo = documentReader.readDocument(textDocument->filePath().toUrlishString());
194
195 if (!documentInfo.document) {
196 LOG_MESSAGE("Error: Document is not available");
197 return context;
198 }
199
200 QTextCursor cursor = editor->textCursor();
201 int cursorPos = cursor.position();
202
203 Context::DocumentContextReader
204 reader(documentInfo.document, documentInfo.mimeType, documentInfo.filePath);
205
206 QString taggedContent;
207 bool readFullFile = Settings::quickRefactorSettings().readFullFile();
208
209 if (cursor.hasSelection()) {
210 int selStart = cursor.selectionStart();
211 int selEnd = cursor.selectionEnd();
212
213 QTextBlock startBlock = documentInfo.document->findBlock(selStart);
214 int startLine = startBlock.blockNumber();
215 int startColumn = selStart - startBlock.position();
216
217 QTextBlock endBlock = documentInfo.document->findBlock(selEnd);
218 int endLine = endBlock.blockNumber();
219 int endColumn = selEnd - endBlock.position();
220
221 QString contextBefore;
222 if (readFullFile) {
223 contextBefore = reader.readWholeFileBefore(startLine, startColumn);
224 } else {
225 contextBefore = reader.getContextBefore(
226 startLine, startColumn, Settings::quickRefactorSettings().readStringsBeforeCursor() + 1);
227 }
228
229 QString selectedText = cursor.selectedText();
230 selectedText.replace(QChar(0x2029), "\n");
231
232 QString contextAfter;
233 if (readFullFile) {
234 contextAfter = reader.readWholeFileAfter(endLine, endColumn);
235 } else {
236 contextAfter = reader.getContextAfter(
237 endLine, endColumn, Settings::quickRefactorSettings().readStringsAfterCursor() + 1);
238 }
239
240 taggedContent = contextBefore;
241 if (selStart == cursorPos) {

Callers

nothing calls this directly

Calls 13

textDocumentMethod · 0.80
readDocumentMethod · 0.80
readWholeFileBeforeMethod · 0.80
getContextBeforeMethod · 0.80
readWholeFileAfterMethod · 0.80
getContextAfterMethod · 0.80
systemPromptMethod · 0.80
openedFilesContextMethod · 0.80
appendMethod · 0.80
filePathMethod · 0.45
positionMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected