It seems that when the dart_analysis_server is started with the onlyAnalyzeProjectsWithOpenFiles as false the server keeps sending a lot of repeated publishDiagnostics notifications to the client for the same file even without moving the cursor.
This doesn't happen when initializing the server with onlyAnalyzeProjectsWithOpenFiles as true.
Tested on flutter channel stable, dart 2.9.0 and flutter dev channel, Dart 2.9.0 (build 2.9.0-21.0.dev 7e72c9ae7e) using lsp-dart.
@DanTup I could not reproduce with vscode using previewLsp and setting onlyAnalyzeProjectsWithOpenFiles to false for some reason...
@ericdallo are you able to capture a log (using --instrumentation-log-file=/foo/bar.txt) of this happening?
I tested it with the capture log but without this instrumentation-log-file settings and I didn't see the server publish a lot of diagnostics like testing with lsp-dart
@ericdallo sorry, I meant - are you able to add the --instrumentation-log-file= option when using lsp-dart to capture a log? It might help understand why the diagnostics are being sent repeatedly.
Thanks!
@DanTup, I recorded a file with onlyAnalyzeProjectsWithOpenFiles as true and another with false:
onlyAnalyzeProjectsWithOpenFiles: true
lsp-dart-ok.zip
onlyAnalyzeProjectsWithOpenFiles: false
lsp-dart-bug.zip
I recorded only 6-7 seconds with the bug one as the server publish a lot of diagnostics and the file would be huge, but I think you can get the point.
Hope it helps!
Hmm, it looks like the server might not be caching the results for that file - which means when requests for things like codeActions are coming through, the file is being re-opened and parsed (which will trigger sending diagnostics).
We had this in VS Code when we sent priority files before setting analysis roots (https://github.com/Dart-Code/Dart-Code/issues/2438) but I don't think anything similar should be possible here.
How simple would it be for me to set this up and reproduce it here? (I have easy access to macOS and Windows, though can also run Linux in Docker fairly easily). I've never used emacs though 馃檭
@DanTup really odd, I think you can download emacs 27(latest), and use this for basic lsp-mode/lsp-dart setup, then open a dart/flutter project and lsp-dart should connect it
Also for reproducing the bug, add this to your init.el:
(setq lsp-dart-only-analyze-projects-with-open-files nil)
Feel free to ask anything or for a fast chat, ask on our gitter, and thank you very much for trying to help with that :)
You can also follow this if helps: https://emacs-lsp.github.io/lsp-mode/page/installation/
@ericdallo I think I've managed to get it set up, as I see yellow(!) text for quick fixes near where I have bad code:

However, it's not clear where the diagnostics are supposed to show up, or how I can enable logging of the LSP server (or pass the --instrumentation-log-file switch so the server will log).
Also - can you confirm how I should set a custom server path? I tried:
(setq lsp-dart-server-command "/Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/bin/server.dart")
;; and
(setq lsp-dart-server-command "/Users/danny/Dev/Dart SDKs/nightly-2020-08-24/bin/dart /Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/bin/server.dart")
I get:
Command "/Users/blah" is not present on the path.
(setq lsp-dart-server-command "/Users/danny/Dev/Dart SDKs/nightly-2020-08-24/bin/dart /Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/bin/server.dart")
Should be:
(setq lsp-dart-server-command '("/Users/danny/Dev/Dart SDKs/nightly-2020-08-24/bin/dart" "/Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/bin/server.dart"))
@yyoncho aha! Thanks! I needed "--lsp" on the end too, but seems to be working now 馃檪
I've managed to run this from source with a log, and I think I have an idea of the issue - though I'm struggling to repro. I think the issue might be that I'm not sending documentSymbol requests (which the broken log file above was). I guess I need to "enable" https://emacs-lsp.github.io/lsp-mode/page/main-features/#breadcrumb-on-headerline but it's not entirely clear how to. setq lsp-headerline-breadcrumb-enable t
@ericdallo ok, I'm mostly there.. however, despite having (setq lsp-dart-only-analyze-projects-with-open-files nil) in my ~/.emacs file, I'm still seeing "initializationOptions"::{"onlyAnalyzeProjectsWithOpenFiles"::true in the instrumentation file. The other settings there are working (for example the command to run the server from source). Any ideas?
@DanTup, you can check the current variable value on emacs with M-x describe-variable, also if you change a variable after the server has started, you need to lsp-workspace-restart to restart the server.
Try to move the setqs to a :init block on lsp-dart's use-package, like here.
Let me know if that doesn't fix the issue
@ericdallo I was restarting emacs after changing. I ran describe-variable but it says it's nil:

Try to move the setqs to a :init block on lsp-dart's use-package
That seems to have done it, thanks!
This seems to be the same issue as https://github.com/Dart-Code/Dart-Code/issues/2438, however my fix (https://dart-review.googlesource.com/c/sdk/+/147183/) was only applied to the original (non-LSP) server.
I've applied the same fix to LSP here:
https://dart-review.googlesource.com/c/sdk/+/160225/
The issue is that when running with the setting above, we use the client-provided folder as analysis roots (not the open files), but applying them may be delayed while we send requests to the client to get configuration. Opening a file before the analysis roots were set would result in the file not being marked as priority, and therefore not being cached.
There was another way to fix this, which was to always set analysis roots prior to asking the client for config. That would work today, but if we add configuration in future that affects analysis, it would mean we'd start initial analysis without those settings.
Thank you very much @DanTup for putting effort in figuring out that!
This LSP fix is already on master?
This LSP fix is already on master?
Sorry, not yet - I've just opened a review for it. The blue badge in the top left corner that says "Active" will be green and say "Merged" once it's merged into master - though it'll be the next day before it's available in a nightly Dart SDK.
If you're eager to test it, you could clone https://github.com/DanTup/sdk/tree/seed-lsp-drivers-priority and run the server from source. You'd probably want to use the latest nightly build for the SDK (you'll get weird issues if the VM running the server from source is too far out-of-sync with the server source) and then just set the path to the server like:
(setq lsp-dart-sdk-dir "/Users/danny/Dev/Dart SDKs/nightly-2020-08-24")
(setq lsp-dart-server-command '("/Users/danny/Dev/Dart SDKs/nightly-2020-08-24/bin/dart" "/Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/bin/server.dart" "--lsp"))
I see, no worries, Is there any way to subscribe for that status change? or could you let me know when the fix is on the latest dart SDK version?
Thank you! I'll test it later :)
@ericdallo it should be in the nightly that was built around an hour ago:
http://gsdview.appspot.com/dart-archive/channels/be/raw/latest/sdk/
Let me know if you still see issues with it. Thanks!