Skip to content

Overflowing string literal earlier in expression forces worse formatting #1802

@jakemac53

Description

@jakemac53

What input code did you provide to the formatter?

See the categories setter call at the bottom here.

base mixin DartAnalyzerSupport
    on ToolsSupport, LoggingSupport, RootsTrackingSupport, FileSystemSupport
    implements SdkSupport, ProcessManagerSupport {
  @visibleForTesting
  static final resolveWorkspaceSymbolTool = Tool(
    name: 'resolve_workspace_symbol',
    description:
        'Look up a symbol or symbols in all workspaces by name. Can be used '
        'to validate that a symbol exists or discover small spelling '
        'mistakes, since the search is fuzzy.',
    inputSchema: Schema.object(
      properties: {
        ParameterNames.query: Schema.string(
          description:
              'Queries are matched based on a case-insensitive partial name '
              'match, and do not support complex pattern matching, regexes, '
              'or scoped lookups.',
        ),
      },
      description:
          'Returns all close matches to the query, with their names '
          'and locations. Be sure to check the name of the responses to ensure '
          'it looks like the thing you were searching for.',
      required: [ParameterNames.query],
      additionalProperties: false,
    ),
    annotations: ToolAnnotations(title: 'Project search', readOnlyHint: true),
  )..categories = [FeatureCategory.dart, FeatureCategory.flutter, FeatureCategory.lsp];
}

What output did the formatter produce?

It won't change it (note that if you force a trailing comma for the categories setter it will reformat it to remove the trailing comma).

What output did you expect or want the formatter to produce?

I expected it to use trailing commas for the list passed to the categories setter to keep lines under 80 chars.

base mixin DartAnalyzerSupport
    on ToolsSupport, LoggingSupport, RootsTrackingSupport, FileSystemSupport
    implements SdkSupport, ProcessManagerSupport {
  @visibleForTesting
  static final resolveWorkspaceSymbolTool = Tool(
    name: 'resolve_workspace_symbol',
    description:
        'Look up a symbol or symbols in all workspaces by name. Can be used '
        'to validate that a symbol exists or discover small spelling '
        'mistakes, since the search is fuzzy.',
    inputSchema: Schema.object(
      properties: {
        ParameterNames.query: Schema.string(
          description:
              'Queries are matched based on a case-insensitive partial name '
              'match, and do not support complex pattern matching, regexes, '
              'or scoped lookups.',
        ),
      },
      description:
          'Returns all close matches to the query, with their names '
          'and locations. Be sure to check the name of the responses to ensure '
          'it looks like the thing you were searching for.',
      required: [ParameterNames.query],
      additionalProperties: false,
    ),
    annotations: ToolAnnotations(title: 'Project search', readOnlyHint: true),
  )..categories = [
    FeatureCategory.dart,
    FeatureCategory.flutter,
    FeatureCategory.lsp,
  ];
}

Anything else we should know?

This appears to be related to the string literals, if I shorten them, then it will reformat the list to use trailing commas, but it also indents the entire constructor call.

This would then cause the string literals to be >80 chars, which can't be fixed without manually editing them.

I would still prefer it do that though because that is something I can fix, and it isn't obvious otherwise that this is the actual cause, it just seems like a formatter bug.

Metadata

Metadata

Assignees

Labels

styleRequest to change the formatter's output style

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions