cursorless-dev / cursorless

Don't let the cursor slow you down
https://www.cursorless.org/
MIT License
1.09k stars 77 forks source link

neovim: support clicking targets #2405

Open fidgetingbits opened 3 weeks ago

fidgetingbits commented 3 weeks ago

If I have a URL in the terminal and target it with click second paint row <blah> it doesn't open the link, like it would in vscode. It prints the openLink Not implemented error. This would be useful for instance if you git push and then get a PR link listed like this:

❯ git push --set-upstream origin cleanup-utils
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 20 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 868 bytes | 868.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
remote: 
remote: Create a pull request for 'cleanup-utils' on GitHub by visiting:
remote:      https://github.com/hands-free-vim/talon.nvim/pull/new/cleanup-utils
remote: 
To ssh://github.com/hands-free-vim/talon.nvim
 * [new branch]      cleanup-utils -> cleanup-utils
branch 'cleanup-utils' set up to track 'origin/cleanup-utils'.
pokey commented 3 weeks ago

note that it should also jump to definition if you use it to target an identifier

saidelike commented 3 weeks ago

I think it should be easy to implement as long as we have a way to open the default browser that works on linux/windows/osx.

Maybe using something like https://github.com/chrishrb/gx.nvim?

fidgetingbits commented 3 weeks ago

I think it should be easy to implement as long as we have a way to open the default browser that works on linux/windows/osx.

Maybe using something like https://github.com/chrishrb/gx.nvim?

The gx mapping is already a default builtin that is cross-platform. In t and nt mode we could just have cursorless issue a gx on the target and it's up to the user to manually install gx.nvim or not if they want something fancier. Could be listed as a recommended plugin or something.

From :help gx:

gx          Opens the current filepath or URL (decided by
            |<cfile>|, 'isfname') at cursor using the system
            default handler, by calling |vim.ui.open()|.

                            *v_gx*
{Visual}gx      Opens the selected text using the system default
            handler, by calling |vim.ui.open()|.

From :help vim.ui.open():

vim.ui.open({path})                                            *vim.ui.open()*
    Opens `path` with the system default handler (macOS `open`, Windows
    `explorer.exe`, Linux `xdg-open`, …), or returns (but does not show) an
    error message on failure.

    Expands "~/" and environment variables in filesystem paths.

    Examples: >lua
        -- Asynchronous.
        vim.ui.open("https://neovim.io/")
        vim.ui.open("~/path/to/file")
        -- Synchronous (wait until the process exits).
        local cmd, err = vim.ui.open("$VIMRUNTIME")
        if cmd then
          cmd:wait()
        end
<

    Parameters: ~
      • {path}  (`string`) Path or URL to open

    Return (multiple): ~
        (`vim.SystemObj?`) Command object, or nil if not found.
        (`string?`) Error message on failure, or nil on success.

    See also: ~
      • |vim.system()|

For being able to jump to definition (which is outside the scope of terminal side I think?) you'd have to do some more complicated target pre-parsing to see if it is a URL, path, or a follow-able symbol I guess.