Skip to content

Commit 6f79248

Browse files
feat: add kconfig editor support
1 parent ae00469 commit 6f79248

File tree

5 files changed

+324
-1
lines changed

5 files changed

+324
-1
lines changed

bundles/com.espressif.idf.ui/META-INF/MANIFEST.MF

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.core.runtime,
1313
org.eclipse.cdt.cmake.ui,
1414
org.eclipse.swt;visibility:=reexport,
1515
org.eclipse.ui;visibility:=reexport,
16+
org.eclipse.ui.workbench,
1617
org.eclipse.jface,
1718
org.eclipse.cdt.core.native,
1819
org.eclipse.cdt.core;bundle-version="9.0.0",
@@ -33,6 +34,9 @@ Require-Bundle: org.eclipse.core.runtime,
3334
org.eclipse.nebula.widgets.xviewer;bundle-version="1.1.0",
3435
org.eclipse.nebula.widgets.xviewer.core;bundle-version="1.0.0",
3536
org.eclipse.text,
37+
org.eclipse.jface.text,
38+
org.eclipse.ui.genericeditor,
39+
org.eclipse.ui.editors,
3640
org.eclipse.cdt.native.serial,
3741
org.eclipse.ui.workbench.texteditor,
3842
org.eclipse.ui.intro,
@@ -45,7 +49,9 @@ Require-Bundle: org.eclipse.core.runtime,
4549
org.freemarker.freemarker,
4650
org.eclipse.tools.templates.freemarker,
4751
org.eclipse.cdt.lsp;bundle-version="3.0.0",
48-
org.eclipse.cdt.lsp.clangd;bundle-version="3.0.0"
52+
org.eclipse.cdt.lsp.clangd;bundle-version="3.0.0",
53+
org.eclipse.tm4e.registry,
54+
org.eclipse.tm4e.languageconfiguration
4955
Automatic-Module-Name: com.espressif.idf.ui
5056
Bundle-ActivationPolicy: lazy
5157
Bundle-RequiredExecutionEnvironment: JavaSE-17

bundles/com.espressif.idf.ui/plugin.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,16 @@
639639
id="com.espressif.idf.ui.editor.idfsize"
640640
name="%editor.name">
641641
</editor>
642+
<editor
643+
class="com.espressif.idf.ui.kconfig.KConfigEditor"
644+
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
645+
default="true"
646+
id="com.espressif.idf.ui.editor.kconfig"
647+
name="KConfig Editor">
648+
<contentTypeBinding
649+
contentTypeId="com.espressif.idf.ui.kconfig.contentType">
650+
</contentTypeBinding>
651+
</editor>
642652
</extension>
643653
<extension
644654
point="org.eclipse.cdt.launch.coreBuildTab">
@@ -845,6 +855,44 @@
845855
name="Partition Table"
846856
priority="normal">
847857
</content-type>
858+
<content-type
859+
base-type="org.eclipse.core.runtime.text"
860+
file-patterns="Kconfig,Kconfig.projbuild,Kconfig.in"
861+
id="com.espressif.idf.ui.kconfig.contentType"
862+
name="KConfig"
863+
priority="normal">
864+
</content-type>
865+
<file-association
866+
content-type="com.espressif.idf.ui.kconfig.contentType"
867+
file-extensions="Kconfig,Kconfig.projbuild,Kconfig.in">
868+
</file-association>
869+
</extension>
870+
<extension
871+
point="org.eclipse.tm4e.registry.grammars">
872+
<grammar
873+
contentTypeId="com.espressif.idf.ui.kconfig.contentType"
874+
path="syntaxes/kconfig.tmLanguage.json"
875+
scopeName="source.kconfig">
876+
</grammar>
877+
<scopeNameContentTypeBinding
878+
contentTypeId="com.espressif.idf.ui.kconfig.contentType"
879+
scopeName="source.kconfig">
880+
</scopeNameContentTypeBinding>
881+
</extension>
882+
<extension
883+
point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
884+
<languageConfiguration
885+
contentTypeId="com.espressif.idf.ui.kconfig.contentType"
886+
path="kconfig-language-configuration.json">
887+
</languageConfiguration>
888+
</extension>
889+
<extension
890+
point="org.eclipse.ui.genericeditor.contentAssistProcessors">
891+
<contentAssistProcessor
892+
class="com.espressif.idf.ui.kconfig.KConfigContentAssistProcessor"
893+
contentType="com.espressif.idf.ui.kconfig.contentType"
894+
triggerCharacters=" ">
895+
</contentAssistProcessor>
848896
</extension>
849897
<extension
850898
point="org.eclipse.ltk.core.refactoring.renameParticipants">
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*******************************************************************************
2+
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
3+
* Use is subject to license terms.
4+
*******************************************************************************/
5+
package com.espressif.idf.ui.kconfig;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
import org.eclipse.jface.text.contentassist.CompletionProposal;
11+
import org.eclipse.jface.text.contentassist.ICompletionProposal;
12+
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
13+
import org.eclipse.jface.text.contentassist.IContextInformation;
14+
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
15+
16+
/**
17+
* @author Kondal Kolipaka <[email protected]>
18+
*/
19+
public class KConfigContentAssistProcessor implements IContentAssistProcessor
20+
{
21+
private static final String[] MAIN_KEYWORDS = {
22+
"config", "menuconfig", "choice", "endchoice", "menu", "endmenu",
23+
"if", "endif", "source", "comment", "mainmenu"
24+
};
25+
26+
private static final String[] TYPES = {
27+
"bool", "tristate", "int", "hex", "string"
28+
};
29+
30+
private static final String[] PROPERTIES = {
31+
"default", "depends", "select", "imply", "range", "help", "prompt",
32+
"visible", "optional"
33+
};
34+
35+
private static final String[] VALUES = {
36+
"y", "n", "m"
37+
};
38+
39+
@Override
40+
public ICompletionProposal[] computeCompletionProposals(org.eclipse.jface.text.ITextViewer viewer, int offset)
41+
{
42+
List<ICompletionProposal> proposals = new ArrayList<>();
43+
44+
String text = viewer.getDocument().get();
45+
int lineStart = text.lastIndexOf('\n', offset - 1) + 1;
46+
String lineText = text.substring(lineStart, offset).trim();
47+
48+
for (String keyword : MAIN_KEYWORDS) {
49+
if (keyword.toLowerCase().startsWith(lineText.toLowerCase())) {
50+
proposals.add(createProposal(keyword, offset - lineText.length(), lineText.length(), keyword));
51+
}
52+
}
53+
54+
for (String type : TYPES) {
55+
if (type.toLowerCase().startsWith(lineText.toLowerCase())) {
56+
proposals.add(createProposal(type, offset - lineText.length(), lineText.length(), type));
57+
}
58+
}
59+
60+
for (String property : PROPERTIES) {
61+
if (property.toLowerCase().startsWith(lineText.toLowerCase())) {
62+
proposals.add(createProposal(property, offset - lineText.length(), lineText.length(), property));
63+
}
64+
}
65+
66+
for (String value : VALUES) {
67+
if (value.toLowerCase().startsWith(lineText.toLowerCase())) {
68+
proposals.add(createProposal(value, offset - lineText.length(), lineText.length(), value));
69+
}
70+
}
71+
72+
return proposals.toArray(new ICompletionProposal[proposals.size()]);
73+
}
74+
75+
private ICompletionProposal createProposal(String text, int offset, int length, String displayText) {
76+
return new CompletionProposal(text, offset, length, text.length(), null, displayText, null, null);
77+
}
78+
79+
@Override
80+
public IContextInformation[] computeContextInformation(org.eclipse.jface.text.ITextViewer viewer, int offset)
81+
{
82+
return null;
83+
}
84+
85+
@Override
86+
public char[] getCompletionProposalAutoActivationCharacters()
87+
{
88+
return new char[] { ' ', '\t', '\n' };
89+
}
90+
91+
@Override
92+
public char[] getContextInformationAutoActivationCharacters()
93+
{
94+
return null;
95+
}
96+
97+
@Override
98+
public String getErrorMessage()
99+
{
100+
return null;
101+
}
102+
103+
@Override
104+
public IContextInformationValidator getContextInformationValidator()
105+
{
106+
return null;
107+
}
108+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
3+
* Use is subject to license terms.
4+
*******************************************************************************/
5+
package com.espressif.idf.ui.kconfig;
6+
7+
import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor;
8+
9+
/**
10+
* @author Kondal Kolipaka <[email protected]>
11+
*/
12+
@SuppressWarnings("restriction")
13+
public class KConfigEditor extends ExtensionBasedTextEditor
14+
{
15+
public static final String KCONFIG_EDITOR_ID = "com.espressif.idf.ui.kconfig.KConfigEditor";
16+
public static final String KCONFIG_CONTENT_TYPE = "com.espressif.idf.ui.kconfig.contentType";
17+
private static final String CONTEXT_ID = "com.espressif.idf.ui.kconfig.editorContext";
18+
19+
public KConfigEditor()
20+
{
21+
super();
22+
}
23+
24+
@Override
25+
protected void initializeKeyBindingScopes() {
26+
setKeyBindingScopes(new String[] { CONTEXT_ID });
27+
}
28+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
3+
"name": "Kconfig",
4+
"fileTypes": ["Kconfig", "Kconfig.projbuild", "Kconfig.in"],
5+
"patterns": [
6+
{
7+
"include": "#lineComment"
8+
},
9+
{
10+
"include": "#keywords"
11+
},
12+
{
13+
"include": "#strings"
14+
},
15+
{
16+
"include": "#stringsValues"
17+
},
18+
{
19+
"include": "#types"
20+
},
21+
{
22+
"include": "#modifiers"
23+
},
24+
{
25+
"include": "#constants"
26+
},
27+
{
28+
"include": "#operators"
29+
},
30+
{
31+
"include": "#numbers"
32+
}
33+
],
34+
"repository": {
35+
"keywords": {
36+
"patterns": [
37+
{
38+
"name": "keyword.control.kconfig",
39+
"match": "\\b(config|choice|endchoice|menuconfig|endmenu|if|endif|source|comment|menu|endmenu)\\b"
40+
},
41+
{
42+
"name": "keyword.other.kconfig",
43+
"match": "\\b(help|prompt|default|depends|select|imply|range|visible|optional)\\b"
44+
}
45+
]
46+
},
47+
"strings": {
48+
"begin": "^(\\s*)(menu|mainmenu)",
49+
"end": "\n",
50+
"name": "variable.language.kconfig",
51+
"patterns": [
52+
{
53+
"name": "constant.character.escape.kconfig",
54+
"match": "\\\\."
55+
},
56+
{
57+
"name": "string.quoted.double.kconfig",
58+
"begin": "\"",
59+
"end": "\"",
60+
"patterns": [
61+
{
62+
"name": "constant.character.escape.kconfig",
63+
"match": "\\\\."
64+
}
65+
]
66+
}
67+
]
68+
},
69+
"stringsValues": {
70+
"name": "string.quoted.double.kconfig",
71+
"begin": "\"",
72+
"end": "\"",
73+
"patterns": [
74+
{
75+
"name": "constant.character.escape.kconfig",
76+
"match": "\\\\."
77+
}
78+
]
79+
},
80+
"types": {
81+
"patterns": [
82+
{
83+
"name": "support.type.kconfig",
84+
"match": "\\b(bool|tristate|int|hex|string)\\b"
85+
}
86+
]
87+
},
88+
"modifiers": {
89+
"patterns": [
90+
{
91+
"name": "support.function.kconfig",
92+
"match": "\\b(default|depends|select|imply|range|help|prompt)\\b"
93+
}
94+
]
95+
},
96+
"constants": {
97+
"patterns": [
98+
{
99+
"name": "constant.language.kconfig",
100+
"match": "\\b(y|n|m)\\b"
101+
}
102+
]
103+
},
104+
"operators": {
105+
"patterns": [
106+
{
107+
"name": "keyword.operator.kconfig",
108+
"match": "(=|!=|<|>|<=|>=)"
109+
}
110+
]
111+
},
112+
"lineComment": {
113+
"name": "comment.line.number-sign.kconfig",
114+
"begin": "#",
115+
"end": "$",
116+
"patterns": [
117+
{
118+
"name": "constant.character.escape.kconfig",
119+
"match": "\\\\."
120+
}
121+
]
122+
},
123+
"numbers": {
124+
"patterns": [
125+
{
126+
"name": "constant.numeric.kconfig",
127+
"match": "\\b(0x[0-9a-fA-F]+|[0-9]+)\\b"
128+
}
129+
]
130+
}
131+
},
132+
"scopeName": "source.kconfig"
133+
}

0 commit comments

Comments
 (0)