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

feat: add stop words / repository context support for C/C++ #744

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

Squadrick
Copy link
Contributor

@Squadrick Squadrick commented Nov 10, 2023

crates/tabby-common/assets/languages.toml Outdated Show resolved Hide resolved
crates/tabby-common/assets/languages.toml Outdated Show resolved Hide resolved
@Squadrick
Copy link
Contributor Author

@wsxiaoys The PRs to exposing TAGS_QUERY (above) have been merged, but there wasn't been a new release tag with those commits. I've raised a request for new tags with the maintainers of those repos. In the meanwhile, I can use cargo's rev property to pick the code, but imo, it's a bit ugly.

So instead of:

tree-sitter-c = "0.20.3"
tree-sitter-cpp = "0.20.3"

we'll have:

tree-sitter-c = { git = "https://github.com/tree-sitter/tree-sitter-c/", rev = "4add3bb" }
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "d153fe1" }

What do you think? Go with rev or wait for release tags?

@Squadrick Squadrick marked this pull request as ready for review November 16, 2023 23:24
@wsxiaoys
Copy link
Member

Go with rev is ok - but you might also considering simply embeds the query scm in https://github.com/TabbyML/tabby/tree/main/crates/tabby-scheduler/queries

Like what we did for go / tsx

@Squadrick
Copy link
Contributor Author

@wsxiaoys Since the queries were not modified, I went with the rev approach. If you would prefer that we stick to having the queries in-repo, let me know and I'll make that changes.

Squashed and pushed the final commit, can you please take a look?

@wsxiaoys
Copy link
Member

Could you add a few verification case (through screenshot) in treesitter's query playground" https://tree-sitter.github.io/tree-sitter/playground, like what we did in #813 (comment)

@Squadrick
Copy link
Contributor Author

@wsxiaoys Sorry about the delay, here's the verification for C++:

Source code:

struct A {
	int a;
    void method();
};
class B {
	void method();
};
void B::method() {}
union C {
  A a; B b;
};
void printTest(int a, std::string b) {}
typedef struct Person {
	std::string s;
} p;

Query:

(struct_specifier name: (type_identifier) @name body:(_)) @definition.class
(union_specifier name: (type_identifier) @name) @definition.class
(function_declarator declarator: (identifier) @name) @definition.function
(function_declarator declarator: (field_identifier) @name) @definition.function
(function_declarator declarator: (qualified_identifier scope: (namespace_identifier) @local.scope name: (identifier) @name)) @definition.method
(type_definition declarator: (type_identifier) @name) @definition.type
(enum_specifier name: (type_identifier) @name) @definition.type
(class_specifier name: (type_identifier) @name) @definition.class

Image:
Screenshot 2023-12-15 at 1 42 53 PM

@Squadrick
Copy link
Contributor Author

For C:

struct A {
	int a;
    void method();
};
void printTest(int a, std::string b) {}
typedef struct Person {
	std::string s;
} p;

Query:

(struct_specifier name: (type_identifier) @name body:(_)) @definition.class
(declaration type: (union_specifier name: (type_identifier) @name)) @definition.class
(function_declarator declarator: (identifier) @name) @definition.function
(type_definition declarator: (type_identifier) @name) @definition.type
(enum_specifier name: (type_identifier) @name) @definition.type

Image:
Screenshot 2023-12-15 at 1 45 57 PM

Copy link
Member

@wsxiaoys wsxiaoys left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM, thanks for the effort!

website/docs/programming-languages.md Show resolved Hide resolved
@wsxiaoys wsxiaoys changed the title Add support for C/C++ feat: add stop words / repository context support for C/C++ Dec 16, 2023
@Squadrick
Copy link
Contributor Author

Squadrick commented Dec 16, 2023

@wsxiaoys Done, should be good to merge now. Also squashed the commits since I had to change the author to my personal email. Should be good to go now. Thanks for the review.

@wsxiaoys wsxiaoys merged commit 5c4f8de into TabbyML:main Dec 16, 2023
3 checks passed
@Squadrick Squadrick deleted the c/cpp branch December 16, 2023 08:51
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.

2 participants