Skip to content

Improve textmate grammar for primary constructors #5920

Closed
dart-lang/dart-syntax-highlight
#87

Description

@DanTup

We may as well do this at the same time as #5918. Primary Constructors mean that new and factory show up in more places in different contexts. We should try to get the grammar to match the semantic tokens as closely as possible. Currently they are very different.

Image
class NewWithoutType {
  const new();
  const new named();
}

class NewWithType {
  const NewWithType.named();
  const NewWithType.new();
}

class FactoryWithoutType {
  FactoryWithoutType._();
  factory() => FactoryWithoutType._();
  factory named() => FactoryWithoutType._();

  void factory() => ''; // Method
}

class FactoryWithType {
  FactoryWithType._();
  factory() => FactoryWithType._();
  factory named() => FactoryWithType._();

  void factory() => ''; // Method
}

class PrimaryWithoutName(final int a) {
  this {}
}

class PrimaryWithName.named(final int a) {
  this {}
}

void f() {
  var _ = NewWithType.new();
  var _ = NewWithType.named();
  var _ = new NewWithType.new();
  var _ = new NewWithType.named();
  var _ = const NewWithType.new();
  var _ = const NewWithType.named();
  var _ = NewWithType.new;
  var _ = NewWithType.named;
  var _ = FactoryWithType.named().factory();
}

D:\Dev\Test Projects\primary_constructors\lib\colors\semantic_tokens.dart

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Feb 23, 2026
  2. added this to the v3.130.0 milestone on Feb 23, 2026
  3. added
    in editorRelates to code editing or language features
    on Feb 23, 2026
  4. added a commit that references this issue on Feb 24, 2026
    b2e04fb
  5. added a commit that references this issue on Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions