Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

[Bug] Using code_metrics for a plugin that has an example app causes the Dart analysis server not to pickup on metrics analysis #253

Closed
GroovinChip opened this issue Apr 7, 2021 · 29 comments
Assignees
Labels
type: bug Something isn't working
Milestone

Comments

@GroovinChip
Copy link

At work, I develop and maintain a Flutter plugin and I added code metrics to it yesterday. I configured it as I normally do. However, metrics analysis doesn't show up in Android Studio's analyzer tab, and when I view the diagnostics it shows errors because of the example. So I tried two things, and while they solved the error, neither results in the metrics being shown in the ide:

  1. Have the analyzer ignore the example
  2. Add code metrics to the example

Unfortunately, I cannot share any code or logs - GitHub is blocked on my work machine (I'm filing this on my phone) and the code is private.

I'd be very grateful for whatever insight you guys might have on this.

@GroovinChip GroovinChip added the type: question Further information is requested label Apr 7, 2021
@incendial
Copy link
Member

incendial commented Apr 7, 2021

@GroovinChip ah, here we go again! 😄

Have you tried open it in VS Code or it's not possible? And could you please do the same steps, that we went through here?

@incendial incendial assigned incendial and unassigned dkrutskikh Apr 7, 2021
@incendial
Copy link
Member

If VS Code will work fine, then I will start debugging from Android Studio right away.

@GroovinChip
Copy link
Author

GroovinChip commented Apr 7, 2021

@GroovinChip ah, here we go again! 😄

Have you tried open it in VS Code or it's not possible? And could you please do the same steps, that we went through here?

Here we go again indeed! 😅

I actually already made sure to exclude the iOS folder, and I made sure that my member ordering rule has the correct indentation. VS code is also not showing any metrics. I think it's because the plugin isn't running. The analysis server diagnostics say that it cannot resolve code metrics for the example app, and so it is not running, which prompted me to file this 😅 I didn't want to bother you guys again, which is why I tried a bunch of things on my own based on previous help you've provided, but no luck 😅

Edit: I'm using version 3.0.0-nullsafety.1 btw

@incendial
Copy link
Member

I didn't want to bother you guys again, which is why I tried a bunch of things on my own based on previous help you've provided, but no luck 😅

No problem, let's try to make it work!

Do I understand you correctly, that:

  1. It works fine for all other code except the example directory and everything inside?
  2. You have two pubspec and two analysis_options files (for the project and for the example) and they are both configured in the same way?

And I have some additional questions:

  1. What type of diagnostic errors you see in the example folder? Is it metrics or rules? Or both?
  2. Could you please try running CLI and check the output for correctness?
  3. If you remove the example, everything works as expected?

@GroovinChip
Copy link
Author

GroovinChip commented Apr 7, 2021

I didn't want to bother you guys again, which is why I tried a bunch of things on my own based on previous help you've provided, but no luck 😅

No problem, let's try to make it work!

Excellent, thank you!

Do I understand you correctly, that:

  1. It works fine for all other code except the example directory and everything inside?

No, it doesn't work at all, and the diagnostics say that it's because it cannot resolve the code metrics package at the example's path.

  1. You have two pubspec and two analysis_options files (for the project and for the example) and they are both configured in the same way?

This is indeed something I tried, and while it resolved the diagnostics error, metrics were still not appearing at all. So I rolled back to only using it in the plugin.

And I have some additional questions:

  1. What type of diagnostic errors you see in the example folder? Is it metrics or rules? Or both?

None

  1. Could you please try running CLI and check the output for correctness?

The cli has worked the whole time, but the dart analysis server in IDE's is not picking up code metrics analysis

  1. If you remove the example, everything works as expected?

As in, completely remove the example from the plugin project?

@incendial
Copy link
Member

incendial commented Apr 7, 2021

No, it doesn't work at all, and the diagnostics say that it's because it cannot resolve the code metrics package at the example's path.

Hmm, that's look very interesting then...

This is indeed something I tried, and while it resolved the diagnostics error, metrics were still not appearing at all. So I rolled back to only using it in the plugin.

So, now you have two pubspecs and the root one is depending on a dart_code_metrics, right?

Great, that cli works, it means that files are parsed correctly and it's not an issue with the analyzer file resolving. Could you please double check that you passed the plugins config to the analysis_options? I mean

analyzer:
  plugins:
    - dart_code_metrics

As in, completely remove the example from the plugin project?

Yeah, I'm very curious, will that help or not.

@GroovinChip
Copy link
Author

GroovinChip commented Apr 7, 2021

No, it doesn't work at all, and the diagnostics say that it's because it cannot resolve the code metrics package at the example's path.

Hmm, that's look very interesting then...

This is indeed something I tried, and while it resolved the diagnostics error, metrics were still not appearing at all. So I rolled back to only using it in the plugin.

So, now you have two pubspecs and the root one is depending on a dart_code_metrics, right?

Yes, two pubspecs - the plugin pubspec and the example app pubspec, and code metrics is a dev dependency in the plugin pubspec.

Great, that cli works, it means that files are parsed correctly and it's not an issue with the analyzer file resolving. Could you please double check that you passed the plugins config to the analysis_options? I mean

analyzer:

  plugins:

    - dart_code_metrics

Yes, the plugin analysis_options.yaml is configured this way., although without empty lines in between analyzer, plugins, and dart_code_metrics

As in, completely remove the example from the plugin project?

Yeah, I'm very curious, will that help or not.

I'll try this and report back.

@GroovinChip
Copy link
Author

Update: deleting the example resolves the error shown previously in the analysis server diagnostics, but metrics are still to appearing in the ide after a restart.

@GroovinChip
Copy link
Author

GroovinChip commented Apr 7, 2021

Update: after invalidating caches and restarting, the analysis server diagnostics say code metrics is not running for an unknown reason. I've restored the example after this. Oddly, now the analysis server shows the code metrics associated with the plugin and example contexts, with no metrics appearing the ide. But I have not yet restarted the ide or the analysis server. Doing so now.

Edit: restarting the analysis server brings the error back

@GroovinChip
Copy link
Author

Here's a picture of the log. I'd paste it, but again, GitHub is blocked (don't ask lol)

image

@GroovinChip
Copy link
Author

And here's what shows above the log
image

@incendial
Copy link
Member

Hm, I think I need some time to think about this...

If you will be able to create an example where the issue can be reproduced - it will be very very helpful.

@GroovinChip
Copy link
Author

I'll see if I can recreate this on my personal computer. Should I update this to be a bug issue? I filed it as a question because I wasn't sure if it was user error or not.

@incendial
Copy link
Member

incendial commented Apr 7, 2021

Yeah, looks like a bug to me... Is it a full stacktrace or there is more? If there is more, can u share a full log?

Edit: and I don't think that this is a problem with a package having an example.

@GroovinChip
Copy link
Author

OK, I'll update the issue. Hm, I thought I had captured the full log but there are actually about 20 more lines. Stand by for the rest.

@GroovinChip GroovinChip changed the title [Question] What's the recommended configuration for using this in a package that has an example? [Bug] Using code_metrics for a plugin that has an example app causes the Dart analysis server not to pickup on metrics analysis Apr 7, 2021
@incendial incendial added type: bug Something isn't working and removed type: question Further information is requested labels Apr 7, 2021
@incendial incendial modified the milestones: 3.1.0, 3.0.0 Apr 7, 2021
@GroovinChip
Copy link
Author

Rest of the log
image

@incendial
Copy link
Member

Thanks!

@GroovinChip
Copy link
Author

Issue reproduced here: https://github.com/GroovinChip/code_metrics_repro1

Logs are in the readme

Oddly, the creation of this project has resulted in #220 reappearing in that same project O_O

@GroovinChip
Copy link
Author

@incendial Restarting the analyzer seems to resolve #220 again for that project

@incendial
Copy link
Member

@GroovinChip some updates from my side - 2.4.1 version works as expected, although there is also this error with Could not resolve ..., so, it seems like it's not the main reason.

And if I try to update the version to null safety, then plugin seems to work fine, but no issues in IDE.

@GroovinChip
Copy link
Author

@GroovinChip some updates from my side - 2.4.1 version works as expected, although there is also this error with Could not resolve ..., so, it seems like it's not the main reason.

And if I try to update the version to null safety, then plugin seems to work fine, but no issues in IDE.

Strange. I did try and downgrade to 2.4.1 (not in the repro) but couldn't due to dependency conflicts, so I can't say if that would work for me or not, but since you still got the error anyway it probably wouldn't work.

@incendial
Copy link
Member

incendial commented Apr 8, 2021

@GroovinChip we finally found the problem, actually two problems 😄 . First one is connected with our migration - analysis options file was not located correctly which resulted in that strange behaviour where the plugin was working correctly, but no files were processed. Second one is about analyzer_plugin package null safety migration, there is a problem with types and I will create an issue.

Edit: the link to the discussion about analyzer_plugin issue. Link to our side fix: #255

@incendial
Copy link
Member

Hope, we will be able to fix it soon.

@incendial incendial mentioned this issue Apr 8, 2021
16 tasks
@GroovinChip
Copy link
Author

@incendial using #255 results in the following diagnostics:

dart-code-metrics-b393cdd27291d8608228f4ab6f9dc9c10750c2e8
bootstrap package path: /Users/groov/development/flutter/.pub-cache/git/dart-code-metrics-b393cdd27291d8608228f4ab6f9dc9c10750c2e8/tools/analyzer_plugin

execution path: /Users/groov/.dartServer/.plugin_manager/578765861728f8b5bd34260a45ad274a/analyzer_plugin/bin/plugin.dart

packages file path: /Users/groov/.dartServer/.plugin_manager/578765861728f8b5bd34260a45ad274a/analyzer_plugin/.packages

not running

type '_InternalLinkedHashMap' is not a subtype of type 'Map?' in type cast
#0      new Request.fromJson (package:analyzer_plugin/protocol/protocol.dart:126:41)
#1      PluginIsolateChannel.listen.onData (package:analyzer_plugin/src/channel/isolate_channel.dart:97:29)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1546:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#4      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#5      _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#6      _StreamController._add (dart:async/stream_controller.dart:607:7)
#7      _StreamController.add (dart:async/stream_controller.dart:554:5)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

dart_code_metrics
bootstrap package path: dart_code_metrics/tools/analyzer_plugin

execution path: null

packages file path: null

not running

Could not resolve "package:dart_code_metrics/dart_code_metrics.dart" in /Users/groov/development/flutter_projects/packages_and_plugins/macos_ui/example.
#0      PluginManager.recordPluginFailure (package:analysis_server/src/plugin/plugin_manager.dart:469:7)
#1      PluginWatcher.addedDriver (package:analysis_server/src/plugin/plugin_watcher.dart:51:17)
#2      AnalysisDriverScheduler.add (package:analyzer/src/dart/analysis/driver.dart:1913:22)
#3      new AnalysisDriver (package:analyzer/src/dart/analysis/driver.dart:293:16)
#4      ContextBuilder.buildDriver (package:analyzer/src/context/builder.dart:122:29)
#5      ServerContextManagerCallbacks.addAnalysisDriver (package:analysis_server/src/analysis_server.dart:647:34)
#6      ContextManagerImpl._createContext (package:analysis_server/src/context_manager.dart:1037:37)
#7      ContextManagerImpl._createContexts (package:analysis_server/src/context_manager.dart:1103:16)
#8      ContextManagerImpl._createContexts (package:analysis_server/src/context_manager.dart:1111:13)
#9      ContextManagerImpl.setRoots (package:analysis_server/src/context_manager.dart:629:9)
#10     AnalysisServer.setAnalysisRoots (package:analysis_server/src/analysis_server.dart:396:22)
#11     AnalysisDomainHandler.setAnalysisRoots (package:analysis_server/src/domain_analysis.dart:346:14)
#12     AnalysisDomainHandler.handleRequest (package:analysis_server/src/domain_analysis.dart:285:16)
#13     AnalysisServer.handleRequest. (package:analysis_server/src/analysis_server.dart:237:38)
#14     _rootRun (dart:async/zone.dart:1354:13)
#15     _CustomZone.run (dart:async/zone.dart:1258:19)
#16     _runZoned (dart:async/zone.dart:1788:10)
#17     runZonedGuarded (dart:async/zone.dart:1776:12)
#18     AnalysisServer.handleRequest (package:analysis_server/src/analysis_server.dart:233:5)
#19     ByteStreamServerChannel._readRequest (package:analysis_server/src/channel/byte_stream_channel.dart:163:14)
#20     ByteStreamServerChannel.listen. (package:analysis_server/src/channel/byte_stream_channel.dart:103:26)
#21     _rootRunUnary (dart:async/zone.dart:1362:47)
#22     _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#24     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#25     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#26     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
#27     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#28     _StringAdapterSink.add (dart:convert/string_conversion.dart:238:11)
#29     _LineSplitterSink._addLines (dart:convert/line_splitter.dart:155:13)
#30     _LineSplitterSink.addSlice (dart:convert/line_splitter.dart:130:5)
#31     StringConversionSinkMixin.add (dart:convert/string_conversion.dart:163:5)
#32     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#33     _rootRunUnary (dart:async/zone.dart:1362:47)
#34     _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#35     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#36     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#37     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#38     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
#39     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
#40     _StringAdapterSink.add (dart:convert/string_conversion.dart:238:11)
#41     _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:243:7)
#42     _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:317:20)
#43     _Utf8ConversionSink.add (dart:convert/string_conversion.dart:310:5)
#44     _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
#45     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#46     _rootRunUnary (dart:async/zone.dart:1362:47)
#47     _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#48     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#49     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#50     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#51     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#52     _StreamController._add (dart:async/stream_controller.dart:607:7)
#53     _StreamController.add (dart:async/stream_controller.dart:554:5)
#54     _Socket._onData (dart:io-patch/socket_patch.dart:2144:41)
#55     _rootRunUnary (dart:async/zone.dart:1370:13)
#56     _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#57     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#58     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#59     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
#60     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
#61     _StreamController._add (dart:async/stream_controller.dart:607:7)
#62     _StreamController.add (dart:async/stream_controller.dart:554:5)
#63     new _RawSocket. (dart:io-patch/socket_patch.dart:1680:33)
#64     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1192:14)
#65     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#66     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#67     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:120:13)
#68     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)

@incendial
Copy link
Member

incendial commented Apr 9, 2021

@GroovinChip yeah, that is actually the second problem I was talking about. Should be resolved after updating dependency constraints here #259

@dkrutskikh
Copy link
Member

@GroovinChip try to use 3.0.0-nullsafety.2 version

@incendial
Copy link
Member

The error with Could not resolve will still remain, but all issues should be now visible in IDE.

@GroovinChip
Copy link
Author

@dkrutskikh This seems to do the trick for now, thanks. Fingers crossed it stays that way!

@incendial
Copy link
Member

incendial commented Apr 10, 2021

Seems like we resolved the main problem with the plugin bootstrapping and the problem with Could not resolve... for a sub package is discussed here and have a decent work-around, so I'm closing this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants