mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
feat: Add additional language for handling to CodeCompletion settings (#150)
This commit is contained in:
parent
5808a892c1
commit
80646e2af0
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "CodeHandler.hpp"
|
||||
#include <settings/CodeCompletionSettings.hpp>
|
||||
#include <QFileInfo>
|
||||
#include <QHash>
|
||||
|
||||
@ -32,6 +33,44 @@ struct LanguageProperties
|
||||
QVector<QString> fileExtensions;
|
||||
};
|
||||
|
||||
const QVector<LanguageProperties> customLanguagesFromSettings()
|
||||
{
|
||||
QVector<LanguageProperties> customLanguages;
|
||||
|
||||
const QStringList customLanguagesList = Settings::codeCompletionSettings().customLanguages();
|
||||
for (const QString &entry : customLanguagesList) {
|
||||
if (entry.trimmed().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QStringList parts = entry.split(',');
|
||||
if (parts.size() < 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString name = parts[0].trimmed();
|
||||
QString commentStyle = parts[1].trimmed();
|
||||
QStringList modelNamesList = parts[2].trimmed().split(' ', Qt::SkipEmptyParts);
|
||||
QStringList extensionsList = parts[3].trimmed().split(' ', Qt::SkipEmptyParts);
|
||||
|
||||
if (!name.isEmpty() && !commentStyle.isEmpty() && !modelNamesList.isEmpty()
|
||||
&& !extensionsList.isEmpty()) {
|
||||
QVector<QString> modelNames;
|
||||
for (const auto &modelName : modelNamesList) {
|
||||
modelNames.append(modelName);
|
||||
}
|
||||
|
||||
QVector<QString> extensions;
|
||||
for (const auto &ext : extensionsList) {
|
||||
extensions.append(ext);
|
||||
}
|
||||
|
||||
customLanguages.append({name, commentStyle, modelNames, extensions});
|
||||
}
|
||||
}
|
||||
|
||||
return customLanguages;
|
||||
}
|
||||
const QVector<LanguageProperties> &getKnownLanguages()
|
||||
{
|
||||
static QVector<LanguageProperties> knownLanguages = {
|
||||
@ -55,6 +94,8 @@ const QVector<LanguageProperties> &getKnownLanguages()
|
||||
{"qml", "//", {"qml"}, {"qml"}},
|
||||
};
|
||||
|
||||
knownLanguages.append(customLanguagesFromSettings());
|
||||
|
||||
return knownLanguages;
|
||||
}
|
||||
|
||||
|
@ -192,6 +192,16 @@ CodeCompletionSettings::CodeCompletionSettings()
|
||||
"Here is the code context with insertion points:\n"
|
||||
"<code_context>\n${prefix}<cursor>${suffix}\n</code_context>\n\n");
|
||||
|
||||
customLanguages.setSettingsKey(Constants::CC_CUSTOM_LANGUAGES);
|
||||
customLanguages.setLabelText(
|
||||
Tr::tr("Additional Programming Languages for handling: Example: rust,//,rust rs,rs"));
|
||||
customLanguages.setToolTip(Tr::tr("Specify additional programming languages in format: "
|
||||
"name,comment_style,model_names,extensions\n"
|
||||
"Example: rust,//,rust rs,rs\n"
|
||||
"Fields: language name, comment prefix, names from LLM "
|
||||
"(space-separated), file extensions (space-separated)"));
|
||||
customLanguages.setDefaultValue({{"cmake,#,cmake,CMakeLists.txt"}, {"qmake,#,qmake,pro pri"}});
|
||||
|
||||
useProjectChangesCache.setSettingsKey(Constants::CC_USE_PROJECT_CHANGES_CACHE);
|
||||
useProjectChangesCache.setDefaultValue(true);
|
||||
useProjectChangesCache.setLabelText(Tr::tr("Max Changes Cache Size:"));
|
||||
@ -259,6 +269,7 @@ CodeCompletionSettings::CodeCompletionSettings()
|
||||
Row{useUserMessageTemplateForCC, Stretch{1}},
|
||||
systemPromptForNonFimModels,
|
||||
userMessageTemplateForCC,
|
||||
customLanguages,
|
||||
}},
|
||||
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
|
||||
|
||||
@ -355,6 +366,7 @@ void CodeCompletionSettings::resetSettingsToDefaults()
|
||||
resetAspect(useUserMessageTemplateForCC);
|
||||
resetAspect(userMessageTemplateForCC);
|
||||
resetAspect(systemPromptForNonFimModels);
|
||||
resetAspect(customLanguages);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
Utils::IntegerAspect autoCompletionCharThreshold{this};
|
||||
Utils::IntegerAspect autoCompletionTypingInterval{this};
|
||||
|
||||
Utils::StringListAspect customLanguages{this};
|
||||
|
||||
// General Parameters Settings
|
||||
Utils::DoubleAspect temperature{this};
|
||||
Utils::IntegerAspect maxTokens{this};
|
||||
|
@ -72,6 +72,7 @@ const char CA_TOKENS_THRESHOLD[] = "QodeAssist.caTokensThreshold";
|
||||
const char CA_LINK_OPEN_FILES[] = "QodeAssist.caLinkOpenFiles";
|
||||
const char CA_STREAM[] = "QodeAssist.caStream";
|
||||
const char CA_AUTOSAVE[] = "QodeAssist.caAutosave";
|
||||
const char CC_CUSTOM_LANGUAGES[] = "QodeAssist.ccCustomLanguages";
|
||||
|
||||
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
|
||||
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";
|
||||
|
Loading…
Reference in New Issue
Block a user