Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
- Centralizing file path logging into `PluginLogger`. (#8707)
- Redacting the Flutter SDK path when logging the command line in `FlutterApp`. (#9203)
- Migrated `FlutterCompletionContributor` (color and icon completion previews) to IntelliJ `CompletionContributor` for LSP completion support. (#9186)
- Migrating Flutter live templates and `DART_TOPLEVEL` context registration to declarative XML extensions to support dynamic plugin loading without IDE restarts. (#9207)

### Removed
- Support for platform version 2025.2. (#9255)
- Eager legacy Dart Analysis Server startup when enabling Dart support for Gradle modules. (#9177)
- Legacy `FlutterLiveTemplatesProvider` implementation in favor of declarative `<defaultLiveTemplates>`. (#9207)

### Fixed
- Android `I/flutter` log lines in the Run console being folded as Flutter command lines (#9265).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ intellijPlatform {
VerifyPluginTask.FailureLevel.PLUGIN_STRUCTURE_WARNINGS,
VerifyPluginTask.FailureLevel.MISSING_DEPENDENCIES,
VerifyPluginTask.FailureLevel.INVALID_PLUGIN,
// VerifyPluginTask.FailureLevel.NOT_DYNAMIC,
VerifyPluginTask.FailureLevel.NOT_DYNAMIC,
)
verificationReportsFormats = VerifyPluginTask.VerificationReportsFormats.ALL
subsystemsToCheck = VerifyPluginTask.Subsystems.ALL
Expand Down
4 changes: 2 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@
<programRunner implementation="io.flutter.run.test.FlutterTestRunner"/>
<runLineMarkerContributor language="Dart" implementationClass="io.flutter.run.test.FlutterTestLineMarkerContributor"/>

<defaultLiveTemplatesProvider implementation="io.flutter.template.FlutterLiveTemplatesProvider"/>
<liveTemplateContext contextId="DART_TOPLEVEL" implementation="io.flutter.template.DartToplevelTemplateContextType"/>
<defaultLiveTemplates file="liveTemplates/flutter_miscellaneous.xml"/>
<liveTemplateContext contextId="DART_TOPLEVEL" baseContextId="DART" implementation="io.flutter.template.DartToplevelTemplateContextType"/>

<!-- IDEA only -->
<moduleBuilder builderClass="io.flutter.module.FlutterModuleBuilder"/>
Expand Down
13 changes: 4 additions & 9 deletions src/io/flutter/template/ABOUT.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
<!--* freshness: { reviewed: '2026-10-25' } *-->
<!--* freshness: { reviewed: '2026-11-03' } *-->
# Flutter Templates

## Overview
Provides Live Templates for Flutter and Dart code snippets to accelerate development. (There are no file templates in this package.)

## Interface
- [`io.flutter.template.DartToplevelTemplateContextType`](DartToplevelTemplateContextType.java) - Extends the Dart plugin's `DartTemplateContextType`; context id `DART_TOPLEVEL`, presentable name `Top-level`.
- [`io.flutter.template.DartToplevelTemplateContextType`](DartToplevelTemplateContextType.java) - Extends the Dart plugin's `DartTemplateContextType`; context id `DART_TOPLEVEL`, base context id `DART`, presentable name `Top-level`.
- `io.flutter.template.DartToplevelTemplateContextType.DartToplevelTemplateContextType()`
- [`io.flutter.template.FlutterLiveTemplatesProvider`](FlutterLiveTemplatesProvider.java)
- `io.flutter.template.FlutterLiveTemplatesProvider.getDefaultLiveTemplateFiles()`
- `io.flutter.template.FlutterLiveTemplatesProvider.getHiddenLiveTemplateFiles()`

## Resources & Registration
- Both classes are registered in [`plugin.xml`](../../../../resources/META-INF/plugin.xml) as `defaultLiveTemplatesProvider` and `liveTemplateContext contextId="DART_TOPLEVEL"`.
- Registered declaratively in [`plugin.xml`](../../../../resources/META-INF/plugin.xml) via `<defaultLiveTemplates file="liveTemplates/flutter_miscellaneous.xml"/>` and `<liveTemplateContext contextId="DART_TOPLEVEL" baseContextId="DART" implementation="io.flutter.template.DartToplevelTemplateContextType"/>`.
- Templates live in [`flutter_miscellaneous.xml`](../../../../resources/liveTemplates/flutter_miscellaneous.xml). Each template body is authored in a sibling `.txt` file (`stful.txt`, `stless.txt`, `stanim.txt`, `inh.txt`, `ihof.txt`, `mdof.txt`, `thof.txt`) and inlined into the XML by a regeneration step; see the [liveTemplates readme](../../../../resources/liveTemplates/readme.md).

## Invariants
- `DartToplevelTemplateContextType` considers an element to be in context if and only if it is not inside a `DartClassDefinition` or a `PsiComment`.
- `FlutterLiveTemplatesProvider` always provides `/liveTemplates/flutter_miscellaneous` as default templates.
- `FlutterLiveTemplatesProvider` always returns `null` for hidden templates.
- `DartToplevelTemplateContextType` considers an element to be in context if and only if it is inside a Dart file (`baseContextId="DART"`) and not inside a `DartClassDefinition` or a `PsiComment`.

## Side Effects
- None.
11 changes: 10 additions & 1 deletion src/io/flutter/template/DartToplevelTemplateContextType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
import com.jetbrains.lang.dart.psi.DartClassDefinition;
import org.jetbrains.annotations.NotNull;

/**
* Live template context for top-level Dart declarations outside of class bodies and comments.
*
* <p>Registered declaratively in {@code plugin.xml} with {@code contextId="DART_TOPLEVEL"} and
* {@code baseContextId="DART"}.
*/
public class DartToplevelTemplateContextType extends DartTemplateContextType {
/**
* Creates the {@code DART_TOPLEVEL} template context type with presentable name {@code "Top-level"}.
*/
public DartToplevelTemplateContextType() {
super("DART_TOPLEVEL", "Top-level", Generic.class);
super("Top-level");
}

@Override
Expand Down
23 changes: 0 additions & 23 deletions src/io/flutter/template/FlutterLiveTemplatesProvider.java

This file was deleted.

133 changes: 133 additions & 0 deletions testSrc/unit/io/flutter/template/FlutterLiveTemplatesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright 2026 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.template;

import com.intellij.codeInsight.template.TemplateActionContext;
import com.intellij.codeInsight.template.TemplateContextType;
import com.intellij.codeInsight.template.impl.TemplateContextTypes;
import com.intellij.codeInsight.template.impl.TemplateImpl;
import com.intellij.codeInsight.template.impl.TemplateSettings;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.jetbrains.lang.dart.DartLanguage;
import com.jetbrains.lang.dart.ide.template.DartTemplateContextType;
import io.flutter.testing.CodeInsightProjectFixture;
import io.flutter.testing.Testing;
import org.junit.Rule;
import org.junit.Test;

import java.util.List;
import java.util.Objects;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
* Unit tests for Flutter live template XML registrations and {@link DartToplevelTemplateContextType}.
*/
public class FlutterLiveTemplatesTest {

private static final String FLUTTER_GROUP = "Flutter";

@Rule
public final CodeInsightProjectFixture fixture = Testing.makeCodeInsightModule();

@Test
public void defaultLiveTemplatesAreLoadedFromDeclarativeRegistration() {
final TemplateSettings settings = TemplateSettings.getInstance();
assertNotNull(settings);

final DartToplevelTemplateContextType topLevelContext =
TemplateContextTypes.getByClass(DartToplevelTemplateContextType.class);
final DartTemplateContextType.Statement statementContext =
TemplateContextTypes.getByClass(DartTemplateContextType.Statement.class);

for (String key : List.of("stless", "stful", "inh", "stanim")) {
final TemplateImpl template = settings.getTemplate(key, FLUTTER_GROUP);
assertNotNull("Expected Flutter live template '" + key + "' to be registered", template);
assertTrue(
"Expected '" + key + "' to be enabled in DART_TOPLEVEL context",
template.getTemplateContext().isEnabled(topLevelContext)
);
assertFalse(
"Expected '" + key + "' not to be directly enabled in DART_STATEMENT context",
template.getTemplateContext().isEnabled(statementContext)
);
}

for (String key : List.of("thof", "ihof", "mdof")) {
final TemplateImpl template = settings.getTemplate(key, FLUTTER_GROUP);
assertNotNull("Expected Flutter live template '" + key + "' to be registered", template);
assertTrue(
"Expected '" + key + "' to be enabled in DART_STATEMENT context",
template.getTemplateContext().isEnabled(statementContext)
);
assertFalse(
"Expected '" + key + "' not to be directly enabled in DART_TOPLEVEL context",
template.getTemplateContext().isEnabled(topLevelContext)
);
}
}

@Test
public void dartToplevelContextRegistrationAndHierarchy() {
final DartToplevelTemplateContextType context =
TemplateContextTypes.getByClass(DartToplevelTemplateContextType.class);
assertNotNull(context);
assertEquals("DART_TOPLEVEL", context.getContextId());
assertEquals("Top-level", context.getPresentableName());

final TemplateContextType baseContext = context.getBaseContextType();
assertNotNull("Expected baseContextId=\"DART\" to resolve a parent context", baseContext);
assertEquals("DART", baseContext.getContextId());
assertTrue(baseContext instanceof DartTemplateContextType.Generic);
}

@Test
public void dartToplevelContextMatchesTopLevelAndRejectsClassBodyAndComments() throws Exception {
Testing.runOnDispatchThread(() -> {
final DartToplevelTemplateContextType context =
TemplateContextTypes.getByClass(DartToplevelTemplateContextType.class);
final PsiFileFactory factory =
PsiFileFactory.getInstance(Objects.requireNonNull(fixture.getProject()));

final String code =
"// header comment\n" +
"void topLevelAnchor() {}\n" +
"class MyWidget {\n" +
" void insideClassAnchor() {}\n" +
"}\n";
final PsiFile dartFile = factory.createFileFromText("main.dart", DartLanguage.INSTANCE, code);

final int commentOffset = code.indexOf("header comment");
final int topLevelOffset = code.indexOf("void topLevelAnchor");
final int classBodyOffset = code.indexOf("void insideClassAnchor");

assertFalse(
"Should not match inside a Dart comment",
context.isInContext(TemplateActionContext.expanding(dartFile, commentOffset))
);
assertTrue(
"Should match at Dart top-level",
context.isInContext(TemplateActionContext.expanding(dartFile, topLevelOffset))
);
assertFalse(
"Should not match inside a DartClassDefinition",
context.isInContext(TemplateActionContext.expanding(dartFile, classBodyOffset))
);

final PsiFile plainFile =
factory.createFileFromText("notes.txt", PlainTextLanguage.INSTANCE, "plain text");
assertFalse(
"Should not match outside Dart files",
context.isInContext(TemplateActionContext.expanding(plainFile, 0))
);
});
}
}
3 changes: 0 additions & 3 deletions tool/baseline/253/verifier-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ Deprecated API usages Deprecated constructor com.intellij.execution.configuratio
Deprecated API usages Deprecated constructor com.intellij.ui.LayeredIcon.<init>(javax.swing.Icon[] icons) is invoked in io.flutter.toolwindow.ToolWindowBadgeUpdater.lambda$updateBadgedIcon$0(ToolWindow) : void
Deprecated API usages Deprecated constructor com.intellij.ui.LayeredIcon.<init>(javax.swing.Icon[] icons) is invoked in io.flutter.toolwindow.ToolWindowBadgeUpdater.lambda$updateBadgedIcon$1(ToolWindow) : void
Deprecated API usages Deprecated constructor com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters.<init>() is invoked in io.flutter.run.SdkRunConfig.writeExternal(Element) : void
Deprecated API usages Deprecated constructor com.jetbrains.lang.dart.ide.template.DartTemplateContextType.<init>(java.lang.String id, java.lang.String presentableName, java.lang.Class baseContextType) is invoked in io.flutter.template.DartToplevelTemplateContextType.<init>()
Deprecated API usages Deprecated field com.intellij.util.system.OS.version : java.lang.String is accessed in io.flutter.utils.SystemUtils.getOsNameAndVersion() : String. This field will be removed in a future release
Deprecated API usages Deprecated interface com.intellij.codeInsight.template.impl.DefaultLiveTemplatesProvider is referenced in io.flutter.template.FlutterLiveTemplatesProvider
Deprecated API usages Deprecated method com.intellij.codeInsight.daemon.DaemonCodeAnalyzer.restart() : void is invoked in io.flutter.font.FontPreviewProcessor$2.onCancel() : void
Deprecated API usages Deprecated method com.intellij.codeInsight.daemon.DaemonCodeAnalyzer.restart() : void is invoked in io.flutter.font.FontPreviewProcessor$2.run(ProgressIndicator) : void
Deprecated API usages Deprecated method com.intellij.coverage.CoverageEngine.createCoverageSuite(com.intellij.coverage.CoverageRunner runner, java.lang.String name, com.intellij.coverage.CoverageFileProvider fileProvider, com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration config) : com.intellij.coverage.CoverageSuite is overridden in class io.flutter.run.coverage.FlutterCoverageEngine
Expand All @@ -31,7 +29,6 @@ Deprecated API usages Deprecated method com.intellij.openapi.vfs.VirtualFileMana
Deprecated API usages Deprecated method com.intellij.psi.search.FilenameIndex.getFilesByName(com.intellij.openapi.project.Project project, java.lang.String name, com.intellij.psi.search.GlobalSearchScope scope) : com.intellij.psi.PsiFile[] is invoked in io.flutter.run.FlutterPositionMapper.lambda$findRemoteSourceRoot$0(String) : PsiFile[]
Deprecated API usages Deprecated method com.intellij.util.ReflectionUtil.getDeclaredMethod(java.lang.Class aClass, java.lang.String name, java.lang.Class[] parameters) : java.lang.reflect.Method is invoked in io.flutter.android.AndroidEmulator.getLaunchInToolWindow() : boolean
Deprecated API usages Deprecated method com.intellij.util.lang.UrlClassLoader.addFiles(java.util.List files) : void is invoked in io.flutter.utils.FileUtils.loadPaths(ClassLoader, List) : void
Dynamic Plugin Status Declares non-dynamic extensions: `com.intellij.defaultLiveTemplatesProvider`
Internal API usages Internal class com.intellij.xdebugger.impl.XDebugSessionImpl is referenced in io.flutter.vmService.VmServiceWrapper.lambda$attachIsolate$5(XDebugSession) : void. This class is marked with @org.jetbrains.annotations.ApiStatus.Internal annotation or @com.intellij.openapi.util.IntellijInternalApi annotation and indicates that the class is not supposed to be used in client code.
Internal API usages Internal enum com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude is referenced in io.flutter.run.common.TestLineMarkerContributor$1.<clinit>() : void. This enum is marked with @org.jetbrains.annotations.ApiStatus.Internal annotation or @com.intellij.openapi.util.IntellijInternalApi annotation and indicates that the class is not supposed to be used in client code.
Internal API usages Internal enum com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude is referenced in io.flutter.run.common.TestLineMarkerContributor.getTestStateIcon(PsiElement, Icon) : Icon. This enum is marked with @org.jetbrains.annotations.ApiStatus.Internal annotation or @com.intellij.openapi.util.IntellijInternalApi annotation and indicates that the class is not supposed to be used in client code.
Expand Down
Loading
Loading