[Github-comments] [geany/geany] Enable local variable and function parameter tag reporting for C/C++ (PR #3175)

Jiří Techet notifications at github.com
Thu Apr 21 12:52:18 UTC 2022


> Nice idea about the following declarations, fine for languages that are C, but be careful, at least Julia violates it ([see](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#Local-Scope) "This is true even if the outer local is declared after (in the sense of textually below) an inner block.") and other languages may too (I think Lisp). Or is this feature filetype specific to C/C++ only?

> [Edit: and inside C++ struct/class declarations all data member names are visible everywhere, even if declared after.]

I probably wasn't clear enough here but this is about local variables only and there's no change for other tag types. I think for variables declared inside functions it's safe to say that those declared after the current line are not usable.

> What about object data members in member functions, data members (and functions as well actually) from all parent classes are available as unqualified names automatically visible in the member function (ignoring complications like "private" and "protected").

I'm not sure if I understand but non-scope autocompletion in Geany just simply takes all the symbols having the typed string as a prefix and shows them. This includes all members of all classes, enums, etc. What I did is that in addition to that, I also included function parameters and local variables from the current function (but again, just those defined on the previous lines).

> Isn't scope autocompletion automatically limited to the applicable scope?

Despite being called "scope autocompletion" the way it works is more like "nesting-aware autocompletion". The scope information is used just to know what members various types have. The scope reported by ctags is more or less just the lexical scope not taking into account various scope-manipulation features of languages like `using namespace` and by just looking at what the `scope` field contains we wouldn't get correct results.

> ... when typing x. first apply (3) to find the possible types of x ...

This is basically the moment we are talking about - finding possible types of `x`. The way it works is that scope autocompletion finds all tags named `x` and then examines whether its `var_type` is a tag of a type that can contain some members. When searching for tags named `x`, scope autocompletion goes in this order:
1. Local variable tags preceding the current line
2. Tags appearing in the current file
2a. (For C/C++ it might be a good idea to improve this by looking for a header file with the same name and continue by looking for the tags there)
4. Workspace tags
5. Global tags

This way we simulate the true scope search and variable visibility (local variables shadowing variables declared in the file which in turn shadow variables declared in other files).

> I presume by <> you mean C++ template parameters? If so, although the parameters are actually part of the typename, technically the members (and so completions) can vary between specialisations. What do you do when there are several, show only the original declaration members, or combine members from all specialisations?

ctags knows basically just the declarations and doesn't track template parameters. When there is `void foo(T t) {}`, for ctags it's the same thing whether `T` is a template parameter or some type. You will see `T` in the symbol tree tooltip or in function parameter calltip.

> Neat!! Does it ripple up through grandparents and great grandparents etc?

Yes, to depth 10. Just added some hard-limit to avoid infinite recursion for things like
```
class C : C {
};
```

> This also applies to non-scope autocompletion inside member functions as mentioned above.

As noted above, non-scope autocompletion is just primitive prefix-matching autocompletion including all tags and those member tags are already included.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3175#issuecomment-1105169579
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany/pull/3175/c1105169579 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20220421/751d6120/attachment-0001.htm>


More information about the Github-comments mailing list