-
Notifications
You must be signed in to change notification settings - Fork 133
feat: add kconfig editor support #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ae00469
6f79248
393edd1
5233e5a
76f8c32
159bf05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "comments": { | ||
| "lineComment": "#" | ||
| }, | ||
| "brackets": [ | ||
| ["(", ")"], | ||
| ["menu", "endmenu"], | ||
| ["choice", "endchoice"] | ||
| ], | ||
| "autoClosingPairs": [ | ||
| ["(", ")"], | ||
| ["\"", "\""] | ||
| ], | ||
| "surroundingPairs": [ | ||
| ["(", ")"], | ||
| ["\"", "\""] | ||
| ], | ||
| "indentationRules": { | ||
| "increaseIndentPattern": "^([\\s]*)(menu|config|menuconfig|choice|help|comment)(.*)$", | ||
| "decreaseIndentPattern": "^(endmenu|endchoice|endif)(.*)$" | ||
| }, | ||
| "wordPattern": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b", | ||
| "folding": { | ||
| "markers": { | ||
| "start": "^\\s*#\\s*region\\b", | ||
| "end": "^\\s*#\\s*endregion\\b" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /******************************************************************************* | ||
| * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
| * Use is subject to license terms. | ||
| *******************************************************************************/ | ||
| package com.espressif.idf.ui.kconfig; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import org.eclipse.jface.text.contentassist.CompletionProposal; | ||
| import org.eclipse.jface.text.contentassist.ICompletionProposal; | ||
| import org.eclipse.jface.text.contentassist.IContentAssistProcessor; | ||
| import org.eclipse.jface.text.contentassist.IContextInformation; | ||
| import org.eclipse.jface.text.contentassist.IContextInformationValidator; | ||
|
|
||
| /** | ||
| * @author Kondal Kolipaka <kondal.kolipaka@espressif.com> | ||
| */ | ||
| public class KConfigContentAssistProcessor implements IContentAssistProcessor | ||
| { | ||
| private static final String[] MAIN_KEYWORDS = { | ||
| "config", "menuconfig", "choice", "endchoice", "menu", "endmenu", | ||
| "if", "endif", "source", "comment", "mainmenu" | ||
| }; | ||
|
|
||
| private static final String[] TYPES = { | ||
| "bool", "tristate", "int", "hex", "string" | ||
| }; | ||
|
|
||
| private static final String[] PROPERTIES = { | ||
| "default", "depends", "select", "imply", "range", "help", "prompt", | ||
| "visible", "optional" | ||
| }; | ||
|
|
||
| private static final String[] VALUES = { | ||
| "y", "n", "m" | ||
| }; | ||
|
|
||
|
Comment on lines
+21
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about having it in a separate interface or enum. Seems like these values can even be in an enum to avoid any NLS tags as well since they seem to be pretty consistent
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enums or interfaces are useful if you plan to reuse them elsewhere. Since these keywords are only used within the content assist processor, I don't think they're a good fit here @coderabbitai what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kolipakakondal I think your approach is reasonable here. The string arrays are simple, clear, and work well for the content assist processor. Since the logic is straightforward prefix matching and these constants aren't currently shared across multiple classes, keeping them colocated is pragmatic. One minor consideration: the The main benefit of enums would be type safety, but since you're doing string prefix matching anyway, it would just add conversion overhead without much practical gain in this specific use case. |
||
| @Override | ||
| public ICompletionProposal[] computeCompletionProposals(org.eclipse.jface.text.ITextViewer viewer, int offset) | ||
| { | ||
| List<ICompletionProposal> proposals = new ArrayList<>(); | ||
|
|
||
| String text = viewer.getDocument().get(); | ||
| int lineStart = text.lastIndexOf('\n', offset - 1) + 1; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. System.lineSeparator() seems like a safe way to avoid using '\n' directly |
||
| String lineText = text.substring(lineStart, offset).trim(); | ||
|
|
||
| for (String keyword : MAIN_KEYWORDS) { | ||
| if (keyword.toLowerCase().startsWith(lineText.toLowerCase())) { | ||
| proposals.add(createProposal(keyword, offset - lineText.length(), lineText.length(), keyword)); | ||
| } | ||
| } | ||
|
|
||
| for (String type : TYPES) { | ||
| if (type.toLowerCase().startsWith(lineText.toLowerCase())) { | ||
| proposals.add(createProposal(type, offset - lineText.length(), lineText.length(), type)); | ||
| } | ||
| } | ||
|
|
||
| for (String property : PROPERTIES) { | ||
| if (property.toLowerCase().startsWith(lineText.toLowerCase())) { | ||
| proposals.add(createProposal(property, offset - lineText.length(), lineText.length(), property)); | ||
| } | ||
| } | ||
|
|
||
| for (String value : VALUES) { | ||
| if (value.toLowerCase().startsWith(lineText.toLowerCase())) { | ||
| proposals.add(createProposal(value, offset - lineText.length(), lineText.length(), value)); | ||
| } | ||
| } | ||
|
|
||
| return proposals.toArray(new ICompletionProposal[proposals.size()]); | ||
| } | ||
|
|
||
| private ICompletionProposal createProposal(String text, int offset, int length, String displayText) { | ||
| return new CompletionProposal(text, offset, length, text.length(), null, displayText, null, null); | ||
| } | ||
|
|
||
| @Override | ||
| public IContextInformation[] computeContextInformation(org.eclipse.jface.text.ITextViewer viewer, int offset) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public char[] getCompletionProposalAutoActivationCharacters() | ||
| { | ||
| return new char[] { ' ', '\t', '\n' }; | ||
| } | ||
|
|
||
| @Override | ||
| public char[] getContextInformationAutoActivationCharacters() | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String getErrorMessage() | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public IContextInformationValidator getContextInformationValidator() | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /******************************************************************************* | ||
| * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. | ||
| * Use is subject to license terms. | ||
| *******************************************************************************/ | ||
| package com.espressif.idf.ui.kconfig; | ||
|
|
||
| import org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor; | ||
|
|
||
| /** | ||
| * @author Kondal Kolipaka <kondal.kolipaka@espressif.com> | ||
| */ | ||
| @SuppressWarnings("restriction") | ||
| public class KConfigEditor extends ExtensionBasedTextEditor | ||
| { | ||
| public static final String KCONFIG_EDITOR_ID = "com.espressif.idf.ui.kconfig.KConfigEditor"; | ||
| public static final String KCONFIG_CONTENT_TYPE = "com.espressif.idf.ui.kconfig.contentType"; | ||
| private static final String CONTEXT_ID = "com.espressif.idf.ui.kconfig.editorContext"; | ||
|
|
||
| public KConfigEditor() | ||
| { | ||
| super(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initializeKeyBindingScopes() { | ||
| setKeyBindingScopes(new String[] { CONTEXT_ID }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix file-extensions attribute: should contain only extension names, not full filename patterns.
The
file-extensionsattribute on line 867 contains full filename patterns ("Kconfig", "Kconfig.projbuild", "Kconfig.in"), but this attribute expects only extension names without dots or path separators. Thefile-patternsattribute on line 860 already correctly specifies these filenames.Remove the redundant
file-associationblock (lines 865–868), as the content-type'sfile-patternsalready establishes the file matching.📝 Committable suggestion
🤖 Prompt for AI Agents