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

Can't get Biome to organize imports on save #15464

Closed
1 task done
micthiesen opened this issue Jul 30, 2024 · 10 comments
Closed
1 task done

Can't get Biome to organize imports on save #15464

micthiesen opened this issue Jul 30, 2024 · 10 comments
Labels
bug [core label] language server An umbrella label for all language servers typescript TypeScript programming language support

Comments

@micthiesen
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I have the Biome extension installed and have these settings:

  "languages": {
    "TypeScript": {
      "language_servers": [
        "!typescript-language-server",
        "!eslint",
        "vtsls",
        "biome"
      ],
      "preferred_line_length": 88,
      "wrap_guides": [88],
      "format_on_save": "on",
      "formatter": {
        "language_server": {
          "name": "biome"
        }
      },
      "code_actions_on_format": {
        "source.fixAll.biome": true,
        "source.organizeImports.biome": true
      }
    }
  }

When saving, the TS file is formatted but the imports are not sorted. I believe the LSP is set up correctly since I can manually trigger the code action:
image

Environment

Zed: v0.146.1 (Zed Preview)
OS: macOS 14.5.0
Memory: 32 GiB
Architecture: aarch64

I've also tried in:
Zed: v0.145.1 (Zed)
OS: macOS 14.5.0
Memory: 32 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log
2024-07-30T06:04:27.553078Z [INFO] fetching latest version of language server "vtsls"
2024-07-30T06:04:27.553136Z [INFO] Node runtime install_if_needed
2024-07-30T06:04:27.554275Z [INFO] starting language server. binary path: "/Users/michael/Code/client-app/node_modules/@biomejs/biome/bin/biome", working directory: "/Users/michael/Code/client-app", args: ["lsp-proxy"]
2024-07-30T06:04:27.640916Z [WARN] unhandled capability unregistration: Unregistration { id: "biome_did_change_extension_settings", method: "workspace/didChangeConfiguration" }
2024-07-30T06:04:27.640983Z [WARN] unhandled capability unregistration: Unregistration { id: "biome_rename", method: "textDocument/rename" }
2024-07-30T06:04:27.641037Z [WARN] language server 2: failed to unregister workspace/DidChangeWatchedFiles capability with id biome_did_change_workspace_settings. not registered.
2024-07-30T06:04:27.64119Z [WARN] unhandled capability unregistration: Unregistration { id: "biome_did_change_extension_settings", method: "workspace/didChangeConfiguration" }
2024-07-30T06:04:27.641254Z [WARN] unhandled capability unregistration: Unregistration { id: "biome_rename", method: "textDocument/rename" }
2024-07-30T06:04:27.64131Z [WARN] language server 2: failed to unregister workspace/DidChangeWatchedFiles capability with id biome_did_change_workspace_settings. not registered.
2024-07-30T06:04:27.641416Z [WARN] unhandled capability registration: Registration { id: "biome_did_change_extension_settings", method: "workspace/didChangeConfiguration", register_options: None }
2024-07-30T06:04:27.64161Z [WARN] unhandled capability registration: Registration { id: "biome_did_change_extension_settings", method: "workspace/didChangeConfiguration", register_options: None }
2024-07-30T06:04:27.688912Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-30T06:04:27.686Z] Agent service starting",
  "metadataStr": "[DEBUG] [agent] [2024-07-30T06:04:27.686Z]",
  "extra": [
    "Agent service starting"
  ]
}
2024-07-30T06:04:27.690139Z [INFO] Language server with id 0 sent unhandled notification client/registerCapability:
{
  "registrations": [
    {
      "id": "a6cbdf27-f31f-4df5-ab42-f07ee1cf9664",
      "method": "workspace/didChangeWorkspaceFolders",
      "registerOptions": {}
    }
  ]
}
2024-07-30T06:04:28.076001Z [INFO] Node runtime install_if_needed
2024-07-30T06:04:28.159223Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 0,
  "message": "[DEBUG] [agent] [2024-07-30T06:04:28.156Z] Telemetry initialized",
  "metadataStr": "[DEBUG] [agent] [2024-07-30T06:04:28.156Z]",
  "extra": [
    "Telemetry initialized"
  ]
}
2024-07-30T06:04:28.708109Z [INFO] downloading language server "vtsls"
2024-07-30T06:04:28.709537Z [INFO] Node runtime install_if_needed
2024-07-30T06:04:28.829167Z [INFO] starting language server. binary path: "/Users/michael/Library/Application Support/Zed/node/node-v22.5.1-darwin-arm64/bin/node", working directory: "/Users/michael/Code/client-app", args: ["/Users/michael/Library/Application Support/Zed/languages/vtsls/node_modules/@vtsls/language-server/bin/vtsls.js", "--stdio"]
2024-07-30T06:05:13.016323Z [INFO] Language server with id 0 sent unhandled notification LogMessage:
{
  "level": 1,
  "message": "[INFO] [ghostText] [2024-07-30T06:05:13.015Z] Cancelled by contextual filter",
  "metadataStr": "[INFO] [ghostText] [2024-07-30T06:05:13.015Z]",
  "extra": [
    "Cancelled by contextual filter"
  ]
}
@micthiesen micthiesen added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Jul 30, 2024
@micthiesen
Copy link
Author

