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

TypeScript: use CORK for scopes #2083

Merged
merged 3 commits into from
Apr 19, 2019

Conversation

ksamborski
Copy link
Member

I've changed manually handling scopes as strings in favor of CORK indexes. Parser code is now shorter and more clear. I've also introduced myself in developers.rst

@coveralls
Copy link

coveralls commented Apr 17, 2019

Coverage Status

Coverage increased (+0.009%) to 85.343% when pulling 4f105fb on ksamborski:typescript-cork into 46490ea on universal-ctags:master.

Copy link
Member

@masatake masatake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether the condition if (scope) is needed or not in a if (scope) dest->scope = foo.
If it is redundant, we should remove the condition.
Could you look at lines setting the scope field?

vStringCopy (methodScope, scope);
vStringPut (methodScope, '.');
vStringCat (methodScope, member->string);
const int nscope = isGenerator ? emitTag (member, TSTAG_GENERATOR) : emitTag (member, TSTAG_METHOD);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const int nscope = emitTag (member, (isGenerator? TSTAG_GENERATOR: TSTAG_METHOD));

reduces typings :-P

vStringCopy (token->scope, scope);
token->scopeParentKind = scopeParentKind;
}
if (scope != CORK_NIL) token->scope = scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the condtion?
I'm not sure but I think

token->scope = scope;

is o.k. even if scope == CORK_NIL.

vStringCopy (token->scope, scope);
token->scopeParentKind = scopeParentKind;
}
if (scope != CORK_NIL) token->scope = scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last comment may be applicable to this line, too.

vStringPut (nscope, '.');
}
vStringCat (nscope, token->string);
if (scope != CORK_NIL) token->scope = scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last comment is applicable to this line.

vStringCopy (member->scope, scope);
member->scopeParentKind = scopeParentKind;
}
if (scope != CORK_NIL) member->scope = scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last comment is applicable to this line.

vStringCopy (token->scope, scope);
token->scopeParentKind = scopeParentKind;
}
if (scope != CORK_NIL) token->scope = scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last comment is applicable to this line.

emitTag (token, TSTAG_GENERATOR);
else
emitTag (token, TSTAG_FUNCTION);
const int nscope = isGenerator ? emitTag (token, TSTAG_GENERATOR) : emitTag (token, TSTAG_FUNCTION);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be shorter with:

const int nscope = emitTag (token, isGenerator ? TSTAG_GENERATOR: TSTAG_FUNCTION);

.

vStringPut (nscope, '.');
}
vStringCat (nscope, token->string);
if (scope != CORK_NIL) token->scope = scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the condition?

@masatake
Copy link
Member

I would like to write about a little bit away from the topic of this pull request.

Did you try --extras=+q option?
It emits full qualified tags.

[jet@living]~/var/ctags% cat /tmp/foo.c
cat /tmp/foo.c
struct ponit {
  double x, y;
};
[jet@living]~/var/ctags% ./ctags -o - /tmp/foo.c
ponit	/tmp/foo.c	/^struct ponit {$/;"	s	file:
x	/tmp/foo.c	/^  double x, y;$/;"	m	struct:ponit	typeref:typename:double	file:
y	/tmp/foo.c	/^  double x, y;$/;"	m	struct:ponit	typeref:typename:double	file:
[jet@living]~/var/ctags% ./ctags --extras=+q -o - /tmp/foo.c
ponit	/tmp/foo.c	/^struct ponit {$/;"	s	file:
ponit::x	/tmp/foo.c	/^  double x, y;$/;"	m	struct:ponit	typeref:typename:double	file:
ponit::y	/tmp/foo.c	/^  double x, y;$/;"	m	struct:ponit	typeref:typename:double	file:
x	/tmp/foo.c	/^  double x, y;$/;"	m	struct:ponit	typeref:typename:double	file:
y	/tmp/foo.c	/^  double x, y;$/;"	m	struct:ponit	typeref:typename:double	file:

--extras=+q (fq tag) is one of popular feature vim users want.
I have not tried yet, however, your parser has not supported the fq tag.

By setting def->requestAutomaticFQTag = true; in TypeScriptParser(), the TypeScript parser can emit fq tag. requestAutomaticFQTag emits fq tags from scope information.

parsers/tcl.c has a bit complicated code about requestAutomaticFQTag.
It tries avoiding automatic FQ emission.
It sets a default separator that combines two names.

parsers/php.c doesn't use requestAutomaticFQTag.
But it tells how to customize separators in the kind definition of the parser.

@masatake
Copy link
Member

I made some minor comments. Other than them, It looks good to me.

@ksamborski
Copy link
Member Author

Thanks @masatake! I'll fix them.

@ksamborski
Copy link
Member Author

I think I've addressed all the issues as well as automatic fq tags. requestAutomaticFQTag is a fantastic option, thanks!

@masatake
Copy link
Member

Could you make 2fb367d and 710bf3e one commit?
Then do git push --force.

@ksamborski
Copy link
Member Author

@masatake Done. Is it now OK?

@masatake
Copy link
Member

Sorry, I have one more comment.
I think adding a test case for --extras=+q is better.

@ksamborski
Copy link
Member Author

I added ts-class-fq.d test case. Do you mean something else?

@masatake
Copy link
Member

Wow, sorry. I missed the test case.
Please, merge this PR after appveyor says o.k.

I will take asleep:-).

@ksamborski
Copy link
Member Author

OK, thanks!

@ksamborski ksamborski merged commit 54c1c2b into universal-ctags:master Apr 19, 2019
@ksamborski ksamborski deleted the typescript-cork branch April 19, 2019 06:41
@masatake
Copy link
Member

masatake commented Apr 19, 2019

Thank you.
You can find various interesting applications of CORK with grepping getEntryInCorkQueue ./parsers.

@masatake
Copy link
Member

No big perfomance degrading with introducing CORK:

(before introducing CORK)
[yamato@slave]~/var/codebase%  ./codebase ctags TypeScript
version: 4aed4f00
features: +wildcards +regex +iconv +option-directory +xpath +json +interactive +sandbox +yaml +aspell +packcc
log: results/4aed4f00,TypeScript..........,..........,time......,default...,2019-04-19-16:04:04.log
tagsoutput: /dev/null
cmdline: + u-ctags --quiet --options=NONE --sort=no --options=profile.d/maps --totals=yes --languages=TypeScript -o - -R code/nest code/tslint code/typescript
15421 files, 1319786 lines (29953 kB) scanned in 11.4 seconds (2618 kB/s)
145494 tags added to tag file

real	0m11.465s
user	0m11.252s
sys	0m0.189s
+ set +x

(after introducing CORK)
[yamato@slave]~/var/codebase%  ./codebase ctags TypeScript
version: 54c1c2b8
features: +wildcards +regex +iconv +option-directory +xpath +json +interactive +sandbox +yaml +aspell +packcc
log: results/54c1c2b8,TypeScript..........,..........,time......,default...,2019-04-19-16:04:50.log
tagsoutput: /dev/null
cmdline: + u-ctags --quiet --options=NONE --sort=no --options=profile.d/maps --totals=yes --languages=TypeScript -o - -R code/nest code/tslint code/typescript
15421 files, 1319786 lines (29953 kB) scanned in 11.5 seconds (2613 kB/s)
145494 tags added to tag file

real	0m11.491s
user	0m11.273s
sys	0m0.189s
+ set +x

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

Successfully merging this pull request may close these issues.

None yet

3 participants