From db5d7e5cac00de7f9e2aee48b05bde5397370dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 8 May 2023 13:34:08 +0200 Subject: [PATCH 1/2] Add a flag indicating whether to trust isFileScope from ctags ctags treats unknown C/C++ file extensions as if they were source files. Because of this, the isFileScope flag is incorrectly set to TRUE for such files even if they are headers and the defined tags don't have a file-only scope. To fix this, we intorduce a flag called trust_file_scope which we set to TRUE only when the source file name matches one of the known C/C++ extensions. For all other languages the flag is set to TRUE. --- src/tagmanager/tm_source_file.c | 19 +++++++++++++++++++ src/tagmanager/tm_source_file.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/tagmanager/tm_source_file.c b/src/tagmanager/tm_source_file.c index 01c3952766..3e9ac38bee 100644 --- a/src/tagmanager/tm_source_file.c +++ b/src/tagmanager/tm_source_file.c @@ -609,6 +609,25 @@ static gboolean tm_source_file_init(TMSourceFile *source_file, const char *file_ else source_file->lang = tm_ctags_get_named_lang(name); + source_file->trust_file_scope = TRUE; + + if (source_file->lang == TM_PARSER_C || source_file->lang == TM_PARSER_CPP) + { + const gchar **ext; + const gchar *common_src_exts[] = + {".c", ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", ".CPP", ".CXX", NULL}; + + source_file->trust_file_scope = FALSE; + for (ext = common_src_exts; *ext; ext++) + { + if (g_str_has_suffix(source_file->short_name, *ext)) + { + source_file->trust_file_scope = TRUE; + break; + } + } + } + return TRUE; } diff --git a/src/tagmanager/tm_source_file.h b/src/tagmanager/tm_source_file.h index 073048c41d..691cd96c9c 100644 --- a/src/tagmanager/tm_source_file.h +++ b/src/tagmanager/tm_source_file.h @@ -35,6 +35,7 @@ typedef struct TMSourceFile char *file_name; /**< Full file name (inc. path) */ char *short_name; /**< Just the name of the file (without the path) */ GPtrArray *tags_array; /**< Sorted tag array obtained by parsing the object. @elementtype{TMTag} */ + gboolean trust_file_scope; } TMSourceFile; GType tm_source_file_get_type(void); From 2fd242b94c41f9254b2288fdb39a1c20d819b53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 8 May 2023 13:52:13 +0200 Subject: [PATCH 2/2] For C/C++ only mark tag as local if it originates from a source file --- src/tagmanager/tm_ctags.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tagmanager/tm_ctags.c b/src/tagmanager/tm_ctags.c index 896413b711..16e2ebf04e 100644 --- a/src/tagmanager/tm_ctags.c +++ b/src/tagmanager/tm_ctags.c @@ -119,7 +119,7 @@ static gboolean init_tag(TMTag *tag, TMSourceFile *file, const tagEntryInfo *tag tag->name = g_strdup(tag_entry->name); tag->type = type; - tag->local = tag_entry->isFileScope; + tag->local = tag_entry->isFileScope && file->trust_file_scope; tag->flags = tm_tag_flag_none_t; if (isTagExtraBitMarked(tag_entry, XTAG_ANONYMOUS)) tag->flags |= tm_tag_flag_anon_t;