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

No tag representation for C++ using ctags #123

Closed
pavlosun opened this issue Jul 15, 2019 · 24 comments
Closed

No tag representation for C++ using ctags #123

pavlosun opened this issue Jul 15, 2019 · 24 comments
Labels
ctags help wanted 🙌 Extra attention is needed tree view

Comments

@pavlosun
Copy link

I started using Vista with coc as a replasemnt for tagbar. Everything looks good so far. My project is C++. In my Vista window, I have the following categories:
Method
Constructor
Namespace

Under the method category I have all my methods in the format:
namespace::class::method

IMHO, it would be more appropriate to have slighly different structure:

Namespace1
->Namespace2
-> Class
-> Method

The constructor and destructor should be grouped together or maybe not separated.

Let me know if you have any question.

@liuchengxu
Copy link
Owner

Use :Vista ctags for tree view. LSP executive doesn't have a tree view in vista.vim right now.

@pavlosun
Copy link
Author

ok, I switched to ctags. In my *.cpp file I see only namespace but in *.hpp I see nothing but an error:

Error detected while processing function <SNR>130_on_exit[6]..<SNR>130_ApplyExtracted[14]..vista#viewer#Display[1]..<SNR>136_Render[2]..vista#renderer#default
#Render[5]..<SNR>138_Render[50]..<SNR>138_RenderDescendants[44]..<SNR>138_RenderDescendants[41]..<SNR>138_DescendantsOf:                            
line    1:
E874: (NFA) Could not pop the stack!
Press ENTER or type command to continue
Error detected while processing function <SNR>130_on_exit[6]..<SNR>130_ApplyExtracted[14]..vista#viewer#Display[1]..vista#sidebar#OpenOrUpdate[23]..vista#util
#SetBufline[1]..<SNR>132_PrependFpath:
line    8:
E745: Using a List as a Number
Press ENTER or type command to continue
Error detected while processing function <SNR>130_on_exit[6]..<SNR>130_ApplyExtracted[14]..vista#viewer#Display[1]..vista#sidebar#OpenOrUpdate[23]..vista#util
#SetBufline[1]..<SNR>132_PrependFpath:
line    8:
E15: Invalid expression: [fpath, ''] + a:lines

I use Universal Ctags

    Current FileType: vista
Avaliable Executives: ['coc', 'ctags']
    Global Variables:
    let g:vista#executive#ctags#support_json_format = 1
    let g:vista#executives = ['ale', 'coc', 'ctags', 'lcn', 'vim_lsp']
    let g:vista#renderer#ctags = 'default'
    let g:vista#renderer#default#vlnum_offset = 3
    let g:vista#renderer#enable_icon = 1
    let g:vista#renderer#icons = {'subroutine': '洛', 'method': '', 'func': '', 'variables': '', 'namespace': '', 'field': '綠', 'interface': '禍', 'type': '', 'packages': '', 'property': '襁', 'implementation': '', 'default': '', 'augroup': 'פּ', 'macro': '', 'enumerator': '', 'const': '', 'macros': '', 'map': 'פּ', 'fields': '綠', 'functions': '', 'enum': '', 'function': '', 'target': '', 'typedef': '', 'variable': '', 'modules': '', 'constant': '', 'struct': 'פּ', 'types': '', 'module': '', 'typeParameter': '', 'package': '', 'class': '', 'member': '', 'var': '', 'union': '鬒'}
    let g:vista_default_executive = 'ctags'

@liuchengxu
Copy link
Owner

#82 seems to be related.

@pavlosun
Copy link
Author

Indeed, it solves the problem with header files. In the source file, I still see only the namespace definition but no error.

@liuchengxu
Copy link
Owner

Fill the full issue template please.

@pavlosun
Copy link
Author

Describe the bug
A clear and concise description of what the bug is.

When *.cpp file is opened, only namespace listed in the Vista window,

Environment:

  • Debian (testing)
  • NVIM v0.3.4
    Build type: Release
    LuaJIT 2.1.0-beta3
    Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-RiUqEm/neovim-0.3.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=1 -DDISABLE_LOG -Wdate-time -D_FORTIFY_SOURCE=1 -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim-RiUqEm/neovim-0.3.4/build/config -I/build/neovim-RiUqEm/neovim-0.3.4/src -I/usr/include -I/build/neovim-RiUqEm/neovim-0.3.4/build/src/nvim/auto -I/build/neovim-RiUqEm/neovim-0.3.4/build/include
    Compiled by [email protected]

Features: +acl +iconv -jemalloc +tui
See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"

  • This plugin version: 310ca5b
    Vista info

    Current FileType: cpp
Avaliable Executives: ['coc', 'ctags']
    Global Variables:
    let g:vista#executive#ctags#support_json_format = 1
    let g:vista#executives = ['ale', 'coc', 'ctags', 'lcn', 'vim_lsp']
    let g:vista#renderer#ctags = 'default'
    let g:vista#renderer#default#vlnum_offset = 3
    let g:vista#renderer#enable_icon = 1
    let g:vista#renderer#icons = {'subroutine': '洛', 'method': '', 'func': '', 'variables': '', 'namespace': '', 'field': '綠', 'interface': '禍', 'type': '', 'packages': '', 'property': '襁', 'implementation': '', 'default': '', 'augroup': 'פּ', 'macro': '', 'enumerator': '', 'const': '', 'macros': '', 'map': 'פּ', 'fields': '綠', 'functions': '', 'enum': '', 'function': '', 'target': '', 'typedef': '', 'variable': '', 'modules': '', 'constant': '', 'struct': 'פּ', 'types': '', 'module': '', 'typeParameter': '', 'package': '', 'class': '', 'member': '', 'var': '', 'union': '鬒'}
    let g:vista_default_executive = 'ctags'

Steps to reproduce given the above info

  1. Install Vista as described elsewhere.
  2. Open *.ccp file with class methods defined
    2.Type :Vista
    Expected behavior
    A clear and concise description of what you expected to happen.

Actual behavior
Only namespaces are visible in the vista window.
help explain your problem.

@pavlosun pavlosun changed the title tag representation for C++ - suggestion No tag representation for C++ Jul 18, 2019
@liuchengxu
Copy link
Owner

I realize that this issue may not be easy to fix since the current strategy used in https://github.com/liuchengxu/vista.vim/blob/master/autoload/vista/renderer/default.vim is unable to handle such a case. This needs some time to resolve.

@liuchengxu liuchengxu added the help wanted 🙌 Extra attention is needed label Sep 21, 2019
@heroin-moose
Copy link
Contributor

heroin-moose commented Sep 22, 2019

Same.

@liuchengxu, what seems to be the problem (which part of renderer should be changed)?

@liuchengxu
Copy link
Owner

Check out s:DescendantsOfRoot, I have not dived into this issue, but it should be a problem of the tree view. @heroin-moose .

@heroin-moose
Copy link
Contributor

heroin-moose commented Sep 23, 2019

@liuchengxu, at least comparing val.scopeKind to a:root_line.kind makes little sense since scopeKind is always class for class members. It is namespace only for plain variables/functions/etc:

namespace foo {
    size_t size = 0;                   /* Displayed in the tree */
    static size_t const Foo::size = 0; /* Not displayed in the tree */
}

@liuchengxu
Copy link
Owner

@heroin-moose Feel free to send a PR to fix it. I'm currently working on another unpublished plugin in my free time.(P.S. I'm very happy with this new plugin, with floating_win and popup, it's just wonderful ).

@heroin-moose
Copy link
Contributor

@liuchengxu, that's not all. I believe that RealParentOf needs some tweaks too.

P.S. Is this new plugin a replacement for Vista?

@liuchengxu
Copy link
Owner

liuchengxu commented Sep 23, 2019

Nope. I would say it a modern generic interactive finder and dispatcher which is able to find or dispatch anything on the fly, could be a replacement of ctrlp and other similar plugins, but in pure vimscript and the newly fancy floating_win and popup. @heroin-moose

@heroin-moose
Copy link
Contributor

Okay, there is one more catch. If you have no namespace, just plain file with a lots of FooBar::<member> entries, ctags correctly detects that all class members have scope FooBar. However, there will be no root node. So Vista must handle that case correctly by creating "virtual" root node.

@liuchengxu
Copy link
Owner

Sounds reasonable. Feel free to correct them.

@heroin-moose
Copy link
Contributor

heroin-moose commented Sep 23, 2019

Actually, it's not that simple. At the very least it would require creating a tag that has no name (can be guessed in a language-specific way) and with no line/expr. And there are places in the code where tags are compared by line numbers.

@heroin-moose
Copy link
Contributor

heroin-moose commented Sep 23, 2019

Well... it would be great to remove these line number checks because Vista can't handle this kind of code:

namespace foo { class Foo { int bar; class Bar { int bar; }; }; };

Tagbar can.

@liuchengxu
Copy link
Owner

Just do it :(, i'll review when you send a PR.

@heroin-moose
Copy link
Contributor

heroin-moose commented Nov 11, 2019

After some poking around I came to a conclusion that Vista has wrong data model for tags. Tagbar, for example, uses tree-like structure that allows strong bond between a parent and children. Vista, on the other hand, uses list and relies on searching descendants during the rendering phase via s:DescendantsOf and s:DescendantsOfRoot.

This works well until it does not. Consider this case:

#include <iostream>

using std::cout;
using std::endl;

namespace foo::bar {
	static const int x = 1;
};

void print_x(void)
{
	cout << foo::bar::x << endl;
}

namespace foo::bar {
	static const int y = 2;
};

void print_y(void)
{
	cout << foo::bar::y << endl;
}

int main(void)
{
	print_x();
	print_y();

	return 0;
}

This may be not the best way to use namespaces but it does illustrate the problem. As you can see there are too identical namespaces, each one with it's own variable: x or y.

Tagbar will handle this case correctly (at least tag-wise, since x will be available after the second namespace foo::bar) by displaying two namespace trees each having either x or y. Vista will also display two namespace trees, but the first one will have both x and y, since Vista will find both x and y during the descendants lookup:

function! s:DescendantsOf(candidates, root_line, scope) abort
  let candidates = filter(copy(a:candidates),
        \ 'has_key(v:val, ''scope'')'.
        \ ' && s:StartWith(v:val.scope, a:scope)'.
        \ ' && v:val.scopeKind ==# a:root_line.kind'.
        \ ' && v:val.line >= a:root_line.line'
        \ )

  return candidates
  " The real parent problem seemingly has been solved?
  " return filter(candidates, 's:RealParentOf(v:val) ==# a:root_line')
endfunction

There is a special function s:RealParentOf that tries to make things right and find the nearest ancestor, but it will fail in this case since it's taking in account only tags in t:vista.without_scope list.

I suggest changing Vista's internal structure from a list to a tree before working on this issue.

@liuchengxu
Copy link
Owner

liuchengxu commented Nov 12, 2019

Yes, I also have a feeling that the strategy used in vista is unable to handle various corner cases after seeing these issues and the abortion of #142, but I currently don't have enough time to dive into this issue. If you are willing to help, feel free to revise any related part, I can provide the necessary assistance.

@heroin-moose
Copy link
Contributor

@liuchengxu, since you've started CTags overhaul, I suggest adding this to the test suite:

namespace foo { class bar { static const int x = 1; }; };

static const int foo::baz::y = 2;

int
main(void)
{
	return 0;
}

The x is now visible (many thanks, sometimes I have to work with code that has weird coding style), y is still not (requires that virtual kind of tag we've been talking about).

@liuchengxu
Copy link
Owner

liuchengxu commented Feb 16, 2020

@heroin-moose Thanks for the test case. I haven't been working on #211 for a while as I don't know how to resolve the duplicated and psedu tag cases. Since I now mainly use vista for the data provider of my fuzzy finder instead of a tags structure explorer, and LSP can also have the tree view, I might not spend more time investigating the ctags tree view. Feel free to help if you are interested.

@liuchengxu liuchengxu changed the title No tag representation for C++ No tag representation for C++ using ctags Feb 17, 2020
@github-actions
Copy link

Stale issue message

@liuchengxu
Copy link
Owner

Closing for #320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctags help wanted 🙌 Extra attention is needed tree view
Projects
None yet
Development

No branches or pull requests

3 participants