sublimelsp / LSP-typescript

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

Infer parameter types from usage #233

Closed mikez closed 6 months ago

mikez commented 6 months ago

Is there a way to trigger "Infer parameter types from usage" on request?

Currently, I do it by toggling the diagnostic panel (⌥⌘M), seeking the file and line I'm on, and then double-clicking the line where it says "Infer parameter types from usage".

Is there an easier way?

(Thank you for this plugin, @rchl.)

rchl commented 6 months ago

You can add keybinding to trigger code actions like:

    {
        "keys": ["primary+."],
        "command": "lsp_code_actions",
        "context": [{"key": "lsp.session_with_capability", "operand": "codeActionProvider"}]
    },

This one triggers code actions on cmd+.. You can configure it as you want.

mikez commented 6 months ago

@rchl Thank you, I just tried it out. It doesn't show the "infer parameters from usage".

The diagnostics panel shows this: image and clicking on said line in the diagnostics panel, I see this: image

However, pressing ⌘+. while on line 21 in the actual file only shows this one action: image

How can I make "infer parameters from usage" an option as well?

rchl commented 6 months ago

I think it might show if you place your cursor within parameters since those code actions are context-specific.

predrag-codetribe commented 6 months ago

Here is how it works for me https://github.com/sublimelsp/LSP-typescript/assets/115091796/607d2167-9b70-45b4-9372-e582bfebf427

mikez commented 6 months ago

@rchl That resolved it! Thank you. :)

Here's my updated flow:

  1. Move cursor to the first function parameter.
  2. Press ⌘+. &

Follow-up question: Can I cycle through all lines that appear in ⌥⌘M, as opposed to having to click on each? A "find next" diagnostic action, a bit like the ⌘G key for search.

rchl commented 6 months ago

You can find various related key bindings in Preferences: LSP key bindings including ones that show diagnostics in a quick panel and ones that jump to next/previous diagnostics. This is a better way of handling navigation than using the panel since the latter is erratic.

mikez commented 6 months ago

@predrag-codetribe Out of curiosity, how did you record and paste that video into Github?

mikez commented 6 months ago

@rchl 👌. …/LSP/Default.sublime-keymap is an amazing resource. Thank you!!

predrag-codetribe commented 6 months ago

@mikez I use Kap . It allows me to export a video to mp4, gif.