Skip to content

Improve textmate grammar for primary constructors #5920

@DanTup

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

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