Skip to content

TypeSpec: new parser #4243

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

Merged
merged 1 commit into from
May 27, 2025
Merged

TypeSpec: new parser #4243

merged 1 commit into from
May 27, 2025

Conversation

iaalm
Copy link
Contributor

@iaalm iaalm commented May 8, 2025

Add parser for TypeSpec

Test passed with make units LANGUAGES=TypeSpec

Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 98.06452% with 6 lines in your changes missing coverage. Please review.

Project coverage is 85.95%. Comparing base (7dbc4db) to head (846da8d).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
parsers/typespec.c 98.06% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4243      +/-   ##
==========================================
+ Coverage   85.89%   85.95%   +0.05%     
==========================================
  Files         245      246       +1     
  Lines       63149    63459     +310     
==========================================
+ Hits        54240    54544     +304     
- Misses       8909     8915       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@iaalm iaalm changed the title TypeSpec: add parser TypeSpec: new parser May 8, 2025
@masatake masatake self-assigned this May 8, 2025
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.

Well written. Thank you.
Could you add the name of the new parser to docs/news/HEAD.rst?

I think we can simplify the code with "cork API",
See https://docs.ctags.io/en/latest/internal.html#cork-api

I will show you how to apply the CORK API to your parser in the next comment.

@masatake
Copy link
Member

masatake commented May 8, 2025

Let's use CORK API.
See the latest two commits at https://github.com/masatake/ctags/commits/tsp-20250509/ .

@masatake masatake added this to the 6.2 milestone May 8, 2025
@doc("API Versions")
enum Versions {
@doc("May 01, 2024 Preview API Version")
v2024_05_01_preview: "2024-05-01-preview",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we extract v2024_05_01_preview ?

NYY-choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have thinked about this. I can do in another PR. BTW, @masatake , could you suggest TypeSpecKinds for this type? I don't find much examples of such kind.

Copy link
Member

Choose a reason for hiding this comment

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

As far as reading https://typespec.io/docs/language-basics/enums/, the enum in TypeSpec is not so different from that in C. So we can reuse what the C parser defines.

$ ./ctags --list-kinds-full=C | grep enum
e       enumerator yes     no      0      C      enumerators (values inside an enumeration)
g       enum       yes     no      0      C      enumeration names

e,enumerator,enumerators (values inside an enumeration) looks suitable here.

Copy link
Member

Choose a reason for hiding this comment

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

We should refer to TypeScript instead of C.

$ ./ctags --list-kinds-full=TypeScript | grep enum
e       enumerator yes     no      0      NONE   enumerators (values inside an enumeration)
g       enum       yes     no      0      NONE   enums

TypeScript also uses g.

import "./common.tsp";

using TypeSpec;
using TypeSpec.Rest;
Copy link
Member

Choose a reason for hiding this comment

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

I'm interested in extracting imported items and usinged items.
I will work on them after merging this pull request.

#3906
#2428

ModelB<ModelA[]>
>;

interface InterfaceA extends InterfaceB {
Copy link
Member

Choose a reason for hiding this comment

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

We can fill inherits: field of interfaceA: with InterfaceB.
NYY-choice.

Filling such a field makes your work applicable to broader use cases.

Here is an example of C++.

$ cat /tmp/foo.cc 
class A: B {
	int x;
};
$ ./ctags -o - /tmp/foo.cc
A	/tmp/foo.cc	/^class A: B {$/;"	c	file:
x	/tmp/foo.cc	/^	int x;$/;"	m	class:A	typeref:typename:int	file:
$ ./ctags --fields=+i -o - /tmp/foo.cc
A	/tmp/foo.cc	/^class A: B {$/;"	c	file:	inherits:B
x	/tmp/foo.cc	/^	int x;$/;"	m	class:A	typeref:typename:int	file:
$ ./ctags --fields=+i -o foo.tags /tmp/foo.cc
$ ~/bin/querytags --tag-file foo.tags class-hierarchy  A
  A
   B

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can do it in another PR

{ true, 'u', "union", "unions" },
{ true, 'a', "alias", "aliases" },
{ true, 'p', "property", "properties" }
};
Copy link
Member

Choose a reason for hiding this comment

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

My reviewing log: These are good. They align with the kinds of TypeScript.

@masatake
Copy link
Member

Thank you for updating.

Could you add the name of the new parser to docs/news/HEAD.rst?

@masatake masatake modified the milestones: 6.2, 6.3 May 20, 2025
@iaalm iaalm changed the title TypeSpec: new parser [WIP]TypeSpec: new parser May 25, 2025
@iaalm iaalm force-pushed the tsp branch 3 times, most recently from a234d44 to a155321 Compare May 25, 2025 08:14
@iaalm iaalm changed the title [WIP]TypeSpec: new parser TypeSpec: new parser May 26, 2025
@masatake
Copy link
Member

Thank you for updating.

Could you add the name of the new parser to docs/news/HEAD.rst?
Please remove whitespace in input.tsp

image

@masatake masatake removed this from the 6.3 milestone May 27, 2025
@masatake masatake merged commit aafc653 into universal-ctags:master May 27, 2025
92 of 93 checks passed
@masatake
Copy link
Member

Thank you very much.

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

Successfully merging this pull request may close these issues.

2 participants