iamcco / vim-language-server

VImScript language server, LSP for vim script
508 stars 17 forks source link

Feature: goto definition for values defined in another script #39

Open pappasam opened 4 years ago

pappasam commented 4 years ago

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.

iamcco commented 4 years ago

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

pappasam commented 4 years ago

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.

iamcco commented 4 years ago

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

iamcco commented 4 years ago

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.

BourgeoisBear commented 1 year ago

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.

iamcco commented 1 year ago

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