Ale: C/C++ ALEGoToDeclaration (or ALEGoToImplementation)

Created on 31 May 2019  路  10Comments  路  Source: dense-analysis/ale

Since there is ALEGoToDefinition, maybe there should be an ALEGoToDeclaration for languages (like C/C++) which have those separately (e.g. the ALEGoToDefinition should go to the right place in the *.h file, and the ALEGoToDeclaration should go to the right place in the corresponding *.cpp file.)

FWIW, YouCompleteMe has a similar feature:
https://github.com/Valloric/YouCompleteMe#the-gotodeclaration-subcommand

enhancement

Most helpful comment

This can be re-opened as the language server protocol specification has since been updated to include a "go to declaration" command. https://microsoft.github.io/language-server-protocol/specification#textDocument_declaration It might not be implemented by a lot of servers yet.

The "go to implementation" command has been around for longer and has a different purpose. https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation

All 10 comments

There's :ALEGoToTypeDefinition, does that do what we want?

I think ALEGoToTypeDefinition already covers this.

:ALEGoToTypeDefinition doesn't seem to work for me in C++, it does the same thing as ALEGoToDefinition. I use clangd+compile_commands.json to get my type info (I have a lot of other linters installed, but they don't read compile_commands -- I'm not sure how they all combine in ALE).

That might be something that needs to be fixed in the language server. I can't see a "go to declaration" command command in the language server protocol specification. The only options appear to be "go to definition," "go to type definition," and "go to implementation." "Go to type definition" looks like the closest thing to a "go to declaration" command.

Is there an ALEGoToImplementation command? I think that if that's something a language server provides, then "Go to implementation" sounds like it might work here to go to e.g. the definition of a function in a *.cpp file.

The terms are somewhat confusing and language server seems to call them the opposite of what I'd call them, but here's what I would be interested to try:

  • ALEGoToDefinition -> goes to function declaration in *.h (this is the current behaviour, even though I think it is a declaration)
  • ALEGoToImplementation -> goes to function definition in *.cpp (I don't think this command exists yet in ALE, but I'd be curious what the language server does)
  • ALEGoToTypeDefinition -> maybe this doesn't apply to C++, or maybe e.g. if you had the cursor placed on a function that returns a class, then GoToTypeDefinition would go to the definition of the class?

Since there is ALEGoToDefinition, maybe there should be an ALEGoToDeclaration for languages (like C/C++) which have those separately (e.g. the ALEGoToDefinition should go to the right place in the *.h file, and the ALEGoToDeclaration should go to the right place in the corresponding *.cpp file.)

FWIW, YouCompleteMe has a similar feature:
https://github.com/Valloric/YouCompleteMe#the-gotodeclaration-subcommand

I think you got it the other way around. ALEGoToDefinition should bring you to the implementation in the *.cpp file, while ALEGoToDeclaration should bring you to the declaration in the *.h file.

But I agree, this functionality would be really nice to see :)
For example, vim-lsp implements this feature.

P.S. Thank you @w0rp for this plugin, it's awesome!

I agree with @proxict that terminology would be most correct for C++.

I had hoped it would also handle the case for other languages which only use a single definition+declaration point, so in that case, as long as both GoToDefinition and GoToDeclaration commands do the same thing it should be fine. (For key mapping simplicity, so I wouldn't need per-language mappings e.g. to prefer GoToDefinition in C++ files)

@w0rp, can this issue be reopened? This feature would be so nice to have for languages which require a separate declaration from definition.

This can be re-opened as the language server protocol specification has since been updated to include a "go to declaration" command. https://microsoft.github.io/language-server-protocol/specification#textDocument_declaration It might not be implemented by a lot of servers yet.

The "go to implementation" command has been around for longer and has a different purpose. https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation

Typescript file also has same problem. we need go to implementation to find a implementation of a interface. So far, as I know, the coc has this feature.
So far if I use ale and coc, both of them will launch a ts-server, which make two node process to eat up my cpu. I think I can use ale only if has go to implementation. Thanks :)

Was this page helpful?
0 / 5 - 0 ratings