1. 9
  1.  

  2. 6

    That’s… cool, but ctags is a 1980’s-style tool. It sometimes works, sometimes doesn’t, but it’s worth noting that today the trend is to use the ‘language server protocol’.

    https://langserver.org/

    LSP for e.g. C++ also sometimes works, sometimes doesn’t work (like ctags I guess) but at least it addresses issues that are impossible to solve by using ctags-style tools (i.e. context-aware symbol lookups).

    But yes, I can’t deny that in the absence of LSP, ctags is a good choice (it’s better than grep!)

    1. 3

      ctags is a 1980’s-style tool. It sometimes works, sometimes doesn’t

      I’m curious what people mean when they say stuff like this. What’s so janky about ctags compared to, say, modern tooling? Or is the only difference that one is newer & trendier than the other?

      LSP for e.g. C++ also sometimes works, sometimes doesn’t work (like ctags I guess)

      My thinking exactly!

      it’s worth noting that today the trend is to use the ‘language server protocol’

      I’ve only ever used Language Server, and while it’s nice and universal, it definitely still has its hiccups. Also, it’s practically owned by Microsoft, and basically just exists to ease adoption of VS Code, which has native support for it.

      issues that are impossible to solve by using ctags-style tools (i.e. context-aware symbol lookups)

      Could you elaborate on this? I’m curious as to the limitations of older tooling and how (if at all) newer tooling has improved upon it.

      1. 5

        LSP isn’t really a smooth ride for me, and I always stumble on some “corner case” that reminds me it still has long way to go, but there are many advantages of LSP over ctags:

        • it can list class methods/fields of a class, even if the type is aliased to a different name,
        • it can infer a type because it knows how semantics work,
        • it supports parsing documentation comments,
        • it knows when some #define is defined or not, because it knows exactly how each file in the project is compiled (if used with e.g. cmake),
        • it supports finding references in the SDK,
        • not every LSP server supports this, but at least theoretically it can support safe refactoring,
        • it can display syntax errors/warnings during typing the code.

        Failure scenarios for ctags include situations like these:

        • Trying to find the definition of a method with a highly generic name, e.g. get(). This will probably always end up with lots of potential hits even in classes that are not related to your current class. It’s probably fine most of the time in C where each function is often declared with an unique name, but C++ names can be very generic, because they’re closed in namespaces/classes so they don’t clash with each other. LSP server solves this because it understands the context of where the cursor is currently located.
        • It doesn’t see symbols created by using macros. LSP server should solve this because it should understand the language syntax, and should be able to parse through macros.
        • Trying to find a symbol in the SDK, unless manually instructed to index the whole SDK. But even then it sometimes fails because libc heavily uses macros and conditional includes.
        • It fails in indexing thirdparty libraries, because it doesn’t know what libraries are being compiled in the project. User can manually instruct ctags by adding paths to thirdparty projects, but still ctags will have no information about availability of selected symbol in current context.
        • It has no understanding of overloaded names and templates in C++, because it doesn’t parse the language. Again, LSP server should solve this because it uses an actual parser.

        But, of course, lots of times ctags work as expected, or at least it “works enough”. That’s why I still think it’s a useful tool.

        Microsoft’s influence is an unfortunate thing, but at the same time there are already many LSP clients and servers that are not controlled my MS at all.

      2. 3

        But yes, I can’t deny that in the absence of LSP, ctags is a good choice (it’s better than grep!)

        This is one of those things that sound like a truism, but I’m not convinced. There’s an Emacs mode (called something like dumb-jump) implementing “go to definition” functionality through regular grep. And it’s surprisingly good. I frequently prefer it to ctags based solutions because it just… Works.

        1. 2

          I think it’s been 10 years since I last used ctags and I really didn’t like it whereas all the LSP stuff I used didn’t make any problems so far - but maybe it’s because I mostly use IDEs with LSP support and not pure vim/emacs. Hmm…