Skip to content

Fixing compilation after platform update. Some refactoring - #309

Merged
VISTALL merged 1 commit into
consulo:masterfrom
unv-unv:compilation-fix
Oct 3, 2026
Merged

VISTALL merged 1 commit into
consulo:masterfrom
unv-unv:compilation-fix

Conversation

@unv-unv

@unv-unv unv-unv commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@VISTALL
VISTALL merged commit ae9b274 into consulo:master Oct 3, 2026
1 check passed
@unv-unv
unv-unv deleted the compilation-fix branch October 3, 2026 19:32
@unv-unv

unv-unv commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@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).

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @unv-unv's task in 3m 12s —— View job


Analysis: why yield (and some other modern keywords) aren't suggested

  • Locate Consulo's Java keyword completion code
  • Find why record works but yield doesn't
  • Compare with IntelliJ Community
  • List what's missing for recent Java features

Where the suggestions come from

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

  1. Port yield (steps 1–3 above) and the return exclusion. This is small and self-contained.
  2. Change START_SWITCH, getSwitchFromLabelPosition and addEnumCases from PsiSwitchStatement to PsiSwitchBlock, and add switch as an expression keyword.
  3. Add sealed/non-sealed to ModifierChooser, plus addWhen().
  4. 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 port KeywordCompletionItemProvider as a whole, adapted to LookupElement (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants