Skip to content

Commit 8eba168

Browse files
committed
feat: Add additional language for handling to CodeCompletion settings
1 parent 5808a89 commit 8eba168

4 files changed

+67
-12
lines changed

CodeHandler.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "CodeHandler.hpp"
2222
#include <QFileInfo>
2323
#include <QHash>
24+
#include <settings/CodeCompletionSettings.hpp>
2425

2526
namespace QodeAssist {
2627

@@ -32,6 +33,45 @@ struct LanguageProperties
3233
QVector<QString> fileExtensions;
3334
};
3435

36+
const QVector<LanguageProperties> customLanguagesFromSettings()
37+
{
38+
QVector<LanguageProperties> customLanguages;
39+
40+
const QStringList customLanguagesList = Settings::codeCompletionSettings().customLanguages();
41+
for (const QString &entry : customLanguagesList) {
42+
if (entry.trimmed().isEmpty()) {
43+
continue;
44+
}
45+
46+
QStringList parts = entry.split(',');
47+
if (parts.size() < 4) {
48+
continue;
49+
}
50+
51+
QString name = parts[0].trimmed();
52+
QString commentStyle = parts[1].trimmed();
53+
QStringList modelNamesList = parts[2].trimmed().split(' ', Qt::SkipEmptyParts);
54+
QStringList extensionsList = parts[3].trimmed().split(' ', Qt::SkipEmptyParts);
55+
56+
if (!name.isEmpty() && !commentStyle.isEmpty() && !modelNamesList.isEmpty()
57+
&& !extensionsList.isEmpty()) {
58+
QVector<QString> modelNames;
59+
for (const auto &modelName : modelNamesList) {
60+
modelNames.append(modelName);
61+
}
62+
63+
QVector<QString> extensions;
64+
for (const auto &ext : extensionsList) {
65+
extensions.append(ext);
66+
}
67+
68+
customLanguages.append({name, commentStyle, modelNames, extensions});
69+
}
70+
}
71+
72+
return customLanguages;
73+
}
74+
3575
const QVector<LanguageProperties> &getKnownLanguages()
3676
{
3777
static QVector<LanguageProperties> knownLanguages = {
@@ -55,6 +95,8 @@ const QVector<LanguageProperties> &getKnownLanguages()
5595
{"qml", "//", {"qml"}, {"qml"}},
5696
};
5797

98+
knownLanguages.append(customLanguagesFromSettings());
99+
58100
return knownLanguages;
59101
}
60102

settings/CodeCompletionSettings.cpp

+22-12
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ CodeCompletionSettings::CodeCompletionSettings()
192192
"Here is the code context with insertion points:\n"
193193
"<code_context>\n${prefix}<cursor>${suffix}\n</code_context>\n\n");
194194

195+
customLanguages.setSettingsKey(Constants::CC_CUSTOM_LANGUAGES);
196+
customLanguages.setLabelText(Tr::tr("Additional Programming Languages for handling:"));
197+
customLanguages.setToolTip(Tr::tr("Specify additional programming languages in format: "
198+
"name,comment_style,model_names,extensions\n"
199+
"Example: rust,//,rust rs,rs"
200+
"Fields: language name, comment prefix, names from LLM "
201+
"(space-separated), file extensions (space-separated)"));
202+
customLanguages.setDefaultValue({{"cmake,#,cmake,CMakeLists.txt"}, {"qmake,#,qmake,pro pri"}});
203+
195204
useProjectChangesCache.setSettingsKey(Constants::CC_USE_PROJECT_CHANGES_CACHE);
196205
useProjectChangesCache.setDefaultValue(true);
197206
useProjectChangesCache.setLabelText(Tr::tr("Max Changes Cache Size:"));
@@ -249,18 +258,18 @@ CodeCompletionSettings::CodeCompletionSettings()
249258
contextGrid.addRow({Row{readFullFile}});
250259
contextGrid.addRow({Row{readFileParts, readStringsBeforeCursor, readStringsAfterCursor}});
251260

252-
auto contextItem = Column{
253-
Row{contextGrid, Stretch{1}},
254-
Row{useSystemPrompt, Stretch{1}},
255-
Group{title(Tr::tr("Prompts for FIM models")), Column{systemPrompt}},
256-
Group{
257-
title(Tr::tr("Prompts for Non FIM models")),
258-
Column{
259-
Row{useUserMessageTemplateForCC, Stretch{1}},
260-
systemPromptForNonFimModels,
261-
userMessageTemplateForCC,
262-
}},
263-
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
261+
auto contextItem = Column{Row{contextGrid, Stretch{1}},
262+
Row{useSystemPrompt, Stretch{1}},
263+
Group{title(Tr::tr("Prompts for FIM models")),
264+
Column{systemPrompt}},
265+
Group{title(Tr::tr("Prompts for Non FIM models")),
266+
Column{
267+
Row{useUserMessageTemplateForCC, Stretch{1}},
268+
systemPromptForNonFimModels,
269+
userMessageTemplateForCC,
270+
customLanguages,
271+
}},
272+
Row{useProjectChangesCache, maxChangesCacheSize, Stretch{1}}};
264273

265274
return Column{
266275
Row{Stretch{1}, resetToDefaults},
@@ -355,6 +364,7 @@ void CodeCompletionSettings::resetSettingsToDefaults()
355364
resetAspect(useUserMessageTemplateForCC);
356365
resetAspect(userMessageTemplateForCC);
357366
resetAspect(systemPromptForNonFimModels);
367+
resetAspect(customLanguages);
358368
}
359369
}
360370

settings/CodeCompletionSettings.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class CodeCompletionSettings : public Utils::AspectContainer
4242
Utils::IntegerAspect autoCompletionCharThreshold{this};
4343
Utils::IntegerAspect autoCompletionTypingInterval{this};
4444

45+
Utils::StringListAspect customLanguages{this};
46+
4547
// General Parameters Settings
4648
Utils::DoubleAspect temperature{this};
4749
Utils::IntegerAspect maxTokens{this};

settings/SettingsConstants.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const char CA_TOKENS_THRESHOLD[] = "QodeAssist.caTokensThreshold";
7272
const char CA_LINK_OPEN_FILES[] = "QodeAssist.caLinkOpenFiles";
7373
const char CA_STREAM[] = "QodeAssist.caStream";
7474
const char CA_AUTOSAVE[] = "QodeAssist.caAutosave";
75+
const char CC_CUSTOM_LANGUAGES[] = "QodeAssist.ccCustomLanguages";
7576

7677
const char QODE_ASSIST_GENERAL_OPTIONS_ID[] = "QodeAssist.GeneralOptions";
7778
const char QODE_ASSIST_GENERAL_SETTINGS_PAGE_ID[] = "QodeAssist.1GeneralSettingsPageId";

0 commit comments

Comments
 (0)