diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/queries/c/scip-tags.scm b/docker-images/syntax-highlighter/crates/scip-syntax/queries/c/scip-tags.scm index d6a64365b12fe..5ea8b30d65e36 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/queries/c/scip-tags.scm +++ b/docker-images/syntax-highlighter/crates/scip-syntax/queries/c/scip-tags.scm @@ -1,11 +1,56 @@ ; Make use of @local -(translation_unit (declaration (init_declarator declarator: (_) @descriptor.term))) +(function_definition body: (_) @local) -(enum_specifier name: (_) @descriptor.type body: (enumerator_list (enumerator name: (_) @descriptor.term)) @descriptor.scope) +(parameter_list) @local -(field_declaration declarator: [ - (pointer_declarator (field_identifier) @descriptor.term) - (field_identifier) @descriptor.term -]) -(function_definition (function_declarator declarator: (_) @descriptor.method)) +(function_declarator declarator: (_) @descriptor.method @kind.function) + +(pointer_declarator declarator: ((identifier) @descriptor.term @kind.variable)) + +(init_declarator + declarator: (identifier) @descriptor.term @kind.variable + value: (_)) + +(array_declarator + declarator: (identifier) @descriptor.term @kind.variable + size: (_)) + +(declaration + (type_qualifier)? + declarator: ((identifier) @descriptor.term @kind.variable)) + +;; Enums +(enum_specifier + name: (_)? + body: (enumerator_list + (enumerator name: (_) @descriptor.term @kind.enummember))) ;; <-- capture enum kind + +(enum_specifier + name: (type_identifier) @descriptor.type @kind.enum ;; <-- capture enum kind + body: (_)) + +;; fields (inside structs, or unions, ...) +(field_declaration_list + (field_declaration declarator: [ + (pointer_declarator (field_identifier) @descriptor.term @kind.field) + (field_identifier) @descriptor.term @kind.field])) + +;; structs +(struct_specifier + name: (type_identifier) @descriptor.type @kind.struct ;; <-- capture struct kidn + body: (_)) @scope + +;; typedefs +(type_definition + type: (_) + declarator: (type_identifier) @descriptor.term @kind.typealias) + +;; macros +(preproc_def + name: (identifier) @descriptor.term @kind.macro) + +;; union +(union_specifier + name: (type_identifier) @descriptor.type @kind.union + body: (_)) @scope diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/lib.rs b/docker-images/syntax-highlighter/crates/scip-syntax/src/lib.rs index 3ec1f58435106..96c6d1a94bc55 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/lib.rs +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/lib.rs @@ -115,6 +115,8 @@ mod test { generate_tags_and_snapshot!(Scip, test_scip_javascript, "globals.js"); generate_tags_and_snapshot!(Scip, test_scip_javascript_object, "javascript-object.js"); + generate_tags_and_snapshot!(All, test_tags_c_example, test_scip_c_example, "example.c"); + // Test to make sure that kinds are the override behavior generate_tags_and_snapshot!(All, test_tags_go_diff, test_scip_go_diff, "go-diff.go"); generate_tags_and_snapshot!( diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ctags-empty-scope.rs.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ctags-empty-scope.rs.snap index f7b6281e7041d..71d2e981477aa 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ctags-empty-scope.rs.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ctags-empty-scope.rs.snap @@ -10,7 +10,7 @@ expression: dumped use walkdir::WalkDir; static LANGUAGE: &str = "Rust"; -// ^^^^^^^^ definition scip-ctags LANGUAGE. +// ^^^^^^^^ definition(Variable) scip-ctags LANGUAGE. const THRESHOLD: i32 = 10; // ^^^^^^^^^ definition(Constant) scip-ctags THRESHOLD. diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_example.c.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_example.c.snap new file mode 100644 index 0000000000000..9e80d2a4ccc6a --- /dev/null +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_example.c.snap @@ -0,0 +1,190 @@ +--- +source: crates/scip-syntax/src/lib.rs +expression: dumped +--- + #include + #include + + #define BUFSIZE 4096 +// ^^^^^^^ definition(Macro) scip-ctags BUFSIZE. + + const char *name = "com.horsegraph.connection"; +// ^^^^ definition(Variable) scip-ctags name. + const char *author = "Petri & Thorsten"; +// ^^^^^^ definition(Variable) scip-ctags author. + const int count; +// ^^^^^ definition(Variable) scip-ctags count. + int count2; +// ^^^^^^ definition(Variable) scip-ctags count2. + const int age = 28; +// ^^^ definition(Field) scip-ctags age. + static uint sweet_sweet_numbers[5] = {23, 420, 69, 42, 7}; +// ^^^^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags sweet_sweet_numbers. + + const int *ptr1 = &count; +// ^^^^ definition(Variable) scip-ctags ptr1. + const int **ptrptr1 = &ptr1; +// ^^^^^^^ definition(Variable) scip-ctags ptrptr1. + const int ***ptrptrptr1 = &ptrptr1; +// ^^^^^^^^^^ definition(Variable) scip-ctags ptrptrptr1. + + enum { BLACK, RED }; +// ^^^^^ definition(EnumMember) scip-ctags BLACK. +// ^^^ definition(EnumMember) scip-ctags RED. + + enum animal { +// ^^^^^^ definition(Enum) scip-ctags animal# + ANIMAL_TOUCAN, +// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_TOUCAN. + ANIMAL_TIGER = 1, +// ^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_TIGER. + ANIMAL_TIGGER = ANIMAL_TIGER, +// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_TIGGER. + ANIMAL_HORSE, +// ^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_HORSE. + ANIMAL_GIRAFFE, +// ^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_GIRAFFE. + ANIMAL_GOPHER = 99, +// ^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_GOPHER. + ANIMAL_ORANGUTAN +// ^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags ANIMAL_ORANGUTAN. + }; + + typedef enum instrument { +// ^^^^^^^^^^ definition(Enum) scip-ctags instrument# + INSTRUMENT_GUITAR, +// ^^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags INSTRUMENT_GUITAR. + INSTRUMENT_KEYTAR, +// ^^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags INSTRUMENT_KEYTAR. + INSTRUMENT_SITAR +// ^^^^^^^^^^^^^^^^ definition(EnumMember) scip-ctags INSTRUMENT_SITAR. + } Instrument; +// ^^^^^^^^^^ definition(TypeAlias) scip-ctags Instrument. + + union { + char *hobby; +// ^^^^^ definition(Field) scip-ctags hobby. + int age; // <-- TODO: this will be tagged as a Constant because it's the same +// ^^^ definition(Field) scip-ctags age. + // symbol as the `const int age` above. + } person; +// ^^^^^^ definition(Variable) scip-ctags person. + + union object { +// ^^^^^^ definition(Union) scip-ctags object# + char *name; +// ^^^^ definition(Field) scip-ctags object#name. + int value; +// ^^^^^ definition(Field) scip-ctags object#value. + int age; +// ^^^ definition(Field) scip-ctags object#age. + } obj1, obj2, *obj3; +// ^^^^ definition(Variable) scip-ctags obj1. +// ^^^^ definition(Variable) scip-ctags obj2. +// ^^^^ definition(Variable) scip-ctags obj3. + + const union object2 { +// ^^^^^^^ definition(Union) scip-ctags object2# + char name; +// ^^^^ definition(Field) scip-ctags object2#name. + } obj4; +// ^^^^ definition(Variable) scip-ctags obj4. + + struct connection { +// ^^^^^^^^^^ definition(Struct) scip-ctags connection# + int complete; +// ^^^^^^^^ definition(Field) scip-ctags connection#complete. + int fd; +// ^^ definition(Field) scip-ctags connection#fd. + int bufsize; +// ^^^^^^^ definition(Field) scip-ctags connection#bufsize. + char *buffer; +// ^^^^^^ definition(Field) scip-ctags connection#buffer. + char *url; +// ^^^ definition(Field) scip-ctags connection#url. + }; + + typedef struct connection Connection; +// ^^^^^^^^^^ definition(TypeAlias) scip-ctags Connection. + + typedef struct computer { +// ^^^^^^^^ definition(Struct) scip-ctags computer# + int cores; +// ^^^^^ definition(Field) scip-ctags computer#cores. + } Computer; +// ^^^^^^^^ definition(TypeAlias) scip-ctags Computer. + + typedef struct { + int number; +// ^^^^^^ definition(Field) scip-ctags number. + } NoName; +// ^^^^^^ definition(TypeAlias) scip-ctags NoName. + + struct outer { +// ^^^^^ definition(Struct) scip-ctags outer# + struct inner { +// ^^^^^ definition(Struct) scip-ctags outer#inner# + int x; +// ^ definition(Field) scip-ctags outer#inner#x. + int y; +// ^ definition(Field) scip-ctags outer#inner#y. + } b; +// ^ definition(Field) scip-ctags outer#b. + }; + + // Prototype + struct connection *new_connection(int fd); +// ^^^^^^^^^^^^^^ definition(Function) scip-ctags new_connection(). + // Implementation + struct connection *new_connection(int fd) { +// ^^^^^^^^^^^^^^ definition(Function) scip-ctags new_connection(). + struct connection *c = malloc(sizeof(struct connection)); + if (c == NULL) { + return NULL; + } + + c->url = NULL; + c->complete = 0; + c->fd = fd; + + c->buffer = calloc(BUFSIZE, sizeof(char)); + if (c->buffer == NULL) { + free(c); + return NULL; + } + c->bufsize = BUFSIZE; + + return c; + } + + static void free_connection(struct connection *c) { +// ^^^^^^^^^^^^^^^ definition(Function) scip-ctags free_connection(). + if (c->buffer) { + free(c->buffer); + } + + if (c->url) { + free(c->url); + } + + free(c); + } + + // Prototype + int returns_int(); +// ^^^^^^^^^^^ definition(Function) scip-ctags returns_int(). + // Implementation + int returns_int() { return 12; } +// ^^^^^^^^^^^ definition(Function) scip-ctags returns_int(). + + int main() { return 0; } +// ^^^^ definition(Function) scip-ctags main(). + + int k_and_r(s, f) +// ^^^^^^^ definition(Function) scip-ctags k_and_r(). + char *s; +// ^ definition(Variable) scip-ctags s. + float f; +// ^ definition(Variable) scip-ctags f. + { return 5; } + diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.js.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.js.snap index 171fc11aee65e..58608d4a7ce09 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.js.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.js.snap @@ -4,15 +4,15 @@ expression: dumped --- // Traditional variable declaration var traditionalVar = "Hello, I'm an old-style variable"; -// ^^^^^^^^^^^^^^ definition scip-ctags traditionalVar. +// ^^^^^^^^^^^^^^ definition(Variable) scip-ctags traditionalVar. // Let variable declaration let scopedLetVar = "Hello, I'm a block-scoped variable"; -// ^^^^^^^^^^^^ definition scip-ctags scopedLetVar. +// ^^^^^^^^^^^^ definition(Variable) scip-ctags scopedLetVar. // Constant variable declaration const constantVar = "Hello, I'm a constant variable"; -// ^^^^^^^^^^^ definition scip-ctags constantVar. +// ^^^^^^^^^^^ definition(Variable) scip-ctags constantVar. // Function declaration function functionDeclaration() { @@ -22,13 +22,13 @@ expression: dumped // Anonymous function declaration var anonymousFunction = function() { -// ^^^^^^^^^^^^^^^^^ definition scip-ctags anonymousFunction. +// ^^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags anonymousFunction. return "Hello, I'm an anonymous function"; }; // ES6 arrow function declaration const arrowFunction = () => { -// ^^^^^^^^^^^^^ definition scip-ctags arrowFunction. +// ^^^^^^^^^^^^^ definition(Variable) scip-ctags arrowFunction. return "Hello, I'm an arrow function"; }; @@ -43,7 +43,7 @@ expression: dumped // Object declaration var objectDeclaration = { -// ^^^^^^^^^^^^^^^^^ definition scip-ctags objectDeclaration. +// ^^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags objectDeclaration. message: "Hello, I'm an object declaration" // ^^^^^^^ definition(Property) scip-ctags objectDeclaration.message. }; @@ -54,11 +54,11 @@ expression: dumped this.message = "Hello, I'm an object constructor"; } var objectConstructed = new ObjectConstructor(); -// ^^^^^^^^^^^^^^^^^ definition scip-ctags objectConstructed. +// ^^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags objectConstructed. // ES6 method shorthand in object declaration var objectWithMethods = { -// ^^^^^^^^^^^^^^^^^ definition scip-ctags objectWithMethods. +// ^^^^^^^^^^^^^^^^^ definition(Variable) scip-ctags objectWithMethods. method() { return "Hello, I'm a method in an object"; } diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.py.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.py.snap index 95269707bb23d..7119a820f712c 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.py.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.py.snap @@ -5,12 +5,12 @@ expression: dumped # TODO: Deal with duplicates (bruh = 10; bruh = 10;) being marked as definitions bruh = 10 -//^^^^ definition scip-ctags bruh. +//^^^^ definition(Variable) scip-ctags bruh. class Bruh(object): // ^^^^ definition(Class) scip-ctags Bruh# a: int -// ^ definition scip-ctags Bruh#a. +// ^ definition(Variable) scip-ctags Bruh#a. def __init__(self) -> None: // ^^^^^^^^ definition(Method) scip-ctags Bruh#__init__(). @@ -26,7 +26,7 @@ expression: dumped if 1 == 1: should_show_ifs = False -// ^^^^^^^^^^^^^^^ definition scip-ctags should_show_ifs. +// ^^^^^^^^^^^^^^^ definition(Variable) scip-ctags should_show_ifs. # Don't show from whiles / fors while False: @@ -98,12 +98,12 @@ expression: dumped foo, bar, baz = 1, 2, 3 -//^^^ definition scip-ctags foo. -// ^^^ definition scip-ctags bar. -// ^^^ definition scip-ctags baz. +//^^^ definition(Variable) scip-ctags foo. +// ^^^ definition(Variable) scip-ctags bar. +// ^^^ definition(Variable) scip-ctags baz. # semi-colons haha foo = 1; bar = foo -//^^^ definition scip-ctags foo. -// ^^^ definition scip-ctags bar. +//^^^ definition(Variable) scip-ctags foo. +// ^^^ definition(Variable) scip-ctags bar. diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.ts.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.ts.snap index d0d4508e244ea..287e2beab2d39 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.ts.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_globals.ts.snap @@ -38,9 +38,9 @@ expression: dumped } var global1 = 0; -// ^^^^^^^ definition scip-ctags global1. +// ^^^^^^^ definition(Variable) scip-ctags global1. var global2; -// ^^^^^^^ definition scip-ctags global2. +// ^^^^^^^ definition(Variable) scip-ctags global2. function func() { // ^^^^ definition(Function) scip-ctags func(). @@ -54,7 +54,7 @@ expression: dumped } var myObject = { -// ^^^^^^^^ definition scip-ctags myObject. +// ^^^^^^^^ definition(Variable) scip-ctags myObject. myProperty: "value", // ^^^^^^^^^^ definition(Property) scip-ctags myObject.myProperty. diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-diff.go.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-diff.go.snap index db86016a8fe15..c49427c2ea55b 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-diff.go.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-diff.go.snap @@ -22,9 +22,9 @@ expression: dumped var ( diffPath = flag.String("f", stdin, "filename of diff (default: stdin)") -// ^^^^^^^^ definition scip-ctags main/diffPath. +// ^^^^^^^^ definition(Variable) scip-ctags main/diffPath. fileIdx = flag.Int("i", -1, "if >= 0, only print and report errors from the i'th file (0-indexed)") -// ^^^^^^^ definition scip-ctags main/fileIdx. +// ^^^^^^^ definition(Variable) scip-ctags main/fileIdx. ) func main() { diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-globals.go.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-globals.go.snap index 1528ae65bc085..b50bea20c1499 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-globals.go.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_go-globals.go.snap @@ -74,9 +74,9 @@ expression: dumped var ( diffPath = flag.String("f", stdin, "filename of diff (default: stdin)") -// ^^^^^^^^ definition scip-ctags multierror/diffPath. +// ^^^^^^^^ definition(Variable) scip-ctags multierror/diffPath. fileIdx = flag.Int("i", -1, "if >= 0, only print and report errors from the i'th file (0-indexed)") -// ^^^^^^^ definition scip-ctags multierror/fileIdx. +// ^^^^^^^ definition(Variable) scip-ctags multierror/fileIdx. ) func RegularFunc() {} diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_javascript-object.js.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_javascript-object.js.snap index 62423a82f9b6c..b7e22e4ad1730 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_javascript-object.js.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_javascript-object.js.snap @@ -3,7 +3,7 @@ source: crates/scip-syntax/src/lib.rs expression: dumped --- var myObject = { -// ^^^^^^^^ definition scip-ctags myObject. +// ^^^^^^^^ definition(Variable) scip-ctags myObject. myProperty: "value", // ^^^^^^^^^^ definition(Property) scip-ctags myObject.myProperty. diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_python-repo-comp.py.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_python-repo-comp.py.snap index 9272417790127..8fe19d6568f45 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_python-repo-comp.py.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_python-repo-comp.py.snap @@ -29,10 +29,10 @@ expression: dumped # sock is literally the socket that is used to communicate with the remote # collector. sock = None -// ^^^^ definition scip-ctags RemoteCollector#sock. +// ^^^^ definition(Variable) scip-ctags RemoteCollector#sock. _debug = False -// ^^^^^^ definition scip-ctags RemoteCollector#_debug. +// ^^^^^^ definition(Variable) scip-ctags RemoteCollector#_debug. def __init__(self, sock=None, debug=False): // ^^^^^^^^ definition(Method) scip-ctags RemoteCollector#__init__(). diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ruby-globals.rb.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ruby-globals.rb.snap index 32f7e79273c3d..09ec1b28f5baa 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ruby-globals.rb.snap +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__scip_snapshot_ruby-globals.rb.snap @@ -22,7 +22,7 @@ expression: dumped end counter = 1 -//^^^^^^^ definition scip-ctags counter. +//^^^^^^^ definition(Variable) scip-ctags counter. while counter <= 5 do no = true counter += 1 @@ -41,7 +41,7 @@ expression: dumped end grade = 42 -//^^^^^ definition scip-ctags grade. +//^^^^^ definition(Variable) scip-ctags grade. case grade when 0.100 shouldntgetcaptured = true diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__tags_snapshot_example.c.snap b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__tags_snapshot_example.c.snap new file mode 100644 index 0000000000000..b8bb6511cd5f6 --- /dev/null +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/snapshots/scip_syntax__test__tags_snapshot_example.c.snap @@ -0,0 +1,63 @@ +--- +source: crates/scip-syntax/src/lib.rs +expression: "String::from_utf8_lossy(buf_writer.buffer())" +--- +{"_type":"tag","name":"age","path":"example.c","language":"c","line":31,"kind":"field","scope":null} +{"_type":"tag","name":"hobby","path":"example.c","language":"c","line":31,"kind":"field","scope":"age"} +{"_type":"tag","name":"object.age","path":"example.c","language":"c","line":37,"kind":"field","scope":null} +{"_type":"tag","name":"object.value","path":"example.c","language":"c","line":37,"kind":"field","scope":"object.age"} +{"_type":"tag","name":"object.name","path":"example.c","language":"c","line":37,"kind":"field","scope":"object.age.object.value"} +{"_type":"tag","name":"object2.name","path":"example.c","language":"c","line":43,"kind":"field","scope":null} +{"_type":"tag","name":"connection.url","path":"example.c","language":"c","line":47,"kind":"field","scope":null} +{"_type":"tag","name":"connection.buffer","path":"example.c","language":"c","line":47,"kind":"field","scope":"connection.url"} +{"_type":"tag","name":"connection.bufsize","path":"example.c","language":"c","line":47,"kind":"field","scope":"connection.url.connection.buffer"} +{"_type":"tag","name":"connection.fd","path":"example.c","language":"c","line":47,"kind":"field","scope":"connection.url.connection.buffer.connection.bufsize"} +{"_type":"tag","name":"connection.complete","path":"example.c","language":"c","line":47,"kind":"field","scope":"connection.url.connection.buffer.connection.bufsize.connection.fd"} +{"_type":"tag","name":"computer.cores","path":"example.c","language":"c","line":57,"kind":"field","scope":null} +{"_type":"tag","name":"number","path":"example.c","language":"c","line":61,"kind":"field","scope":null} +{"_type":"tag","name":"hasNestedStruct.b","path":"example.c","language":"c","line":65,"kind":"field","scope":null} +{"_type":"tag","name":"isNestedStruct.y","path":"example.c","language":"c","line":66,"kind":"field","scope":"hasNestedStruct.b"} +{"_type":"tag","name":"isNestedStruct.x","path":"example.c","language":"c","line":66,"kind":"field","scope":"hasNestedStruct.b.isNestedStruct.y"} +{"_type":"tag","name":"isNestedStruct","path":"example.c","language":"c","line":66,"kind":"struct","scope":"hasNestedStruct.b"} +{"_type":"tag","name":"main","path":"example.c","language":"c","line":112,"kind":"function","scope":null} +{"_type":"tag","name":"returns_int","path":"example.c","language":"c","line":110,"kind":"function","scope":null} +{"_type":"tag","name":"returns_int","path":"example.c","language":"c","line":108,"kind":"function","scope":null} +{"_type":"tag","name":"free_connection","path":"example.c","language":"c","line":95,"kind":"function","scope":null} +{"_type":"tag","name":"new_connection","path":"example.c","language":"c","line":75,"kind":"function","scope":null} +{"_type":"tag","name":"new_connection","path":"example.c","language":"c","line":73,"kind":"function","scope":null} +{"_type":"tag","name":"hasNestedStruct","path":"example.c","language":"c","line":65,"kind":"struct","scope":null} +{"_type":"tag","name":"NoName","path":"example.c","language":"c","line":63,"kind":"typeAlias","scope":null} +{"_type":"tag","name":"Computer","path":"example.c","language":"c","line":59,"kind":"typeAlias","scope":null} +{"_type":"tag","name":"computer","path":"example.c","language":"c","line":57,"kind":"struct","scope":null} +{"_type":"tag","name":"Connection","path":"example.c","language":"c","line":55,"kind":"typeAlias","scope":null} +{"_type":"tag","name":"connection","path":"example.c","language":"c","line":47,"kind":"struct","scope":null} +{"_type":"tag","name":"obj4","path":"example.c","language":"c","line":45,"kind":"constant","scope":null} +{"_type":"tag","name":"object2","path":"example.c","language":"c","line":43,"kind":"union","scope":null} +{"_type":"tag","name":"obj3","path":"example.c","language":"c","line":41,"kind":"variable","scope":null} +{"_type":"tag","name":"obj2","path":"example.c","language":"c","line":41,"kind":"variable","scope":null} +{"_type":"tag","name":"obj1","path":"example.c","language":"c","line":41,"kind":"variable","scope":null} +{"_type":"tag","name":"object","path":"example.c","language":"c","line":37,"kind":"union","scope":null} +{"_type":"tag","name":"person","path":"example.c","language":"c","line":35,"kind":"variable","scope":null} +{"_type":"tag","name":"Instrument","path":"example.c","language":"c","line":29,"kind":"typeAlias","scope":null} +{"_type":"tag","name":"INSTRUMENT_SITAR","path":"example.c","language":"c","line":28,"kind":"enumMember","scope":null} +{"_type":"tag","name":"INSTRUMENT_KEYTAR","path":"example.c","language":"c","line":27,"kind":"enumMember","scope":null} +{"_type":"tag","name":"INSTRUMENT_GUITAR","path":"example.c","language":"c","line":26,"kind":"enumMember","scope":null} +{"_type":"tag","name":"instrument","path":"example.c","language":"c","line":25,"kind":"enum","scope":null} +{"_type":"tag","name":"ANIMAL_ORANGUTAN","path":"example.c","language":"c","line":22,"kind":"enumMember","scope":null} +{"_type":"tag","name":"ANIMAL_GOPHER","path":"example.c","language":"c","line":21,"kind":"enumMember","scope":null} +{"_type":"tag","name":"ANIMAL_GIRAFFE","path":"example.c","language":"c","line":20,"kind":"enumMember","scope":null} +{"_type":"tag","name":"ANIMAL_HORSE","path":"example.c","language":"c","line":19,"kind":"enumMember","scope":null} +{"_type":"tag","name":"ANIMAL_TIGGER","path":"example.c","language":"c","line":18,"kind":"enumMember","scope":null} +{"_type":"tag","name":"ANIMAL_TIGER","path":"example.c","language":"c","line":17,"kind":"enumMember","scope":null} +{"_type":"tag","name":"ANIMAL_TOUCAN","path":"example.c","language":"c","line":16,"kind":"enumMember","scope":null} +{"_type":"tag","name":"animal","path":"example.c","language":"c","line":15,"kind":"enum","scope":null} +{"_type":"tag","name":"RED","path":"example.c","language":"c","line":13,"kind":"enumMember","scope":null} +{"_type":"tag","name":"BLACK","path":"example.c","language":"c","line":13,"kind":"enumMember","scope":null} +{"_type":"tag","name":"sweet_sweet_numbers","path":"example.c","language":"c","line":11,"kind":"variable","scope":null} +{"_type":"tag","name":"age","path":"example.c","language":"c","line":10,"kind":"constant","scope":null} +{"_type":"tag","name":"count2","path":"example.c","language":"c","line":9,"kind":"variable","scope":null} +{"_type":"tag","name":"count","path":"example.c","language":"c","line":8,"kind":"constant","scope":null} +{"_type":"tag","name":"author","path":"example.c","language":"c","line":7,"kind":"constant","scope":null} +{"_type":"tag","name":"name","path":"example.c","language":"c","line":6,"kind":"constant","scope":null} +{"_type":"tag","name":"BUFSIZE","path":"example.c","language":"c","line":4,"kind":"macro","scope":null} + diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/ts_scip.rs b/docker-images/syntax-highlighter/crates/scip-syntax/src/ts_scip.rs index ba4c7f4e3caea..332f92e620222 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/ts_scip.rs +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/ts_scip.rs @@ -33,6 +33,7 @@ pub fn captures_to_kind(kind: &Option<&String>) -> symbol_information::Kind { "kind.function" => Function, "kind.getter" => Getter, "kind.interface" => Interface, + "kind.macro" => Macro, "kind.method" => Method, "kind.methodalias" => MethodAlias, "kind.methodspec" => MethodSpecification, @@ -46,6 +47,8 @@ pub fn captures_to_kind(kind: &Option<&String>) -> symbol_information::Kind { "kind.struct" => Struct, "kind.typealias" => TypeAlias, "kind.trait" => Trait, + "kind.union" => Union, + "kind.variable" => Variable, // "kind.implementation" => Implementation, TODO _ => UnspecifiedKind, }) @@ -67,6 +70,7 @@ pub fn symbol_kind_to_ctags_kind(kind: &symbol_information::Kind) -> Option<&'st Function => Some("function"), Getter => Some("getter"), Interface => Some("interface"), + Macro => Some("macro"), Method => Some("method"), MethodAlias => Some("methodAlias"), MethodSpecification => Some("methodSpec"), @@ -80,6 +84,8 @@ pub fn symbol_kind_to_ctags_kind(kind: &symbol_information::Kind) -> Option<&'st Struct => Some("struct"), TypeAlias => Some("typeAlias"), Trait => Some("trait"), + Union => Some("union"), + Variable => Some("variable"), // Implementation => Some("implementation"), TODO _ => None, } diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/testdata/example.c b/docker-images/syntax-highlighter/crates/scip-syntax/testdata/example.c index 4cce7f667ff72..e501b8ba5c6e8 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/testdata/example.c +++ b/docker-images/syntax-highlighter/crates/scip-syntax/testdata/example.c @@ -1,3 +1,121 @@ -int main() { - return 0; +#include +#include + +#define BUFSIZE 4096 + +const char *name = "com.horsegraph.connection"; +const char *author = "Petri & Thorsten"; +const int count; +int count2; +const int age = 28; +static uint sweet_sweet_numbers[5] = {23, 420, 69, 42, 7}; + +const int *ptr1 = &count; +const int **ptrptr1 = &ptr1; +const int ***ptrptrptr1 = &ptrptr1; + +enum { BLACK, RED }; + +enum animal { + ANIMAL_TOUCAN, + ANIMAL_TIGER = 1, + ANIMAL_TIGGER = ANIMAL_TIGER, + ANIMAL_HORSE, + ANIMAL_GIRAFFE, + ANIMAL_GOPHER = 99, + ANIMAL_ORANGUTAN +}; + +typedef enum instrument { + INSTRUMENT_GUITAR, + INSTRUMENT_KEYTAR, + INSTRUMENT_SITAR +} Instrument; + +union { + char *hobby; + int age; // <-- TODO: this will be tagged as a Constant because it's the same + // symbol as the `const int age` above. +} person; + +union object { + char *name; + int value; + int age; +} obj1, obj2, *obj3; + +const union object2 { + char name; +} obj4; + +struct connection { + int complete; + int fd; + int bufsize; + char *buffer; + char *url; +}; + +typedef struct connection Connection; + +typedef struct computer { + int cores; +} Computer; + +typedef struct { + int number; +} NoName; + +struct outer { + struct inner { + int x; + int y; + } b; +}; + +// Prototype +struct connection *new_connection(int fd); +// Implementation +struct connection *new_connection(int fd) { + struct connection *c = malloc(sizeof(struct connection)); + if (c == NULL) { + return NULL; + } + + c->url = NULL; + c->complete = 0; + c->fd = fd; + + c->buffer = calloc(BUFSIZE, sizeof(char)); + if (c->buffer == NULL) { + free(c); + return NULL; + } + c->bufsize = BUFSIZE; + + return c; } + +static void free_connection(struct connection *c) { + if (c->buffer) { + free(c->buffer); + } + + if (c->url) { + free(c->url); + } + + free(c); +} + +// Prototype +int returns_int(); +// Implementation +int returns_int() { return 12; } + +int main() { return 0; } + +int k_and_r(s, f) +char *s; +float f; +{ return 5; }