JavaScript: don't split a string token into words when tagging
This one is derrived from https://github.com/universal-ctags/ctags/pull/3363#discussion_r1594584760 .
The name of the parser: JavaScript
The command line you used to run ctags:
$ ./ctags --options=NONE --excmd=combine --sort=no --fields=rZKs --extras=+r -o - baz.js
The content of input file:
class T4 {
"r4.i4" = 42
"r4.f4"() { return 43; }
}
let t = new T4
console.log(t['r4.i4']);
console.log(t['r4.f4']());
The tags output you are not satisfied with:
T4 baz.js 1;/^class T4 {$/;" class roles:def
i4 baz.js 2;/^ "r4.i4" = 42$/;" field scope:class:T4.r4 roles:def
f4 baz.js 3;/^ "r4.f4"() { return 43; }$/;" method scope:class:T4.r4 roles:def
The tags output you expect:
T4 baz.js 1;/^class T4 {$/;" class roles:def
r4.i4 baz.js 2;/^ "r4.i4" = 42$/;" field scope:class:T4.r4 roles:def
r4.f4 baz.js 3;/^ "r4.f4"() { return 43; }$/;" method scope:class:T4.r4 roles:def
The version of ctags:
Universal Ctags 6.1.0(adcea47e3), Copyright (C) 2015-2023 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: May 8 2024, 23:15:34
URL: https://ctags.io/
Output version: 0.0
Optional compiled features: +wildcards, +regex, +iconv, +debug, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript, +pcre2
How do you get ctags binary:
git clone
diff --git a/parsers/jscript.c b/parsers/jscript.c
index 7762c6273..e2430357d 100644
--- a/parsers/jscript.c
+++ b/parsers/jscript.c
@@ -485,7 +485,7 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
const char *p;
char *name_chain = NULL;
- if (!token->dynamicProp && kind != JSTAG_PROPERTY && (p = strrchr (name, '.')) != NULL )
+ if (!token->dynamicProp && !isType (token, TOKEN_STRING) && (p = strrchr (name, '.')) != NULL )
{
if ((p - name) != 0)
name_chain = eStrndup (name, (size_t) (p - name));
This is one of the ways to fix this issue.
Another one is:
diff --git a/parsers/jscript.c b/parsers/jscript.c
index 7762c6273..8605ef8f7 100644
--- a/parsers/jscript.c
+++ b/parsers/jscript.c
@@ -485,7 +485,7 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,
const char *p;
char *name_chain = NULL;
- if (!token->dynamicProp && kind != JSTAG_PROPERTY && (p = strrchr (name, '.')) != NULL )
+ if (!token->dynamicProp && kind != JSTAG_PROPERTY && kind != JSTAG_FIELD && kind != JSTAG_METHOD && (p = strrchr (name, '.')) != NULL )
{
if ((p - name) != 0)
name_chain = eStrndup (name, (size_t) (p - name));
Setting dynamicProp of the token for tagging in the context where makeJsTagCommon calls is yet another way.
I'd think the best solution would be marking it a dynamic property, but checking the token type seems a reasonable enough trick. Fussing around with the kind is however a bad idea IMO, as it will make it harder to handle the other issue where some tags aren't split properly -- and kind has sementically little to do with what the tag name should be.
Fussing around with the kind is however a bad idea IMO
I agree with you. Many confusions come from "Fussing around with the kind". I expect introducing "unknown" kind may be able to reduce "Fussing around with the kind" code. Instead of writing and/or maintaining "Fussing around with the kind" code for guessing a kind for a tag, we can just assign "unknown" to the tag. Eventually, we need the "unknown" kind when the parser deals with "import."
Generally, a parser should maintain compatibility with its kinds, fields, extras, and roles. However, now that we have a "versioning mechanism" in parsers, we can change these drastically if we really want.