Repository navigation
Fixing compilation after platform update. Some refactoring - #309
Conversation
|
@claude When I'm typing "re" Consulo suggests keywords "return" and "record", but when I'm typing "yi" it doesn't suggest "yield". Need analysis where such a suggestions located and what to add to cover latest Java features. Compare with IDEA CE (https://github.com/jetbrains/intellij-community). |
|
Claude finished @unv-unv's task in 3m 12s —— View job Analysis: why
|
| Consulo | IntelliJ CE (master) | |
|---|---|---|
| Keyword completion | plugin/src/main/java/com/intellij/java/impl/codeInsight/completion/JavaKeywordCompletion.java, called from JavaCompletionContributor.java:330 |
java/java-impl/src/com/intellij/java/completion/modcommand/KeywordCompletionItemProvider.java. The old JavaKeywordCompletion is now a deprecated stub. |
Modifiers (public, static, …) |
ModifierChooser.java |
ModifierChooser.java |
module-info.java |
JavaModuleCompletion.java |
KeywordCompletionItemProvider.addModuleKeywords() |
record works because addClassKeywords() (line 565) checks JavaFeature.RECORDS. Consulo has no matching code for yield: PsiKeyword.YIELD is defined but nothing in completion uses it. The parser (StatementParser.java:316) and PSI (PsiYieldStatement, PsiSwitchExpression, PsiSwitchLabeledRuleStatement) already support it, so only completion is missing.
What IntelliJ does for yield, and what to port
1. addBreakContinue() (Consulo line 943). IntelliJ adds an else if branch after the PsiSwitchStatement check:
if (psiElement().inside(PsiSwitchStatement.class).accepts(myPosition)) {
addKeyword(br);
}
else if (psiElement().inside(PsiSwitchExpression.class).accepts(myPosition) &&
PsiUtil.isAvailable(JavaFeature.SWITCH_EXPRESSION, myPosition)) {
addKeyword(new OverridableSpace(createKeyword(PsiKeyword.YIELD), TailType.INSERT_SPACE));
}This covers case X: yi<caret> and case X -> { yi<caret> }.
2. Don't offer return inside a switch expression. In addStatementKeywords(), IntelliJ wraps return:
if (!(PsiTreeUtil.getParentOfType(myPosition, PsiSwitchExpression.class, PsiLambdaExpression.class) instanceof PsiSwitchExpression)) {
// add RETURN
}3. Single-statement switch rules (case X -> yi<caret>). That position is not a statement position, so step 1 never runs there. IntelliJ handles it in the non-statement branch of addKeywords():
else {
PsiSwitchLabeledRuleStatement rule = findEnclosingSwitchRule(myPosition);
if (rule != null) addSwitchRuleKeywords(rule);
}addSwitchRuleKeywords offers throw, assert, while, do, for, if, try, plus return for a switch statement or yield for a switch expression. All except throw get an extra handler, wrapRuleIntoBlock, which turns -> stmt into -> { stmt } using BlockUtils.expandSingleStatementToBlockStatement.
Other gaps for recent Java versions
| Feature | IntelliJ | Consulo |
|---|---|---|
switch as an expression (int x = sw<caret>) |
addExpressionKeywords() adds switch when !statementPosition && ENHANCED_SWITCH |
Missing; switch is only offered at statement positions |
when guards (Java 21) |
addWhen(), PATTERN_GUARDS_AND_RECORD_PATTERNS |
Missing (PsiKeyword.WHEN is unused) |
case/default in switch expressions and rule switches |
getSwitchFromLabelPosition() returns PsiSwitchBlock; START_SWITCH uses PsiSwitchBlock |
Hardcoded to PsiSwitchStatement (lines 95–96, 388–398), so no case/default/enum case X: inside switch expressions |
Pattern cases (Java 21): case null, case null, default, sealed-inheritor cases, null inside a case label |
addEnhancedCases(), addPatternMatchingInSwitchCases(), addSealedHierarchyCases(), addCaseAfterNullDefault(), addCaseNullToSwitch() |
Missing |
sealed / non-sealed modifiers (Java 17) |
ModifierChooser adds both for SEALED_CLASSES |
Missing (only permits is offered) |
| Primitive types in patterns (Java 23 preview) | suggestPrimitiveTypesForPattern(), suggestPrimitivesInsideDeconstructionListPattern() |
Missing |
import module (Java 25) |
addFileHeaderKeywords(): module after import for MODULE_IMPORT_DECLARATIONS |
Missing; JavaFeature.MODULE_IMPORT_DECLARATIONS itself doesn't exist in Consulo |
No keywords after :: |
canAddKeywords() |
Missing |
Suggested order
- Port
yield(steps 1–3 above) and thereturnexclusion. This is small and self-contained. - Change
START_SWITCH,getSwitchFromLabelPositionandaddEnumCasesfromPsiSwitchStatementtoPsiSwitchBlock, and addswitchas an expression keyword. - Add
sealed/non-sealedtoModifierChooser, plusaddWhen(). - Port the pattern-switch cases and the
import module/ primitive-pattern parts. These are larger; per the jetbrains-sync approach, it may be easier to portKeywordCompletionItemProvideras a whole, adapted toLookupElement(Consulo doesn't have ModCompletion yet).
This is analysis only; I haven't changed any code. Tell me if you want me to implement step 1 (or more) on a branch.
No description provided.