Skip to content

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

Closed

Description

@alexmarkley

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. :)

Activity

  1. DanTup commented on Feb 5, 2021

    @DanTup
    Member

    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).

  2. added
    awaiting infoRequires more information from the customer to progress
    on Feb 5, 2021
  3. alexmarkley commented on Feb 8, 2021

    @alexmarkley
    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.

  4. DanTup commented on Feb 9, 2021

    @DanTup
    Member

    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!

  5. alexmarkley commented on Feb 10, 2021

    @alexmarkley
    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

  6. DanTup commented on Feb 10, 2021

    @DanTup
    Member

    /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.

  7. alexmarkley commented on Feb 10, 2021

    @alexmarkley
    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.)

  8. DanTup commented on Feb 11, 2021

    @DanTup
    Member

    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.

  9. 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[/+] on Feb 11, 2021
  10. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    and removed
    awaiting infoRequires more information from the customer to progress
    on Feb 11, 2021
  11. added this to the On Deck milestone on Feb 11, 2021
  12. modified the milestones: On Deck, v3.25.0 on Jun 28, 2021
  13. DanTup commented on Jul 21, 2021

    @DanTup
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions