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

Click to Goto Definition? #81

Open
bscan opened this issue Nov 28, 2023 · 3 comments
Open

Click to Goto Definition? #81

bscan opened this issue Nov 28, 2023 · 3 comments

Comments

@bscan
Copy link

bscan commented Nov 28, 2023

Is it possible to use ctrl+click for Goto Definition? Ctrl+Click is the default for goto definition in vscode, Intellij, and the Kate editor.

When I update the Keybinding for lsp:goto-definition to ctrl+1lclick, it results in looking up the definition under the cursor rather than under the mouse, which is not intuitive. This means I that I would need to first click and then ctrl+click for goto definition. See the gif below where I'm trying to goto definition on Foo

Goto

@Guldoman
Copy link
Member

Yeah, we could add a lsp:goto-definition-under-cursor command.

Adding something like this to your user module should work for now:

local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local lsp = require "plugins.lsp"

command.add(
  function()
    local dv = core.active_view
    return dv and dv.doc and dv.doc.lsp_open, dv and dv.doc or nil
  end, {
  ["lsp:goto-definition-under-cursor"] = function()
    local doc, line, col = lsp.get_hovered_location(core.root_view.mouse.x, core.root_view.mouse.y)
    if doc then
      lsp.goto_symbol(doc, line, col)
    end
  end,
})

keymap.add({
  ["ctrl+1lclick"] = "lsp:goto-definition-under-cursor",
})

@bscan
Copy link
Author

bscan commented Nov 29, 2023

Perfect, this worked for me. Thanks!

@MrNavaStar
Copy link

would love to see this feature merged, thanks for snippet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants