Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript: don't split a string token into words when tagging #3995

Open
masatake opened this issue May 9, 2024 · 4 comments
Open

JavaScript: don't split a string token into words when tagging #3995

masatake opened this issue May 9, 2024 · 4 comments
Assignees

Comments

@masatake
Copy link
Member

masatake commented May 9, 2024

This one is derrived from #3363 (comment) .

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

@jafl jafl self-assigned this May 9, 2024
@masatake
Copy link
Member Author

masatake commented May 9, 2024

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));

@masatake
Copy link
Member Author

masatake commented May 9, 2024

Setting dynamicProp of the token for tagging in the context where makeJsTagCommon calls is yet another way.

@b4n
Copy link
Member

b4n commented May 10, 2024

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.

@masatake
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants