dsh-plugin-codegraph-tree-sitter 0.1.1 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/extract.d.ts +17 -0
- package/lib/extract.js +1709 -22
- package/lib/languages.d.ts +140 -1
- package/lib/languages.js +707 -2
- package/lib/resolve.d.ts +3 -0
- package/lib/resolve.js +44 -3
- package/lib/schema.js +3 -3
- package/package.json +2 -2
package/lib/languages.d.ts
CHANGED
|
@@ -28,7 +28,127 @@ export interface DefinitionRule {
|
|
|
28
28
|
/** Node types the field must resolve to for this rule to match. */
|
|
29
29
|
readonly types: readonly string[];
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Present only when this rule must reject a name shape it cannot represent as a single declared
|
|
33
|
+
* name — a destructuring `variable_declarator` (`const {a, b} = x`) or a Python tuple/attribute
|
|
34
|
+
* assignment (`a, b = 1, 2`, `self.x = 1`) binds through {@link nameField} too, but to a pattern
|
|
35
|
+
* node this package does not attempt to name. Absent, any node type in {@link nameField} matches.
|
|
36
|
+
*/
|
|
37
|
+
readonly nameNodeTypes?: readonly string[];
|
|
38
|
+
/**
|
|
39
|
+
* Present only when this rule must not match the same node type wherever it appears — a bare
|
|
40
|
+
* `property_identifier` names an enum member only directly inside an `enum_body`; the same node
|
|
41
|
+
* type also names a method, a class field, and a member-expression property everywhere else. Absent,
|
|
42
|
+
* any parent matches.
|
|
43
|
+
*/
|
|
44
|
+
readonly parentType?: string;
|
|
45
|
+
/**
|
|
46
|
+
* True only for a rule this package extracts solely directly inside a module's top level or a class
|
|
47
|
+
* body — never inside a function or method body. Unlike a function or class declaration (captured at
|
|
48
|
+
* any depth, however deeply nested), a function-local variable is not a workspace "symbol" anyone
|
|
49
|
+
* would search for by name, and capturing it would flood the cross-file name index `resolve.ts` uses
|
|
50
|
+
* to settle calls — more names means more collisions, which means more calls silently dropped to
|
|
51
|
+
* `unresolved`. See `resolve.ts`'s "an ambiguous edge is worse than a missing one" rule.
|
|
52
|
+
*
|
|
53
|
+
* This is a property of the *rule*, not of {@link kind} in general: JS/TS's `field_definition` rule
|
|
54
|
+
* (kind `field`) sets this because a class field could in principle sit at any depth a class does —
|
|
55
|
+
* but Go's struct-field rule, also kind `field`, must not, because its enclosing `type_spec` is itself
|
|
56
|
+
* never scope-restricted (a Go type declaration is captured at any depth, like a function), so a
|
|
57
|
+
* scope-restricted struct-field rule could never fire at all. Absent (the common case), always
|
|
58
|
+
* extracted regardless of depth.
|
|
59
|
+
*/
|
|
60
|
+
readonly scopeRestricted?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Present only when a rule must distinguish two node types that share both their own type and their
|
|
63
|
+
* immediate parent's type — C#'s field vs. local variable both parse as a `variable_declarator`
|
|
64
|
+
* directly inside a `variable_declaration`, and only the *grandparent* differs
|
|
65
|
+
* (`field_declaration` vs. `local_declaration_statement`). Absent, any grandparent matches, the same
|
|
66
|
+
* as an absent {@link parentType}.
|
|
67
|
+
*/
|
|
68
|
+
readonly grandparentType?: string;
|
|
31
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose matched node has no separate
|
|
72
|
+
* name-bearing child — a bare enum member (`enum_body`'s `Red` in `enum Color { Red }`) parses as a
|
|
73
|
+
* lone `property_identifier` token with no fields of its own; the node itself, unlike every other
|
|
74
|
+
* `nameField` target, *is* the name.
|
|
75
|
+
*/
|
|
76
|
+
export declare const SELF_NAME_FIELD = "@self";
|
|
77
|
+
/**
|
|
78
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name sits behind an arbitrarily deep
|
|
79
|
+
* chain of C/C++ `declarator` wrappers — `int *make(int a)`'s name is three `declarator` fields down
|
|
80
|
+
* (`pointer_declarator` → `function_declarator` → `identifier`), and a plain `int g` binds its
|
|
81
|
+
* `identifier` directly with no wrapper at all. See `declaratorName` in `extract.ts`, which this
|
|
82
|
+
* sentinel dispatches to instead of a flat `childForFieldName` lookup.
|
|
83
|
+
*/
|
|
84
|
+
export declare const DECLARATOR_NAME_FIELD = "@declarator";
|
|
85
|
+
/**
|
|
86
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name is its matched node's first
|
|
87
|
+
* named child with no field name of its own — C#'s `variable_declarator` binds neither its name nor its
|
|
88
|
+
* optional initializer to a field at all (`int Field = 5;`'s `variable_declarator` has two purely
|
|
89
|
+
* positional named children, `identifier` then `equals_value_clause`), unlike every other grammar this
|
|
90
|
+
* package extracts a name from. Distinct from {@link SELF_NAME_FIELD}: the matched node's own text
|
|
91
|
+
* would include that initializer (`"Field = 5"`), not just the name. See `firstChildName` in
|
|
92
|
+
* `extract.ts`.
|
|
93
|
+
*/
|
|
94
|
+
export declare const FIRST_CHILD_NAME_FIELD = "@first-child";
|
|
95
|
+
/**
|
|
96
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name is PHP-specific: a bare `name`
|
|
97
|
+
* node directly (`const_element`'s `VERSION` in `const VERSION = "1"`), or one nested a level deeper
|
|
98
|
+
* inside a `variable_name` child (`property_element`'s `$name` in `public string $name;`, and an
|
|
99
|
+
* `assignment_expression`'s `$fn` in `$fn = function () {}` — both bind their bare `name` behind the
|
|
100
|
+
* same `$`-prefixed wrapper). See `phpElementName` in `extract.ts`, which this sentinel dispatches to
|
|
101
|
+
* instead of a flat `childForFieldName` lookup — none of these three shapes bind their name to a field
|
|
102
|
+
* of its own.
|
|
103
|
+
*/
|
|
104
|
+
export declare const PHP_ELEMENT_NAME_FIELD = "@php-element";
|
|
105
|
+
/**
|
|
106
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name is Kotlin-specific: the bundled
|
|
107
|
+
* `tree-sitter-kotlin` grammar this package loads binds *no* grammar fields at all (verified against a
|
|
108
|
+
* real parse — `Language.fieldCount`/`fieldNameForId` enumerate zero for it), unlike every other grammar
|
|
109
|
+
* this package extracts from, so a plain `childForFieldName` lookup can never work here regardless of
|
|
110
|
+
* which field name is named. A `class_declaration`'s/`function_declaration`'s/`enum_entry`'s declared
|
|
111
|
+
* name is instead the first direct named child typed `type_identifier` (a class/interface/enum name) or
|
|
112
|
+
* `simple_identifier` (a function/enum-entry name) — found by type rather than by position, since an
|
|
113
|
+
* optional leading `modifiers` node (wrapping `private`/`internal`/…) would otherwise sit at index 0
|
|
114
|
+
* ahead of it. See `kotlinDeclaredName` in `extract.ts`, which this sentinel dispatches to.
|
|
115
|
+
*/
|
|
116
|
+
export declare const KOTLIN_NAME_FIELD = "@kotlin-name";
|
|
117
|
+
/**
|
|
118
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name is Swift-specific: a
|
|
119
|
+
* `property_declaration`'s own `name` field points to a `pattern` node (`var x: Int`'s `x` sits behind
|
|
120
|
+
* this wrapper, not bound to a field of `property_declaration` directly), and the actual declared
|
|
121
|
+
* identifier is one level deeper still, bound to that `pattern` node's own `bound_identifier` field.
|
|
122
|
+
* See `swiftPropertyName` in `extract.ts`, which this sentinel dispatches to instead of a flat
|
|
123
|
+
* `childForFieldName` lookup. Verified against a real parse, not guessed.
|
|
124
|
+
*/
|
|
125
|
+
export declare const SWIFT_PROPERTY_NAME_FIELD = "@swift-property";
|
|
126
|
+
/**
|
|
127
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name is Swift-specific in a
|
|
128
|
+
* different way: a `function_declaration`/`protocol_function_declaration` with an explicit return type
|
|
129
|
+
* (`func add() -> Int`) binds *two* nodes to its own `name` field in this grammar build — the declared
|
|
130
|
+
* identifier itself, and (a verified, unguessed quirk of this specific compiled grammar) its
|
|
131
|
+
* `return_type` node as well — so `childrenForFieldName('name')` returns both, failing
|
|
132
|
+
* `soleNamedField`'s "exactly one bound child" uniqueness check the same way Go's genuinely ambiguous
|
|
133
|
+
* `const a, b = 1, 2` does, and silently dropping every such function from this package's graph. Unlike
|
|
134
|
+
* that Go case, this is not a real multi-name ambiguity — the identifier always comes first in document
|
|
135
|
+
* order — so `swiftFunctionName` in `extract.ts` uses `childForFieldName('name')` (first match) instead
|
|
136
|
+
* of `soleNamedField`'s all-matches check.
|
|
137
|
+
*/
|
|
138
|
+
export declare const SWIFT_FUNCTION_NAME_FIELD = "@swift-function";
|
|
139
|
+
/**
|
|
140
|
+
* Sentinel {@link DefinitionRule.nameField} value for a rule whose name is Dart-specific: a `declaration`
|
|
141
|
+
* node is how Dart spells both a class/struct field (`int x;`, wrapping an `initialized_identifier_list`
|
|
142
|
+
* of one or more `initialized_identifier` children, itself the same multi-name ambiguity Go's
|
|
143
|
+
* `const_spec`/`var_spec` already reject outright) and a constructor (wrapping a `constructor_signature`
|
|
144
|
+
* instead, handled by its own separate rule matching that inner node type directly, not this one) — with
|
|
145
|
+
* no field of its own binding either shape, so `dartFieldName` in `extract.ts` returns `undefined` for
|
|
146
|
+
* anything but the single-identifier field-list shape, the same "don't guess" precedent this file already
|
|
147
|
+
* follows elsewhere; a `declaration` wrapping a constructor simply fails to match this rule and is left
|
|
148
|
+
* for the dedicated `constructor_signature` rule to capture during the walk's ordinary recursion into it.
|
|
149
|
+
* Verified against a real parse, not guessed.
|
|
150
|
+
*/
|
|
151
|
+
export declare const DART_FIELD_NAME_FIELD = "@dart-field";
|
|
32
152
|
/** One tree-sitter node type recording a relative-import binding, per language family. */
|
|
33
153
|
export interface ImportRule {
|
|
34
154
|
/** The tree-sitter node type anchoring one import statement, e.g. `import_statement`. */
|
|
@@ -46,10 +166,29 @@ export interface LanguageSpec {
|
|
|
46
166
|
readonly definitions: readonly DefinitionRule[];
|
|
47
167
|
/** Node types whose {@link callFunctionField} names the callee. */
|
|
48
168
|
readonly callTypes: readonly string[];
|
|
49
|
-
/** Field on a call node holding the callee expression
|
|
169
|
+
/** Field on a call node holding the callee expression, used for any {@link callTypes} member absent
|
|
170
|
+
* from {@link callFunctionFieldByType}. */
|
|
50
171
|
readonly callFunctionField: string;
|
|
172
|
+
/**
|
|
173
|
+
* Present only when different {@link callTypes} members name their callee through different fields —
|
|
174
|
+
* PHP's `member_call_expression` ($obj->method()) and `scoped_call_expression` (Class::method()) both
|
|
175
|
+
* use `name`, while `function_call_expression` uses `function`; every other language's call types
|
|
176
|
+
* (today, always exactly one) share a single field, so this is absent for all of them. Overrides
|
|
177
|
+
* {@link callFunctionField} for the node types it lists.
|
|
178
|
+
*/
|
|
179
|
+
readonly callFunctionFieldByType?: Readonly<Record<string, string>>;
|
|
51
180
|
/** Node types anchoring one import statement. */
|
|
52
181
|
readonly importTypes: readonly string[];
|
|
182
|
+
/**
|
|
183
|
+
* Node types that bound a new function scope even when the walk never captures them as a named
|
|
184
|
+
* definition — a callback (`arr.forEach(function(item) { ... })`) or an IIFE's `function_expression`
|
|
185
|
+
* never matches a {@link DefinitionRule} (only a *named* declaration, or one assigned through a
|
|
186
|
+
* captured `variable_declarator`, does), but a `const`/`var` inside its body is exactly the
|
|
187
|
+
* function-local binding a `scopeRestricted` {@link DefinitionRule} exists to exclude. Empty for a language with
|
|
188
|
+
* no anonymous-function shape that can contain a statement (Python's `lambda` body is a single
|
|
189
|
+
* expression, never a block).
|
|
190
|
+
*/
|
|
191
|
+
readonly bareFunctionScopeTypes: readonly string[];
|
|
53
192
|
}
|
|
54
193
|
/** Every grammar this package loads, keyed by the seam language label it produces. */
|
|
55
194
|
export declare const LANGUAGE_TABLE: readonly LanguageSpec[];
|