diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2026-01-21 09:59:13 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2026-01-21 13:38:45 +0000 |
| commit | 8fc377978dcf81013752b91c15eb8d573fca560f (patch) | |
| tree | c1cf2241556888c759e0d2ab8641caee53a35e0d /pkg | |
| parent | 6b862b615943965909f5b1b611786b5ba2d2819e (diff) | |
pkg/codesearch: do indexing of struct/union/enum
Update #6469
Diffstat (limited to 'pkg')
18 files changed, 245 insertions, 26 deletions
diff --git a/pkg/codesearch/database.go b/pkg/codesearch/database.go index 800c5759b..edeb761cc 100644 --- a/pkg/codesearch/database.go +++ b/pkg/codesearch/database.go @@ -44,7 +44,7 @@ type LineRange struct { var DatabaseFormatHash = func() string { // Semantic version should be bumped when the schema does not change, // but stored values changes. - const semanticVersion = "1" + const semanticVersion = "2" schema, err := jsonschema.For[Database](nil) if err != nil { panic(err) diff --git a/pkg/codesearch/testdata/query-def-source-header b/pkg/codesearch/testdata/query-def-source-header index 9e221f57b..edd8d2303 100644 --- a/pkg/codesearch/testdata/query-def-source-header +++ b/pkg/codesearch/testdata/query-def-source-header @@ -2,7 +2,7 @@ def-source source0.c function_with_comment_in_header yes function function_with_comment_in_header is defined in source0.c: - 19: void function_with_comment_in_header() - 20: { - 21: same_name_in_several_files(); - 22: } + 24: void function_with_comment_in_header() + 25: { + 26: same_name_in_several_files(); + 27: } diff --git a/pkg/codesearch/testdata/query-def-source-open b/pkg/codesearch/testdata/query-def-source-open index c8c11b8ef..79d0f8977 100644 --- a/pkg/codesearch/testdata/query-def-source-open +++ b/pkg/codesearch/testdata/query-def-source-open @@ -2,10 +2,10 @@ def-source source0.c open yes function open is defined in source0.c: - 6: /* - 7: * Comment about open. - 8: */ - 9: int open() - 10: { - 11: return 0; - 12: } + 11: /* + 12: * Comment about open. + 13: */ + 14: int open() + 15: { + 16: return 0; + 17: } diff --git a/pkg/codesearch/testdata/query-def-source-struct0 b/pkg/codesearch/testdata/query-def-source-struct0 new file mode 100644 index 000000000..adf011a3c --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct0 @@ -0,0 +1,8 @@ +def-source source0.c struct_in_c_file yes + +struct struct_in_c_file is defined in source0.c: + + 6: struct struct_in_c_file { + 7: int X; + 8: struct some_struct by_value; + 9: }; diff --git a/pkg/codesearch/testdata/query-def-source-struct1 b/pkg/codesearch/testdata/query-def-source-struct1 new file mode 100644 index 000000000..f6b5bba0b --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct1 @@ -0,0 +1,8 @@ +def-source source0.c some_struct yes + +struct some_struct is defined in source0.h: + + 17: struct some_struct { + 18: int x; + 19: int y; + 20: }; diff --git a/pkg/codesearch/testdata/query-def-source-struct2 b/pkg/codesearch/testdata/query-def-source-struct2 new file mode 100644 index 000000000..5de681a75 --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct2 @@ -0,0 +1,5 @@ +def-source source0.c some_struct_t yes + +typedef some_struct_t is defined in source0.h: + + 22: typedef struct some_struct some_struct_t; diff --git a/pkg/codesearch/testdata/query-def-source-struct3 b/pkg/codesearch/testdata/query-def-source-struct3 new file mode 100644 index 000000000..0d4f4e29e --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct3 @@ -0,0 +1,11 @@ +def-source source0.c some_struct_with_a_comment yes + +struct some_struct_with_a_comment is defined in source0.h: + + 24: /* + 25: * This should not require an explanation. + 26: */ + 27: struct some_struct_with_a_comment { + 28: int x; + 29: struct some_struct* other_struct; + 30: }; diff --git a/pkg/codesearch/testdata/query-def-source-struct4 b/pkg/codesearch/testdata/query-def-source-struct4 new file mode 100644 index 000000000..bd0c03d90 --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct4 @@ -0,0 +1,7 @@ +def-source source0.c typedefed_struct_t yes + +typedef typedefed_struct_t is defined in source0.h: + + 32: typedef struct { + 33: int x; + 34: } typedefed_struct_t; diff --git a/pkg/codesearch/testdata/query-def-source-struct5 b/pkg/codesearch/testdata/query-def-source-struct5 new file mode 100644 index 000000000..b86f38484 --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct5 @@ -0,0 +1,7 @@ +def-source source0.c another_struct yes + +struct another_struct is defined in source0.h: + + 36: typedef struct another_struct { + 37: int x; + 38: } another_struct_t; diff --git a/pkg/codesearch/testdata/query-def-source-struct6 b/pkg/codesearch/testdata/query-def-source-struct6 new file mode 100644 index 000000000..77d9a1102 --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct6 @@ -0,0 +1,7 @@ +def-source source0.c another_struct_t yes + +typedef another_struct_t is defined in source0.h: + + 36: typedef struct another_struct { + 37: int x; + 38: } another_struct_t; diff --git a/pkg/codesearch/testdata/query-def-source-struct7 b/pkg/codesearch/testdata/query-def-source-struct7 new file mode 100644 index 000000000..3d6212614 --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct7 @@ -0,0 +1,8 @@ +def-source source0.c some_union yes + +union some_union is defined in source0.h: + + 40: union some_union { + 41: int x; + 42: void* p; + 43: }; diff --git a/pkg/codesearch/testdata/query-def-source-struct8 b/pkg/codesearch/testdata/query-def-source-struct8 new file mode 100644 index 000000000..93c7c6516 --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct8 @@ -0,0 +1,8 @@ +def-source source0.c some_enum yes + +enum some_enum is defined in source0.h: + + 45: enum some_enum { + 46: enum_foo = 1, + 47: enum_bar = 2, + 48: }; diff --git a/pkg/codesearch/testdata/query-def-source-struct9 b/pkg/codesearch/testdata/query-def-source-struct9 new file mode 100644 index 000000000..20056963a --- /dev/null +++ b/pkg/codesearch/testdata/query-def-source-struct9 @@ -0,0 +1,5 @@ +def-source source0.c some_enum_t yes + +typedef some_enum_t is defined in source0.h: + + 50: typedef enum some_enum some_enum_t; diff --git a/pkg/codesearch/testdata/query-file-index-source b/pkg/codesearch/testdata/query-file-index-source index c238079d0..3263deca3 100644 --- a/pkg/codesearch/testdata/query-file-index-source +++ b/pkg/codesearch/testdata/query-file-index-source @@ -5,3 +5,4 @@ file source0.c defines the following entities: function close function function_with_comment_in_header function open +struct struct_in_c_file diff --git a/pkg/codesearch/testdata/query-find-references-normal b/pkg/codesearch/testdata/query-find-references-normal index 1bc1a4be1..2c19827cc 100644 --- a/pkg/codesearch/testdata/query-find-references-normal +++ b/pkg/codesearch/testdata/query-find-references-normal @@ -2,10 +2,10 @@ find-references source0.c same_name_in_several_files "" 3 10 same_name_in_several_files has 1 references: -function function_with_comment_in_header calls it at source0.c:21 - 19: void function_with_comment_in_header() - 20: { - 21: same_name_in_several_files(); - 22: } +function function_with_comment_in_header calls it at source0.c:26 + 24: void function_with_comment_in_header() + 25: { + 26: same_name_in_several_files(); + 27: } diff --git a/pkg/codesearch/testdata/source0.c b/pkg/codesearch/testdata/source0.c index 384c4c119..2d312ff99 100644 --- a/pkg/codesearch/testdata/source0.c +++ b/pkg/codesearch/testdata/source0.c @@ -3,6 +3,11 @@ #include "source0.h" +struct struct_in_c_file { + int X; + struct some_struct by_value; +}; + /* * Comment about open. */ diff --git a/pkg/codesearch/testdata/source0.c.json b/pkg/codesearch/testdata/source0.c.json index cb80dc021..ba6b41751 100644 --- a/pkg/codesearch/testdata/source0.c.json +++ b/pkg/codesearch/testdata/source0.c.json @@ -1,13 +1,23 @@ { "definitions": [ { + "kind": "enum", + "name": "some_enum", + "body": { + "file": "source0.h", + "start_line": 45, + "end_line": 48 + }, + "comment": {} + }, + { "kind": "function", "name": "close", "type": "int ()", "body": { "file": "source0.c", - "start_line": 14, - "end_line": 17 + "start_line": 19, + "end_line": 22 }, "comment": {} }, @@ -29,8 +39,8 @@ "type": "void ()", "body": { "file": "source0.c", - "start_line": 19, - "end_line": 22 + "start_line": 24, + "end_line": 27 }, "comment": {}, "refs": [ @@ -38,7 +48,7 @@ "kind": "calls", "entity_kind": "function", "name": "same_name_in_several_files", - "line": 21 + "line": 26 } ] }, @@ -48,14 +58,108 @@ "type": "int ()", "body": { "file": "source0.c", - "start_line": 6, - "end_line": 12 + "start_line": 11, + "end_line": 17 }, "comment": { "file": "source0.c", - "start_line": 6, - "end_line": 8 + "start_line": 11, + "end_line": 13 + } + }, + { + "kind": "struct", + "name": "another_struct", + "body": { + "file": "source0.h", + "start_line": 36, + "end_line": 38 + }, + "comment": {} + }, + { + "kind": "struct", + "name": "some_struct", + "body": { + "file": "source0.h", + "start_line": 17, + "end_line": 20 + }, + "comment": {} + }, + { + "kind": "struct", + "name": "some_struct_with_a_comment", + "body": { + "file": "source0.h", + "start_line": 24, + "end_line": 30 + }, + "comment": { + "file": "source0.h", + "start_line": 24, + "end_line": 26 } + }, + { + "kind": "struct", + "name": "struct_in_c_file", + "body": { + "file": "source0.c", + "start_line": 6, + "end_line": 9 + }, + "comment": {} + }, + { + "kind": "typedef", + "name": "another_struct_t", + "body": { + "file": "source0.h", + "start_line": 36, + "end_line": 38 + }, + "comment": {} + }, + { + "kind": "typedef", + "name": "some_enum_t", + "body": { + "file": "source0.h", + "start_line": 50, + "end_line": 50 + }, + "comment": {} + }, + { + "kind": "typedef", + "name": "some_struct_t", + "body": { + "file": "source0.h", + "start_line": 22, + "end_line": 22 + }, + "comment": {} + }, + { + "kind": "typedef", + "name": "typedefed_struct_t", + "body": { + "file": "source0.h", + "start_line": 32, + "end_line": 34 + }, + "comment": {} + }, + { + "kind": "union", + "name": "some_union", + "body": { + "file": "source0.h", + "start_line": 40, + "end_line": 43 + }, + "comment": {} } ] }
\ No newline at end of file diff --git a/pkg/codesearch/testdata/source0.h b/pkg/codesearch/testdata/source0.h index d1540ebce..9549feb9d 100644 --- a/pkg/codesearch/testdata/source0.h +++ b/pkg/codesearch/testdata/source0.h @@ -13,3 +13,38 @@ static inline int func_in_header() { return 0; } + +struct some_struct { + int x; + int y; +}; + +typedef struct some_struct some_struct_t; + +/* + * This should not require an explanation. + */ +struct some_struct_with_a_comment { + int x; + struct some_struct* other_struct; +}; + +typedef struct { + int x; +} typedefed_struct_t; + +typedef struct another_struct { + int x; +} another_struct_t; + +union some_union { + int x; + void* p; +}; + +enum some_enum { + enum_foo = 1, + enum_bar = 2, +}; + +typedef enum some_enum some_enum_t; |
