Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart: allow quick fixes with multiple edits. and support .arb translation files. #871

Closed

Conversation

hpoul
Copy link

@hpoul hpoul commented Jun 24, 2022

When a analysis warning is produced with multiple fixes they were correctly displayed in the "Dart Analysis" tool window. But in the quick fix drop down only fixsets with a single fix were displayed.
This changes this behavior to allow multiple fixes. And it seems to work for me.

In addition i've added .arb files to the list of analysis files.

@alexander-doroshko alexander-doroshko self-assigned this Aug 17, 2022
@alexander-doroshko
Copy link
Member

@hpoul I'm very sorry about the delay with your PR.
Can you give an example of a quick fix that has multiple SourceFileEdits?

Are arb files supported by the Dart Analysis Server? I haven't found it in the Dart SDK source code so far.

@hpoul
Copy link
Author

hpoul commented Aug 22, 2022

@alexander-doroshko well.. the dart analysis server supports plugins.. and I've written one to show quick fixes for externalizing strings.. which requires multiple sourceedits to

  1. Create an entry in the .arb fine
  2. Change the .dart file to reference the name used in the arb file

See also dart-lang/sdk#46722 (comment)

@alexander-doroshko
Copy link
Member

@hpoul Thanks. Allowing multiple source changes looks reasonable to me.

Is there a real need in adding .arb to the list of analyzed files?

@hpoul
Copy link
Author

hpoul commented Aug 23, 2022

@alexander-doroshko iirc the main reason for my change was that the assist list checks whether the assist intention is part of an analysable file, and only shows it when that's the case:

if (!(file instanceof DartFile) || !DartAnalysisServerService.isLocalAnalyzableFile(file.getVirtualFile())) {

public static boolean isLocalAnalyzableFile(@Nullable final VirtualFile file) {
if (file != null && file.isInLocalFileSystem()) {
return isFileNameRespectedByAnalysisServer(file.getName());
}
return false;
}
public static boolean isFileNameRespectedByAnalysisServer(@NotNull String _fileName) {
// see https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/generated/engine.dart (class AnalysisEngine)
// and AbstractAnalysisServer.analyzableFilePatterns
@NonNls String fileName = _fileName.toLowerCase(Locale.US);
return fileName.endsWith(".dart") ||
fileName.endsWith(".htm") ||
fileName.endsWith(".html") ||
fileName.equals(".analysis_options") ||
fileName.equals("analysis_options.yaml") ||
fileName.equals("pubspec.yaml") ||
fileName.equals("fix_data.yaml") ||
fileName.equals("androidmanifest.xml");
}

so I added the arb file. But since arb files are now part of dart/flutter projects i guess it would make sense that they will also be analysed one day 🤔

@alexander-doroshko
Copy link
Member

I've merged the multi-SourceFileEdits part of the PR.

assist list checks whether the assist intention is part of an analysable file, and only shows it when that's the case:

As I understand, only the file in the editor is checked using isLocalAnalyzableFile(). So it should work if your quick fix is registered for a .dart file, even if it includes changes in .arb file as well.

intellij-monorepo-bot pushed a commit that referenced this pull request Dec 22, 2022
close #871

(cherry picked from commit 13152cf65c4e95a5e3cbf257f29b7618a8c3c7d7)

GitOrigin-RevId: fa410db5e899855c4c48250f8a2496d0e394ed7d
intellij-monorepo-bot pushed a commit that referenced this pull request Dec 23, 2022
close #871

(cherry picked from commit 13152cf65c4e95a5e3cbf257f29b7618a8c3c7d7)

GitOrigin-RevId: afe87787781f25b941f1b13d24c584d2a5381d2b
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.

2 participants