Skip to content

Fixing compilation after platform update. Some refactoring#612

Merged
VISTALL merged 1 commit intoconsulo:masterfrom
unv-unv:compilation-fix
Apr 21, 2026
Merged

Fixing compilation after platform update. Some refactoring#612
VISTALL merged 1 commit intoconsulo:masterfrom
unv-unv:compilation-fix

Conversation

@unv-unv
Copy link
Copy Markdown
Contributor

@unv-unv unv-unv commented Apr 21, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates C# live template macros to compile against the updated platform APIs, mainly by modernizing formatting and adopting the newer LocalizeValue-based presentable names.

Changes:

  • Migrate macro getPresentableName() implementations from String to LocalizeValue.
  • Refactor/modernize code style (lambdas, pattern matching instanceof, generics diamond).
  • Add/adjust read/UI access annotations in several macros and helper utilities.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/VariableTypeMacroBase.java Refactor base macro implementation; adds pattern matching and annotates some methods.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/TypeMacro.java Updates getPresentableName() to return LocalizeValue.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/SuggestVariableNameMacro.java Switches to Application.get() and updates presentable name localization.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/SuggestIndexVariableNameMacro.java Updates getPresentableName() to LocalizeValue and reformats code.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/IListVariableMacro.java Adds read-action annotation and updates presentable name localization.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/ForeachVariableMacro.java Adds read-action annotation and updates presentable name localization.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/ForeachComponentTypeMacro.java Updates getPresentableName() to LocalizeValue and reformats logic.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/CSharpLiveTemplateMacroUtil.java Minor refactor/modernization of variable resolution helper.
csharp-impl/src/main/java/consulo/csharp/impl/ide/liveTemplates/macro/ArrayVariableMacro.java Adds read-action annotation and updates presentable name localization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +104 to +109
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
assert file != null;
PsiElement element = file.findElementAt(offset);

assert element != null;
if(PsiUtilCore.getElementType(element) == CSharpTokens.IDENTIFIER)
{
DotNetVariable variable = CSharpLineMarkerUtil.getNameIdentifierAs(element, DotNetVariable.class);
if(variable != null)
{
return CSharpNameSuggesterUtil.getSuggestedVariableNames(variable);
}
}
else
{
final PsiFile fileCopy = (PsiFile) file.copy();
ApplicationManager.getApplication().runWriteAction(new Runnable()
{
@Override
public void run()
{
try
{
ReparseRangeUtil.reparseRange(fileCopy, offset, offset, "xxx");
}
catch(IncorrectOperationException e)
{
LOGGER.error(e);
}
assert element != null;
if (PsiUtilCore.getElementType(element) == CSharpTokens.IDENTIFIER) {
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using assert for file / element nullability here is unsafe in production because assertions may be disabled, which would turn these into potential NPEs (file.findElementAt(offset) and subsequent PSI access). Prefer explicit null checks with an early return (e.g., Collections.emptyList()), so the macro fails gracefully when the editor/document isn't backed by a PSI file or no element exists at the offset.

Copilot uses AI. Check for mistakes.
Comment on lines +53 to +58
@Override
public Result calculateResult(Expression[] params, ExpressionContext context) {
final PsiElement[] vars = getVariables(params, context);
if (vars == null || vars.length == 0) {
return null;
}
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateResult() calls getVariables() and constructs a PsiElementResult based on PSI, but the method itself is not annotated with @RequiredReadAction (only calculateLookupItems() is). Several implementations of getVariables() were updated to require a read action, so calculateResult() should also be marked @RequiredReadAction (or otherwise ensure it is always invoked under a read lock) to avoid read/write access violations at runtime.

Copilot uses AI. Check for mistakes.
Comment on lines +64 to +65
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
PsiElement place = file.findElementAt(offset);
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPsiFile() and findElementAt() can return null. As written, file.findElementAt(offset) and then resolveAllVariables(place) will throw if either file or place is null. Please add null-handling (e.g., return null/default value when file or place is null) before dereferencing and before calling resolveAllVariables().

Suggested change
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
PsiElement place = file.findElementAt(offset);
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
if (file == null) {
return new TextResult(getDefaultValue());
}
PsiElement place = file.findElementAt(offset);
if (place == null) {
return new TextResult(getDefaultValue());
}

Copilot uses AI. Check for mistakes.
@VISTALL VISTALL merged commit f3898b3 into consulo:master Apr 21, 2026
5 checks passed
@unv-unv unv-unv deleted the compilation-fix branch April 21, 2026 10:56
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.

3 participants