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

Feature Request - goto definition for YAML alias/anchors #18

Closed
weilbith opened this issue Apr 9, 2021 · 8 comments · Fixed by nvim-treesitter/nvim-treesitter#1203
Closed
Labels
enhancement New feature or request

Comments

@weilbith
Copy link

weilbith commented Apr 9, 2021

Is your feature request related to a problem? Please describe.
Working with large YAML files (e.g. some continuous integration configurations), anchors are a typical feature. It is a typical scenario that you are at an alias that merges an anchor and you want to now how the content looks the anchor refers to. As anchors are usually references multiple times in the same document, it is annoying to use tools like * or similar.

Describe the solution you'd like
I would be cool if you could use goto_definition on an alias to jump to the related anchor.

Describe alternatives you've considered
Using * many times (also causes trouble for anchors names that are not a single word like my-anchor)
Using include search like [ <CTR-I (also suffers from word boundaries and must not be accurate/correct)
The YAML language server apparently does not support such "definition" jumps as well.

@weilbith weilbith added the enhancement New feature or request label Apr 9, 2021
@weilbith weilbith changed the title Feature Request - goto definition for YAML anchors Feature Request - goto definition for YAML alias/anchors Apr 9, 2021
stsewd added a commit to stsewd/nvim-treesitter that referenced this issue Apr 10, 2021
The parser doesn't break the symbols in `*` `&` from the name of
anchors/aliases. So go to definition doesn't work, but highlight of
usage does :D

Test with

```yaml
Defaults: &defaults
  Company: foo
  Item: 123

Computer:
  <<: *defaults
  <<: *defaults
  Price: 3000
```

Ref nvim-treesitter/nvim-treesitter-refactor#18
@stsewd
Copy link
Member

stsewd commented Apr 10, 2021

This needs to be changed in locals.scm (nvim-treesitter/nvim-treesitter#1172) and in the parser itself (parse the name of the anchor/alias and the * & symbols by separate ikatyang/tree-sitter-yaml#23) in order for go to definition to work

stsewd added a commit to nvim-treesitter/nvim-treesitter that referenced this issue Apr 10, 2021
The parser doesn't break the symbols in `*` `&` from the name of
anchors/aliases. So go to definition doesn't work, but highlight of
usage does :D

Test with

```yaml
Defaults: &defaults
  Company: foo
  Item: 123

Computer:
  <<: *defaults
  <<: *defaults
  Price: 3000
```

Ref nvim-treesitter/nvim-treesitter-refactor#18
@weilbith
Copy link
Author

Cool. Thanks for your work!
But just to be sure: this is not yet working, but got just kinda prepared. Right?

@stsewd
Copy link
Member

stsewd commented Apr 10, 2021

Cool. Thanks for your work!
But just to be sure: this is not yet working, but got just kinda prepared. Right?

Isn't fully working yet, yeah. ikatyang/tree-sitter-yaml#23 needs to be addressed.

Thanood pushed a commit to Thanood/nvim-treesitter that referenced this issue Apr 14, 2021
The parser doesn't break the symbols in `*` `&` from the name of
anchors/aliases. So go to definition doesn't work, but highlight of
usage does :D

Test with

```yaml
Defaults: &defaults
  Company: foo
  Item: 123

Computer:
  <<: *defaults
  <<: *defaults
  Price: 3000
```

Ref nvim-treesitter/nvim-treesitter-refactor#18
stsewd added a commit to stsewd/nvim-treesitter that referenced this issue Apr 18, 2021
stsewd added a commit to nvim-treesitter/nvim-treesitter that referenced this issue Apr 18, 2021
@weilbith
Copy link
Author

Do I need to do something to make it work? Except of updating all treesitter plugins?

@stsewd
Copy link
Member

stsewd commented Apr 20, 2021

Do I need to do something to make it work? Except of updating all treesitter plugins?

You need to update the plugins and the parser :TSUpdate. You can also change the default mapping of goto_definition https://github.com/nvim-treesitter/nvim-treesitter-refactor#navigation

@gegoune
Copy link

gegoune commented Apr 20, 2021

I have everything most up to date, and with this configuration:

navigation = {
  enable = true,
  keymaps = {
    goto_definition_lsp_fallback = "<C-]>"
  }
}

and

vim.api.nvim_buf_set_keymap(0, "n", "<C-]>", "<cmd>lua vim.lsp.buf.definition()<CR>", {noremap = true, silent = true})

pressing C-] one yaml's anchor does not move the cursor at all.

@stsewd
Copy link
Member

stsewd commented Apr 23, 2021

Hi, this is my config

require'nvim-treesitter.configs'.setup {
  ensure_installed = "all",
  refactor = {
    navigation = {
      enable = true,
      keymaps = {
        goto_definition = "gd",
      },
    },
  },
}

Make sure you have the latest version of the yaml parser installed :TSInstall yaml

This is the file I'm testing with

Defaults: &defaults
  Company: foo
  Item: 123

Computer:
  <<: *defaults
  <<: *defaults
  Price: 3000

Setting the cursor under *defaults and pressing gd moves the cursor to &defaults.

I can see this doesn't work with goto_definition_lsp_fallback, but that looks like a bug in another part of the code, I don't use neovim's lsp, so I can be helpful with that option.

stsewd added a commit to stsewd/nvim-treesitter-refactor that referenced this issue Apr 23, 2021
@stsewd
Copy link
Member

stsewd commented Apr 23, 2021

@cloggier this should fix the lsp fallback #19

stsewd added a commit that referenced this issue May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants