-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document code: Add tree-sitter query for CPP (#4392)
- Loading branch information
Showing
7 changed files
with
422 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import dedent from 'dedent' | ||
|
||
import { SupportedLanguage } from '../grammars' | ||
import type { QueryName } from '../queries' | ||
|
||
const DOCUMENTABLE_NODES = dedent` | ||
; Function definitions | ||
;-------------------------------- | ||
(function_definition | ||
type: (primitive_type) | ||
declarator: (function_declarator) | ||
body: (compound_statement) @symbol.function) @range.function | ||
; Class definitions | ||
;-------------------------------- | ||
(class_specifier | ||
name: (type_identifier) | ||
body: (_)) @range.class | ||
(struct_specifier | ||
name: (type_identifier) | ||
body: (_)) @range.struct | ||
(declaration | ||
type: (union_specifier | ||
name: (type_identifier) @symbol.union)) @range.union | ||
; Variables | ||
;-------------------------------- | ||
(declaration) @symbol.identifier @range.identifier | ||
; Types | ||
;-------------------------------- | ||
(type_definition | ||
type: (struct_specifier) @symbol.identifier) @range.identifier | ||
(enum_specifier | ||
name: (type_identifier) @symbol.identifier) @range.identifier | ||
` | ||
|
||
const ENCLOSING_FUNCTION_QUERY = dedent` | ||
(function_definition declarator: (function_declarator) @symbol.function) @range.function | ||
` | ||
|
||
export const cppQueries = { | ||
[SupportedLanguage.cpp]: { | ||
singlelineTriggers: '', | ||
intents: '', | ||
documentableNodes: DOCUMENTABLE_NODES, | ||
identifiers: '', | ||
graphContextIdentifiers: '', | ||
enclosingFunction: ENCLOSING_FUNCTION_QUERY, | ||
}, | ||
} satisfies Partial<Record<SupportedLanguage, Record<QueryName, string>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
vscode/src/tree-sitter/query-tests/test-data/documentable-node.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* wrapper */ | ||
void wrapper() | ||
{ | ||
void test() | ||
{ | ||
// | | ||
} | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
void test() | ||
{ | ||
// | | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
static void twoSum(int *nums, int numsSize, int target, int *returnSize) | ||
{ | ||
if (numsSize < 2) | ||
{ | ||
return; | ||
} | ||
else | ||
{ | ||
for (int i = 0; i < numsSize; i++) | ||
{ | ||
for (int j = i + 1; j < numsSize; j++) | ||
{ | ||
if (nums[i] + nums[j] == target) | ||
{ | ||
// | | ||
returnSize[0] = i; | ||
returnSize[1] = j; | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
void test_multiline_func_declaration( | ||
// | | ||
int val, | ||
int val2) | ||
{ | ||
wrapper(); | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
void test_parameter(int val) | ||
{ | ||
// | | ||
wrapper(); | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
typedef struct | ||
{ | ||
// | | ||
} Agent; | ||
|
||
// ------------------------------------ | ||
|
||
typedef struct | ||
{ | ||
// | | ||
void (*__init__)(struct AgentMultiLine *self, char *name); | ||
} AgentMultiLine; | ||
|
||
// ------------------------------------ | ||
|
||
void AgentMultiLine__init__(AgentMultiLine *self, char *name) | ||
{ | ||
// | | ||
self->name = name; | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
typedef struct | ||
{ | ||
char *name; | ||
// | | ||
} Agent; | ||
|
||
// ------------------------------------ | ||
|
||
void Agent_test(Agent *self) | ||
{ | ||
// | | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
void return_statement() | ||
{ | ||
return; | ||
// | | ||
} | ||
|
||
// ------------------------------------ | ||
|
||
return_statement('value'); | ||
// | | ||
|
||
// ------------------------------------ | ||
|
||
char *user_name = "Tom"; | ||
// | | ||
|
||
// ------------------------------------ | ||
|
||
enum Level | ||
{ | ||
// | | ||
LOW, | ||
MEDIUM, | ||
HIGH | ||
}; |
Oops, something went wrong.