mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
feat: Add settings for Quick Refactor
This commit is contained in:
parent
d1b72ef973
commit
96fec750aa
@ -194,7 +194,7 @@ LLMCore::ContextData QuickRefactorHandler::prepareContext(
|
|||||||
QTextCursor cursor = editor->textCursor();
|
QTextCursor cursor = editor->textCursor();
|
||||||
int cursorPos = cursor.position();
|
int cursorPos = cursor.position();
|
||||||
|
|
||||||
// TODO add selecting content before and after cursor/selection and from others opened files too
|
// TODO add selecting content before and after cursor/selection
|
||||||
QString fullContent = documentInfo.document->toPlainText();
|
QString fullContent = documentInfo.document->toPlainText();
|
||||||
QString taggedContent = fullContent;
|
QString taggedContent = fullContent;
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ LLMCore::ContextData QuickRefactorHandler::prepareContext(
|
|||||||
taggedContent.insert(cursorPos, "<cursor>");
|
taggedContent.insert(cursorPos, "<cursor>");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString systemPrompt = quickRefactorSystemPrompt();
|
QString systemPrompt = Settings::codeCompletionSettings().quickRefactorSystemPrompt();
|
||||||
systemPrompt += "\n\nFile information:";
|
systemPrompt += "\n\nFile information:";
|
||||||
systemPrompt += "\nLanguage: " + documentInfo.mimeType;
|
systemPrompt += "\nLanguage: " + documentInfo.mimeType;
|
||||||
systemPrompt += "\nFile path: " + documentInfo.filePath;
|
systemPrompt += "\nFile path: " + documentInfo.filePath;
|
||||||
@ -226,7 +226,7 @@ LLMCore::ContextData QuickRefactorHandler::prepareContext(
|
|||||||
systemPrompt += "\n- The output should be ready to insert directly into the editor";
|
systemPrompt += "\n- The output should be ready to insert directly into the editor";
|
||||||
systemPrompt += "\n- Follow the existing code style and indentation patterns";
|
systemPrompt += "\n- Follow the existing code style and indentation patterns";
|
||||||
|
|
||||||
if (Settings::codeCompletionSettings().useOpenFilesContext()) {
|
if (Settings::codeCompletionSettings().useOpenFilesInQuickRefactor()) {
|
||||||
systemPrompt += "\n\n" + m_contextManager.openedFilesContext({documentInfo.filePath});
|
systemPrompt += "\n\n" + m_contextManager.openedFilesContext({documentInfo.filePath});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +250,6 @@ void QuickRefactorHandler::handleLLMResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
m_isRefactoringInProgress = false;
|
|
||||||
|
|
||||||
QString cleanedResponse = response.trimmed();
|
QString cleanedResponse = response.trimmed();
|
||||||
if (cleanedResponse.startsWith("```")) {
|
if (cleanedResponse.startsWith("```")) {
|
||||||
int firstNewLine = cleanedResponse.indexOf('\n');
|
int firstNewLine = cleanedResponse.indexOf('\n');
|
||||||
@ -276,8 +274,6 @@ void QuickRefactorHandler::handleLLMResponse(
|
|||||||
LOG_MESSAGE("----------- END REFACTORED CODE -----------");
|
LOG_MESSAGE("----------- END REFACTORED CODE -----------");
|
||||||
|
|
||||||
emit refactoringCompleted(result);
|
emit refactoringCompleted(result);
|
||||||
} else {
|
|
||||||
emit refactoringProgress(response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,15 +290,4 @@ void QuickRefactorHandler::cancelRequest()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuickRefactorHandler::isRefactoringInProgress() const
|
|
||||||
{
|
|
||||||
return m_isRefactoringInProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QuickRefactorHandler::quickRefactorSystemPrompt() const
|
|
||||||
{
|
|
||||||
return QString("You are an expert code refactoring assistant specializing in C++, Qt, and QML "
|
|
||||||
"development.");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QodeAssist
|
} // namespace QodeAssist
|
||||||
|
@ -50,11 +50,9 @@ public:
|
|||||||
void sendRefactorRequest(TextEditor::TextEditorWidget *editor, const QString &instructions);
|
void sendRefactorRequest(TextEditor::TextEditorWidget *editor, const QString &instructions);
|
||||||
|
|
||||||
void cancelRequest();
|
void cancelRequest();
|
||||||
bool isRefactoringInProgress() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void refactoringCompleted(const QodeAssist::RefactorResult &result);
|
void refactoringCompleted(const QodeAssist::RefactorResult &result);
|
||||||
void refactoringProgress(const QString &partialResult);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void prepareAndSendRequest(
|
void prepareAndSendRequest(
|
||||||
@ -63,7 +61,6 @@ private:
|
|||||||
const Utils::Text::Range &range);
|
const Utils::Text::Range &range);
|
||||||
|
|
||||||
void handleLLMResponse(const QString &response, const QJsonObject &request, bool isComplete);
|
void handleLLMResponse(const QString &response, const QJsonObject &request, bool isComplete);
|
||||||
QString quickRefactorSystemPrompt() const;
|
|
||||||
LLMCore::ContextData prepareContext(
|
LLMCore::ContextData prepareContext(
|
||||||
TextEditor::TextEditorWidget *editor,
|
TextEditor::TextEditorWidget *editor,
|
||||||
const Utils::Text::Range &range,
|
const Utils::Text::Range &range,
|
||||||
|
@ -218,6 +218,18 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
maxChangesCacheSize.setRange(2, 1000);
|
maxChangesCacheSize.setRange(2, 1000);
|
||||||
maxChangesCacheSize.setDefaultValue(10);
|
maxChangesCacheSize.setDefaultValue(10);
|
||||||
|
|
||||||
|
// Quick refactor command settings
|
||||||
|
useOpenFilesInQuickRefactor.setSettingsKey(Constants::CC_USE_OPEN_FILES_IN_QUICK_REFACTOR);
|
||||||
|
useOpenFilesInQuickRefactor.setLabelText(
|
||||||
|
Tr::tr("Include context from open files in quick refactor"));
|
||||||
|
useOpenFilesInQuickRefactor.setDefaultValue(false);
|
||||||
|
quickRefactorSystemPrompt.setSettingsKey(Constants::CC_QUICK_REFACTOR_SYSTEM_PROMPT);
|
||||||
|
quickRefactorSystemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
|
||||||
|
quickRefactorSystemPrompt.setDefaultValue(
|
||||||
|
"You are an expert C++, Qt, and QML code completion assistant. Your task is to provide"
|
||||||
|
"precise and contextually appropriate code completions to insert depending on user "
|
||||||
|
"instructions.\n\n");
|
||||||
|
|
||||||
// Ollama Settings
|
// Ollama Settings
|
||||||
ollamaLivetime.setSettingsKey(Constants::CC_OLLAMA_LIVETIME);
|
ollamaLivetime.setSettingsKey(Constants::CC_OLLAMA_LIVETIME);
|
||||||
ollamaLivetime.setToolTip(
|
ollamaLivetime.setToolTip(
|
||||||
@ -303,6 +315,10 @@ CodeCompletionSettings::CodeCompletionSettings()
|
|||||||
Space{8},
|
Space{8},
|
||||||
Group{title(Tr::tr("Context Settings")), contextItem},
|
Group{title(Tr::tr("Context Settings")), contextItem},
|
||||||
Space{8},
|
Space{8},
|
||||||
|
Group{
|
||||||
|
title(Tr::tr("Quick Refactor Settings")),
|
||||||
|
Column{useOpenFilesInQuickRefactor, quickRefactorSystemPrompt}},
|
||||||
|
Space{8},
|
||||||
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
|
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
|
||||||
Stretch{1}};
|
Stretch{1}};
|
||||||
});
|
});
|
||||||
@ -371,6 +387,8 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
|||||||
resetAspect(customLanguages);
|
resetAspect(customLanguages);
|
||||||
resetAspect(showProgressWidget);
|
resetAspect(showProgressWidget);
|
||||||
resetAspect(useOpenFilesContext);
|
resetAspect(useOpenFilesContext);
|
||||||
|
resetAspect(useOpenFilesInQuickRefactor);
|
||||||
|
resetAspect(quickRefactorSystemPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,10 @@ public:
|
|||||||
Utils::BoolAspect useProjectChangesCache{this};
|
Utils::BoolAspect useProjectChangesCache{this};
|
||||||
Utils::IntegerAspect maxChangesCacheSize{this};
|
Utils::IntegerAspect maxChangesCacheSize{this};
|
||||||
|
|
||||||
|
// Quick refactor command settings
|
||||||
|
Utils::BoolAspect useOpenFilesInQuickRefactor{this};
|
||||||
|
Utils::StringAspect quickRefactorSystemPrompt{this};
|
||||||
|
|
||||||
// Ollama Settings
|
// Ollama Settings
|
||||||
Utils::StringAspect ollamaLivetime{this};
|
Utils::StringAspect ollamaLivetime{this};
|
||||||
Utils::IntegerAspect contextWindow{this};
|
Utils::IntegerAspect contextWindow{this};
|
||||||
|
@ -120,6 +120,10 @@ const char CC_MAX_CHANGES_CACHE_SIZE[] = "QodeAssist.ccMaxChangesCacheSize";
|
|||||||
const char CA_USE_SYSTEM_PROMPT[] = "QodeAssist.useChatSystemPrompt";
|
const char CA_USE_SYSTEM_PROMPT[] = "QodeAssist.useChatSystemPrompt";
|
||||||
const char CA_SYSTEM_PROMPT[] = "QodeAssist.chatSystemPrompt";
|
const char CA_SYSTEM_PROMPT[] = "QodeAssist.chatSystemPrompt";
|
||||||
|
|
||||||
|
// quick refactor command settings
|
||||||
|
const char CC_QUICK_REFACTOR_SYSTEM_PROMPT[] = "QodeAssist.ccQuickRefactorSystemPrompt";
|
||||||
|
const char CC_USE_OPEN_FILES_IN_QUICK_REFACTOR[] = "QodeAssist.ccUseOpenFilesInQuickRefactor";
|
||||||
|
|
||||||
// preset prompt settings
|
// preset prompt settings
|
||||||
const char CC_TEMPERATURE[] = "QodeAssist.ccTemperature";
|
const char CC_TEMPERATURE[] = "QodeAssist.ccTemperature";
|
||||||
const char CC_MAX_TOKENS[] = "QodeAssist.ccMaxTokens";
|
const char CC_MAX_TOKENS[] = "QodeAssist.ccMaxTokens";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user