-
Notifications
You must be signed in to change notification settings - Fork 7
✨ Add TypeScript and JavaScript comment type support (issue #69) #82
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
d569bff
61468bf
4e9ef51
4d85094
28e12e1
5e7d48b
b36c271
5fbc0e7
089816f
6b726c6
852e50c
0330c0b
2ceb5b4
279c935
41fb7a9
0cc642d
4ba26b7
22322cf
f16b61c
45d6d1e
90ca459
dd7554c
2da4c49
de4dfda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,13 @@ | |
| # @C and C++ Scope Node Types, IMPL_C_2, impl, [FE_C_SUPPORT, FE_CPP] | ||
| CommentType.cpp: {"function_definition", "class_definition"}, | ||
| CommentType.cs: {"method_declaration", "class_declaration", "property_declaration"}, | ||
| CommentType.ts: { | ||
|
ubmarco marked this conversation as resolved.
|
||
| "function_declaration", | ||
| "class_declaration", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class-field arrow functions resolve to the enclosing class instead of the field.
class A {
// @m
handler = () => {};
}
|
||
| "method_definition", | ||
| "lexical_declaration", | ||
|
ubmarco marked this conversation as resolved.
|
||
| "variable_declaration", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JavaScript's dominant function-definition forms are not scope types, so markers on them mis-associate — and The scope set covers only ES declaration syntax. Assignment-based definitions — the norm in CommonJS, which is precisely what // @m
module.exports = function f(){};
function unrelated(){} // -> tagged_scope = "function unrelated(){}"
// @m
Foo.prototype.bar = function(){};
function unrelated(){} // -> tagged_scope = "function unrelated(){}"Anonymous default exports (the standard shape for React/Next.js page modules) get no scope at all: // @m
export default () => {}; // -> tagged_scope = None
// @m
export default function () {}; // -> tagged_scope = NoneWidening |
||
| }, | ||
| # @Rust Scope Node Types, IMPL_RUST_2, impl, [FE_RUST]; | ||
| CommentType.rust: { | ||
| "function_item", | ||
|
|
@@ -64,6 +71,7 @@ | |
| """ | ||
| CPP_QUERY = """(comment) @comment""" | ||
| C_SHARP_QUERY = """(comment) @comment""" | ||
| TYPE_SCRIPT_QUERY = """(comment) @comment""" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sixth verbatim copy of the same query string.
Relatedly, the |
||
| YAML_QUERY = """(comment) @comment""" | ||
| RUST_QUERY = """ | ||
| (line_comment) @comment | ||
|
|
@@ -120,6 +128,11 @@ def init_tree_sitter(comment_type: CommentType) -> tuple[Parser, Query]: | |
|
|
||
| parsed_language = Language(tree_sitter_c_sharp.language()) | ||
| query = Query(parsed_language, C_SHARP_QUERY) | ||
| elif comment_type == CommentType.ts: | ||
| import tree_sitter_typescript # noqa: PLC0415 | ||
|
|
||
| parsed_language = Language(tree_sitter_typescript.language_typescript()) | ||
|
ubmarco marked this conversation as resolved.
Outdated
|
||
| query = Query(parsed_language, TYPE_SCRIPT_QUERY) | ||
| elif comment_type == CommentType.yaml: | ||
| import tree_sitter_yaml # noqa: PLC0415 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||
| // regular comment | ||||||
| function testA() { | ||||||
| // @type,TS_REQ_002,TypeScript one-line test | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This marker is in the wrong field order for the default one-line style, so the new integration test asserts on a garbage need.
{'title': 'type', 'id': 'TS_REQ_002', 'type': 'TypeScript one-line test', 'links': []}(actual output from running
Suggested change
…and the |
||||||
| return 1; | ||||||
| } | ||||||
|
|
||||||
| /* regular block comment */ | ||||||
| const testB = () => { | ||||||
| return 2; | ||||||
| }; | ||||||
|
|
||||||
| // another comment | ||||||
| class Demo { | ||||||
| methodA() { | ||||||
| return 3; | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heading deviates from the established convention.
Every prior pre-release cycle in this file used
Unreleased— e.g. atadf35ccthe in-progress section was:Unreleased ----------The PR description also says the entry was added "under
Upcoming", so the actual heading matches neither. SuggestUnreleasedfor consistency with the release tooling and history.