Skip to content

Commit ff7c1a1

Browse files
committed
Fix Python Symbol Kind Mapping for CTags
Teach the CTags symbol parser to consider the source file extension when mapping ctags output into internal symbol kinds. This fixes Python methods that are reported as "member" entries by ctags so they are recognized as methods rather than being dropped or misclassified. The parser now derives the file extension from the target file path and passes it through the symbol-kind mapping path, keeping the behavior otherwise unchanged for other languages. * CTags parsing * Symbol kind mapping **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent 4e04564 commit ff7c1a1

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

CodeLite/CTags.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ bool CTags::IsSupportedSymbolLanguage(const wxString& language)
100100
return std::find(supported.begin(), supported.end(), lang) != supported.end();
101101
}
102102

103-
std::optional<CTags::SymbolKind>
104-
CTags::MapSymbolKind(const wxString& kind, const wxString& scope, const wxString& kind_from_ctags)
103+
std::optional<CTags::SymbolKind> CTags::MapSymbolKind(const wxString& kind,
104+
const wxString& scope,
105+
const wxString& kind_from_ctags,
106+
const wxString& file_ext)
105107
{
106108
const wxString k = kind.Lower();
107109
const wxString c = kind_from_ctags.Lower();
@@ -115,6 +117,9 @@ CTags::MapSymbolKind(const wxString& kind, const wxString& scope, const wxString
115117
return SymbolKind::kPrototype;
116118
if (k == "method" || c == "method")
117119
return SymbolKind::kMethod;
120+
if (file_ext == "py" && c == "member")
121+
// Python methods are marked as "members"
122+
return SymbolKind::kMethod;
118123
if (k == "function") {
119124
if (scope.empty() || scope == "<global>")
120125
return SymbolKind::kGlobalMethod;
@@ -142,7 +147,8 @@ std::optional<wxString> CTags::DoSymbolGenerate(const wxString& file, const wxSt
142147
return wxString::FromUTF8(result.out);
143148
}
144149

145-
std::vector<CTags::SymbolInfo> CTags::ParseSymbolOutput(const wxString& content, const wxString& filename)
150+
std::vector<CTags::SymbolInfo>
151+
CTags::ParseSymbolOutput(const wxString& content, const wxString& filename, const wxString& file_ext)
146152
{
147153
std::vector<SymbolInfo> out;
148154
wxArrayString lines = ::wxStringTokenize(content, "\n", wxTOKEN_STRTOK);
@@ -163,7 +169,7 @@ std::vector<CTags::SymbolInfo> CTags::ParseSymbolOutput(const wxString& content,
163169
scope = wxString::FromUTF8(entry["scope"].get<std::string>());
164170
}
165171

166-
auto mapped_kind = MapSymbolKind(kind, scope, kind);
172+
auto mapped_kind = MapSymbolKind(kind, scope, kind, file_ext);
167173
if (!mapped_kind) {
168174
continue;
169175
}
@@ -233,8 +239,9 @@ clStatusOr<std::vector<CTags::SymbolInfo>> CTags::ParseFileSymbols(const wxStrin
233239
if (!content)
234240
return std::vector<CTags::SymbolInfo>{};
235241

242+
wxString file_ext = wxFileName{tmpfile.get() ? tmpfile->GetFullPath() : file}.GetExt();
236243
clDEBUG() << "Parsing symbols..." << endl;
237-
auto symbols = ParseSymbolOutput(*content, file);
244+
auto symbols = ParseSymbolOutput(*content, file, file_ext);
238245
clDEBUG() << "Parsing symbols...done" << endl;
239246

240247
clDEBUG() << "Sorting symbols..." << endl;

CodeLite/CTags.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,18 @@ class WXDLLIMPEXP_CL CTags
226226
*
227227
* @param content wxString The input text containing one JSON object per line.
228228
* @param filename wxString The file path to assign to each parsed symbol entry.
229-
*
229+
* @param file_ext wxString the filename extension.
230230
* @return std::vector<CTags::SymbolInfo> A vector of parsed symbol records, possibly empty if no valid entries are
231231
* found.
232232
*
233233
* @throws None. Any parsing or conversion errors are caught internally and the corresponding line is ignored.
234234
*/
235-
static std::vector<SymbolInfo> ParseSymbolOutput(const wxString& content, const wxString& filename);
236-
static std::optional<SymbolKind>
237-
MapSymbolKind(const wxString& kind, const wxString& scope, const wxString& kind_from_ctags);
235+
static std::vector<SymbolInfo>
236+
ParseSymbolOutput(const wxString& content, const wxString& filename, const wxString& file_ext);
237+
static std::optional<SymbolKind> MapSymbolKind(const wxString& kind,
238+
const wxString& scope,
239+
const wxString& kind_from_ctags,
240+
const wxString& file_ext);
238241
};
239242

240243
#endif // CTAGSGENERATOR_HPP

0 commit comments

Comments
 (0)