Skip to content

dart.lineLength setting only works at the workspace level when using LSP #3124

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

Closed
alexmarkley opened this issue Feb 5, 2021 · 8 comments
Closed
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Milestone

Comments

@alexmarkley
Copy link

alexmarkley commented Feb 5, 2021

Updated today and noticed this (apparent) regression. I have dart.lineLength set in my project's settings.json file, but Format Document appears to be ignoring this, forcing lines to 80 columns.

Edit: Please let me know what other information I can provide as far as troubleshooting goes. :)

@DanTup
Copy link
Member

DanTup commented Feb 5, 2021

Can you confirm the version of Flutter you're using? My guess is that after upgrading, you accepted the prompt to enable the LSP protocol, so it's a result of that rather than the version. lineLength should be supported in LSP since dart-lang/sdk@ba459f9 though (which I believe should be in the current Flutter stable).

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Feb 5, 2021
@alexmarkley
Copy link
Author

Result of flutter doctor -v:

[✓] Flutter (Channel stable, 1.22.6, on macOS 11.1 20C69 darwin-x64, locale en-US)
    • Flutter version 1.22.6 at /Users/alex/Development/Flutter/flutter
    • Framework revision 9b2d32b605 (2 weeks ago), 2021-01-22 14:36:39 -0800
    • Engine revision 2f0af37152
    • Dart version 2.10.5


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/alex/Library/Android/sdk
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/alex/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.8.4

[!] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.53.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.19.0

[✓] Connected device (1 available)
    • Alex's iPhone (mobile) • 00f777378e33cc1c0fd0af01b429e8b0fe04ba87 • ios • iOS 14.4

! Doctor found issues in 1 category.

Also you are correct, I did opt in to the LSP protocol. Setting "dart.previewLsp": false solves the problem for me.

@DanTup
Copy link
Member

DanTup commented Feb 9, 2021

I switched to Flutter stable (1.22.6) and tested this, but it seems to be honouring the dart.lineLength setting for me. I set it to 200 and reformatted a file, and it unwrapped many lines. Setting it to 80 and formatted then caused it to re-wrap them.

LSP is going to become the default in the future, so I'd like to track down why it's not working for some - could you try the following for me to get a log?

  • Re-enable LSP and reload VS Code
  • Ensure you can repro in a new project created with Flutter: New Application Project and use that for logging (the log will include parts of the open source files)
  • Create a new file with just the simple contents below (this will wrap at 80 chars and unwrap at 800 chars)
  • Run the Dart: Capture Analysis Server Logs command in VS Code
  • Set dart.lineLength to 80 and format the document
  • Change the dart.lineLength setting to 800, save the settings, then re-format the document
  • Click Cancel on the logging notification to stop logging and open the log, then attach it here
var a = [
  123456789,
  123456789,
  123456789,
  123456789,
  123456789,
  123456789,
  123456789,
  123456789,
  123456789,
  123456789,
  123456789
];

Thanks!

@alexmarkley
Copy link
Author

@DanTup You're right, strictly following your steps to reproduce I am unable to reproduce the problem.

My normal workflow includes creating workspaces with multiple folders in them. So after "Create a new file with just the simple contents below" but before "Run the Dart: Capture Analysis Server Logs command in VS Code" I clicked File > Add Folder to Workspace... and selected another folder to add.

At that point I am able to reproduce the problem. Here's the requested log:

Dart-Code-Log-2021-01-02 21-14-09.txt

@DanTup
Copy link
Member

DanTup commented Feb 10, 2021

/in the attached log, the settings include:

"lineLength":80,

Where are you changing the dart.lineLength setting? If you're setting it in a single folder (eg. in the .vscode/settings.json file), that will only apply when you specifically open that folder. If you open a "workspace" (multiple folders at once) then it needs to either be set in your VS Code settings, or the .code-workspace settings.

@alexmarkley
Copy link
Author

In my current workflow the setting is set at the folder .vscode/settings.json level, and it seems to be working as desired as long as I keep previewLSP: false.

It's weird that you'd be showing lineLength: 80 in the logs I attached, because as far as I can tell I only have it set in the one place.

It also doesn't make sense to me to require the setting to be set at the workspace level, because a workspace exists at a higher level than the project's Git repository, and developers may be working on a different combination of repositories at any given time. (Hence it would not make sense to commit the workspace anywhere.)

@DanTup
Copy link
Member

DanTup commented Feb 11, 2021

In my current workflow the setting is set at the folder .vscode/settings.json level, and it seems to be working as desired as long as I keep previewLSP: false.

Ah, I think I understand. In the non-LSP version I think we support this as a "resource setting" which means it can be scoped per workspace folder (so if your workspace if you had two projects, they could each have their own setting). There are actually many settings flagged as resource that do not make much sense as such (for example the analyzer log file, which can only exist one per workspace).

The LSP server only supports workspace config, which means it'll only work set at the workspace level or the user settings level.

@DanTup DanTup changed the title Dart-Code 3.19.1 is ignoring dart.lineLength during Format Document dart.lineLength setting only works at the workspace level when using LSP Feb 11, 2021
@DanTup DanTup added in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug and removed awaiting info Requires more information from the customer to progress labels Feb 11, 2021
@DanTup DanTup added this to the On Deck milestone Feb 11, 2021
@DanTup DanTup modified the milestones: On Deck, v3.25.0 Jun 28, 2021
dart-bot pushed a commit to dart-lang/sdk that referenced this issue Jul 21, 2021
Fixes Dart-Code/Dart-Code#3124.

Change-Id: I724395550ffca14c4cedae46519d568fd0680e02
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/207663
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@DanTup
Copy link
Member

DanTup commented Jul 21, 2021

dart-lang/sdk@c881935 has landed in the SDK, and lineLength and enableSdkFormatter are now supported at the WorkspaceFolder level instead of only globally/window level.

Since the change is in the SDK, it will require an SDK update (so may take a little longer to show up than things that only need changes in the VS Code extension).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Projects
None yet
Development

No branches or pull requests

2 participants