I posted this issue on the Biome extension repo but it looks like it might be an issue with Zed sending the code action (not sure): biomejs/biome-zed#35

@micthiesen
Copy link
Author

Here are my Biome daemon logs in case that's helpful:

~/Library/Caches/dev.biomejs.biome/biome-logs/server.log.2024-07-30-15
├─  1ms DEBUG biome_lsp::handlers::analysis Suggested actions:
  │ [CodeAction(CodeAction { title: "Organize Imports (Biome)", kind: Some(CodeActionKind("source.organizeImports.biome")), diagnostics: None, edit: Some(WorkspaceEdit { changes: Some({Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/michael/Code/client-app/packages/functions/handlers/AbstractApiHandler.ts", query: None, fragment: None }: [TextEdit { range: Range { start: Position { line: 0, character: 7 }, end: Position { line: 0, character: 11 } }, new_text: "{ assertUser }" }, TextEdit { range: Range { start: Position { line: 0, character: 19 }, end: Position { line: 0, character: 23 } }, new_text: "api" }, TextEdit { range: Range { start: Position { line: 0, character: 24 }, end: Position { line: 0, character: 28 } }, new_text: "helpers" }, TextEdit { range: Range { start: Position { line: 0, character: 29 }, end: Position { line: 0, character: 33 } }, new_text: "asserts" }, TextEdit { range: Range { start: Position { line: 1, character: 7 }, end: Position { line: 1, character: 19 } }, new_text: "User" }, TextEdit { range: Range { start: Position { line: 1, character: 20 }, end: Position { line: 1, character: 22 } }, new_text: "" }, TextEdit { range: Range { start: Position { line: 1, character: 29 }, end: Position { line: 1, character: 32 } }, new_text: "core" }, TextEdit { range: Range { start: Position { line: 1, character: 33 }, end: Position { line: 1, character: 40 } }, new_text: "auth" }, TextEdit { range: Range { start: Position { line: 1, character: 41 }, end: Position { line: 1, character: 48 } }, new_text: "User" }, TextEdit { range: Range { start: Position { line: 6, character: 50 }, end: Position { line: 7, character: 46 } }, new_text: "" }, TextEdit { range: Range { start: Position { line: 10, character: 0 }, end: Position { line: 10, character: 0 } }, new_text: "import AbstractHandler from \"./AbstractHandler\";\n" }]}), document_changes: None, change_annotations: None }), command: None, is_preferred: Some(true), disabled: None, data: None })]
