sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin
MIT License
131 stars 11 forks source link

SortImports #248

Closed mikez closed 1 month ago

mikez commented 1 month ago

How does VsCode do sortImports, is this not using typescript language server?

The issue with organizeImports is that it removes "unused" classes which sometimes are used in JavaScript JSDoc annotations; I want to keep those imports. The sortImports command only sorts and doesn't remove.

rchl commented 1 month ago

I think the readme is a bit outdated. The source.sortImports.ts code action is also supported - https://github.com/typescript-language-server/typescript-language-server/blob/master/README.md#code-actions-on-save

mikez commented 1 month ago

👍 confirm that lsp_code_actions_on_save works.

Should lsp_execute with _typescript.sortImports also work? Can't make it work yet.

rchl commented 1 month ago

No, this is a newer functionality that doesn't have legacy _typescript.* command exposed since it should be redundant. It should be possible to invoke code action through the editor.

mikez commented 1 month ago

In the README.md, you have this example listed:

{ "keys": ["ctrl+k"], "command": "lsp_execute",
  "args": {
    "session_name": "LSP-typescript",
    "command_name": "_typescript.organizeImports",
    "command_args": ["${file}"]
  }
}

How would I setup a keyboard shortcut otherwise?

rchl commented 1 month ago

Actually maybe there is no direct equivalent to that.

You could do this:

    {
        "keys": ["alt+c"],
        "command": "lsp_code_actions",
        "args": {"only_kinds": ["source.sortImports.ts"]},
        "context": [{"key": "lsp.session_with_capability", "operand": "codeActionProvider.codeActionKinds"}]
    }

but that would still pop up a menu that you would have to confirm.