vim-language-server icon indicating copy to clipboard operation
vim-language-server copied to clipboard

Feature: goto definition for values defined in another script

Open pappasam opened this issue 5 years ago • 6 comments

First, thanks for this language server! It does its job well.

I have lots of plugins and it would be nice if I could jump to the definition of a function, a variable, or a command that is defined in another function. For example:

:verbose command FiletypeFormat
    Name              Args Address Complete   Definition
    FiletypeFormat    0    %                  silent! let b:filetype_formatter_winview = winsaveview() | <line1>,<line2>call filetype_formatter#format_filetype() | silent call winrestview(b:filetype_formatter_win
view)
        Last set from ~/.config/nvim/pack/packager/start/vim-filetype-formatter/plugin/filetype_formatter.vim line 113

The result gives me the file and line where the command (or function if using function) was last defined. Maybe we can use this, or something like it, to locate definitions in other VimScripts?

The above assumes that the user is using Vim to edit their Vimscript.

pappasam avatar May 05 '20 21:05 pappasam

It can jump to the plugin vim file and works as expected for me.

iamcco avatar May 06 '20 06:05 iamcco

Try this in your vimrc:

command Hello echo 'hello'
nmap h :Hello<cr>

Put your cursor over the Hello in the nmap. Does it jump to the command definition for you? It doesn't look like goto definition works for Vim "commands" at all for me.

Also, for functions, after some more testing, I've found that the problem seems to be that if a function contains an underscore (_) in its name, goto definition does not work.

filetype_formatter#echo_log() defined in autoload/filetype_formatter is not found.

pappasam avatar May 06 '20 15:05 pappasam

No, it does not support command, because it can not recognize the 'Hello' as an command in 'nmap h :Hello'

iamcco avatar May 06 '20 15:05 iamcco

I don't know how you test with funcrion but it works well for me. Make sure your files in workspace or vim runtime path.

iamcco avatar May 06 '20 15:05 iamcco

Should it handle vim9script as well as classic vimscript? With the following init options

	\      indexes: {
	\        "runtimepath": v:true,
	\        "gap": 100,
	\        "count": 3,
	\      },
	\      suggest: {
	\        "fromVimruntime": v:true,
	\        "fromRuntimepath": v:true,
	\      }
	\    },

it indexes all of my classic vimscript plugins, but LspAddServer is not indexed.

BourgeoisBear avatar Aug 14 '23 11:08 BourgeoisBear

vim9script is not support yet https://github.com/iamcco/vim-language-server/issues/78

iamcco avatar Sep 07 '23 06:09 iamcco