┌─┘
└─┐biome_lsp::handlers::formatting::format{params=DocumentFormattingParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/michael/Code/client-app/packages/functions/handlers/AbstractApiHandler.ts", query: None, fragment: None } }, options: FormattingOptions { tab_size: 2, insert_spaces: true, properties: {}, trim_trailing_whitespace: Some(true), insert_final_newline: Some(true), trim_final_newlines: Some(true) }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None } }}
  ├─  0ms DEBUG biome_service::workspace::server File capabilities: Js(JsFileSource { language: TypeScript { definition_file: false }, variant: Standard, module_kind: Module, version: ES2022, embedding_kind: None }) BiomePath { path: "/Users/michael/Code/client-app/packages/functions/handlers/AbstractApiHandler.ts" }
  ├─  0ms DEBUG biome_service::workspace The file has the following feature sets:
  │ {OrganizeImports: Supported, Lint: Supported, Search: FileNotSupported, Format: Supported}
  ├─  0ms DEBUG biome_lsp::handlers::formatting Formatting...
  ├─  0ms DEBUG biome_service::workspace::server File capabilities: Js(JsFileSource { language: TypeScript { definition_file: false }, variant: Standard, module_kind: Module, version: ES2022, embedding_kind: None }) BiomePath { path: "/Users/michael/Code/client-app/packages/functions/handlers/AbstractApiHandler.ts" }
  ├─  0ms DEBUG biome_service::file_handlers::javascript Options used for format:
  │ Indent style: Space
  │ Indent width: 2
  │ Line ending: LF
  │ Line width: 88
  │ Quote style: Double Quotes
  │ JSX quote style: Double Quotes
  │ Quote properties: As needed
  │ Trailing commas: All
  │ Semicolons: Always
  │ Arrow parentheses: Always
  │ Bracket spacing: true
  │ Bracket same line: false
  │ Attribute Position: Auto
  │
  ├─  0ms INFO biome_service::file_handlers::javascript Format file /Users/michael/Code/client-app/packages/functions/handlers/AbstractApiHandler.ts
  └─┐biome_formatter::printer::Printer::print{}
  ┌─┘
┌─┘
├─112m  WARN tower_lsp Got a textDocument/didSave notification, but it is not implemented

@notpeter notpeter added typescript TypeScript programming language support language server An umbrella label for all language servers and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Aug 1, 2024
@famouzkk
Copy link

same for me

@tuzemec
Copy link

tuzemec commented Aug 15, 2024

I'm still using Biome as external formatter. And I can't figure out a working config to have vtsls code actions on format even if my life depends on it.
It's really frustrating.

Current config that kinda worked some time ago but not anymore:

{
  "format_on_save": "on",
  "language_servers": [
    "vtsls",
    "biome",
    "!eslint",
    "!prettier",
    "!typescript-language-server",
    "..."
  ],
  "formatter": [
    {
      "language_server": {
        "name": "vtsls"
      }
    },
    {
      "external": {
        "command": "npx",
        "arguments": [
          "biome",
          "check",
          "--write",
          "--stdin-file-path={buffer_path}"
        ]
      }
    }
  ],
  "code_actions_on_format": {
    "source.removeUnusedImports.ts": true
  }
}

@flazouh
Copy link

flazouh commented Aug 16, 2024

Nothing seems to works with this ide, I tried to configure eslint first, no way to make it work, now trying biome, it works kinda, but organise imports doesn't work, eventhough it works in webstorm, i'm growing tired of fighting against this software tbh.

@trivikr
Copy link

trivikr commented Aug 17, 2024

Biome import sorting works for me on following the settings mentioned in https://github.com/biomejs/biome-zed

Example repo with settings https://github.com/aws/aws-sdk-js-codemod/blob/ac758504da4ccdf2502ead248748e7af8d6053ea/.zed/settings.json#L2-L6

@tuzemec
Copy link

tuzemec commented Aug 17, 2024

Biome import sorting works for me on following the settings mentioned in https://github.com/biomejs/biome-zed

Example repo with settings https://github.com/aws/aws-sdk-js-codemod/blob/ac758504da4ccdf2502ead248748e7af8d6053ea/.zed/settings.json#L2-L6

This is not working for me with 0.149.1.
Also it will disable all other language servers. Ideally only eslint and prettier should be disabled:

And now this is something that is working for me currently (as local project settings):

{
  "language_servers": ["biome", "!eslint", "!prettier", "..."],
  "format_on_save": "on",
  "code_actions_on_format": {
    "source.organizeImports.biome": true,
    "source.fixAll.ts": true,
    "source.removeUnusedImports.ts": true
  },
  "formatter": {
    "external": {
      "command": "npx",
      "arguments": [
        "biome",
        "check",
        "--write",
        "--stdin-file-path",
        "{buffer_path}"
      ]
    }
  }
}

It organizes the imports via biome and removes the unused imports (I guess via vtsls). But for some reason is not working on my work machine.

Also you need to have:

  "organizeImports": {
    "enabled": true
  },

in your project biome.json.

@vitallium
Copy link
Contributor

Can someone please check this issue against the newly released version of Biome - 1.9.4. I submitted a small fix for their LSP to correctly report available code actions. I think everything should be working with that version. Thanks!

@tuzemec
Copy link

tuzemec commented Oct 24, 2024

Can someone please check this issue against the newly released version of Biome - 1.9.4. I submitted a small fix for their LSP to correctly report available code actions. I think everything should be working with that version. Thanks!

Thanks @vitallium !
It seems to be working for me with biome 1.9.4 and Zed Preview 0.159.0 and the following config:

  "language_servers": [
    "typescript-language-server",
    "biome",
    "!vtsls",
    "!eslint",
    "!prettier",
    "..."
  ],
  "formatter": {
    "language_server": {
      "name": "biome"
    }
  },
  "code_actions_on_format": {
    "source.fixAll.biome": true,
    "source.organizeImports.biome": true,
    "source.removeUnusedImports.ts": true
  }

@github-actions github-actions bot added admin read Pending admin review triage Maintainer needs to classify the issue labels Nov 5, 2024
@notpeter notpeter removed triage Maintainer needs to classify the issue admin read Pending admin review labels Nov 5, 2024
@vitallium
Copy link
Contributor

It seems after landing biomejs/biome#4122 to Biome this LSP action started working. I think we can close this issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] language server An umbrella label for all language servers typescript TypeScript programming language support
Projects
None yet
Development

No branches or pull requests

8 participants