From 13bdb37cf7496a27b0b77c9893839c0fc3aba186 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 18 Apr 2022 00:38:12 +0200 Subject: [PATCH] Update goto symbol definitions to take into account local variables We only want to use local variables within the current function for the goto. This means we want to filter out local variable tags that: 1. Are from a different file 2. Are declared later in the file than where the current cursor is 3. Have different scope than the current function scope Fundamentally the same requirements as for (non-scope) autocompletion. --- src/symbols.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/symbols.c b/src/symbols.c index 51a5a93f1..d211b505a 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -1597,13 +1597,23 @@ static TMTag *find_best_goto_tag(GeanyDocument *doc, GPtrArray *tags) static GPtrArray *filter_tags(GPtrArray *tags, TMTag *current_tag, gboolean definition) { + GeanyDocument *doc = document_get_current(); + guint current_line = sci_get_current_line(doc->editor->sci) + 1; const TMTagType forward_types = tm_tag_prototype_t | tm_tag_externvar_t; TMTag *tmtag, *last_tag = NULL; + const gchar *current_scope = NULL; GPtrArray *filtered_tags = g_ptr_array_new(); guint i; + symbols_get_current_function(doc, ¤t_scope); + foreach_ptr_array(tmtag, i, tags) { + /* don't show local variables outside current function or other + * irrelevant tags - same as in the autocomplete case */ + if (!tm_workspace_is_autocomplete_tag(tmtag, doc->tm_file, current_line, current_scope)) + continue; + if ((definition && !(tmtag->type & forward_types)) || (!definition && (tmtag->type & forward_types))) { -- 2.11.4.GIT