🎨 more minimal tree-sitter queries for code ctx provider
This commit is contained in:
parent
283c7ebcad
commit
f6633fd157
19 changed files with 196 additions and 1 deletions
|
|
@ -51,7 +51,8 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
const sourcePath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"tag-qry",
|
||||
"tree-sitter",
|
||||
"code-snippet-queries",
|
||||
`tree-sitter-${fullLangName}-tags.scm`,
|
||||
);
|
||||
if (!fs.existsSync(sourcePath)) {
|
||||
|
|
|
|||
11
core/package-lock.json
generated
11
core/package-lock.json
generated
|
|
@ -55,6 +55,7 @@
|
|||
"@types/uuid": "^9.0.7",
|
||||
"esbuild": "^0.19.11",
|
||||
"jest": "^29.7.0",
|
||||
"tree-sitter-cli": "^0.21.0",
|
||||
"ts-jest": "^29.1.1"
|
||||
}
|
||||
},
|
||||
|
|
@ -9825,6 +9826,16 @@
|
|||
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tree-sitter-cli": {
|
||||
"version": "0.21.0",
|
||||
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.21.0.tgz",
|
||||
"integrity": "sha512-wA7wT5724fNQW82XDH6zT6ZcYonjrAKLCHHuhLsPcAKULrhp3rNuMvlgBdB5FUBvmjHNhtTZF/qpHenMoRJPBw==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
"tree-sitter": "cli.js"
|
||||
}
|
||||
},
|
||||
"node_modules/tree-sitter-wasms": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/tree-sitter-wasms/-/tree-sitter-wasms-0.1.6.tgz",
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ export async function getLanguageForFile(
|
|||
filepath: string,
|
||||
): Promise<Language | undefined> {
|
||||
try {
|
||||
await Parser.init();
|
||||
const extension = path.extname(filepath).slice(1);
|
||||
|
||||
if (!supportedLanguages[extension]) {
|
||||
|
|
|
|||
|
|
@ -5492,6 +5492,11 @@ tr46@~0.0.3:
|
|||
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
|
||||
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
|
||||
|
||||
tree-sitter-cli@^0.21.0:
|
||||
version "0.21.0"
|
||||
resolved "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.21.0.tgz"
|
||||
integrity sha512-wA7wT5724fNQW82XDH6zT6ZcYonjrAKLCHHuhLsPcAKULrhp3rNuMvlgBdB5FUBvmjHNhtTZF/qpHenMoRJPBw==
|
||||
|
||||
tree-sitter-wasms@^0.1.6:
|
||||
version "0.1.6"
|
||||
resolved "https://registry.npmjs.org/tree-sitter-wasms/-/tree-sitter-wasms-0.1.6.tgz"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
(function_definition declarator: (function_declarator (identifier) @name)) @definition.function
|
||||
|
||||
(struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class
|
||||
|
||||
(declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class
|
||||
|
||||
(type_definition declarator: (type_identifier) @name ) @body
|
||||
|
||||
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
(class_declaration
|
||||
name: (identifier) @name.definition.class
|
||||
) @definition.class
|
||||
|
||||
(class_declaration
|
||||
bases: (base_list (_) @name.reference.class)
|
||||
) @reference.class
|
||||
|
||||
(interface_declaration
|
||||
name: (identifier) @name.definition.interface
|
||||
) @definition.interface
|
||||
|
||||
(interface_declaration
|
||||
bases: (base_list (_) @name.reference.interface)
|
||||
) @reference.interface
|
||||
|
||||
(method_declaration
|
||||
name: (identifier) @name.definition.method
|
||||
) @definition.method
|
||||
|
||||
(namespace_declaration
|
||||
name: (identifier) @name.definition.module
|
||||
) @definition.module
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(function_definition declarator: (function_declarator) @name.definition.function) @definition.function
|
||||
|
||||
(type_definition declarator: (type_identifier) @name.definition.type) @definition.type
|
||||
|
||||
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type
|
||||
|
||||
(class_specifier name: (type_identifier) @name.definition.class) @definition.class
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
;; defun/defsubst
|
||||
(function_definition name: (symbol) @name.definition.function) @definition.function
|
||||
|
||||
;; Treat macros as function definitions for the sake of TAGS.
|
||||
(macro_definition name: (symbol) @name.definition.function) @definition.function
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
; Definitions
|
||||
|
||||
; * modules and protocols
|
||||
(call
|
||||
target: (identifier) @ignore
|
||||
(arguments (alias) @name.definition.module)
|
||||
(#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
|
||||
|
||||
; * functions/macros
|
||||
(call
|
||||
target: (identifier) @ignore
|
||||
(arguments
|
||||
[
|
||||
; zero-arity functions with no parentheses
|
||||
(identifier) @name.definition.function
|
||||
; regular function clause
|
||||
(call target: (identifier) @name.definition.function)
|
||||
; function clause with a guard clause
|
||||
(binary_operator
|
||||
left: (call target: (identifier) @name.definition.function)
|
||||
operator: "when")
|
||||
])
|
||||
(#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @definition.function
|
||||
|
||||
; * modules
|
||||
(alias) @name.reference.module @reference.module
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(function_declaration
|
||||
name: (identifier) @name.definition.function) @definition.function
|
||||
(#strip! @doc "^//\\s*")
|
||||
(#set-adjacent! @doc @definition.function)
|
||||
)
|
||||
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(method_declaration
|
||||
name: (field_identifier) @name.definition.method) @definition.method
|
||||
(#strip! @doc "^//\\s*")
|
||||
(#set-adjacent! @doc @definition.method)
|
||||
)
|
||||
|
||||
(type_spec
|
||||
name: (type_identifier) @name.definition.type) @definition.type
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(class_declaration
|
||||
name: (identifier) @name.definition.class) @definition.class
|
||||
|
||||
(method_declaration
|
||||
name: (identifier) @name.definition.method) @definition.method
|
||||
|
||||
(interface_declaration
|
||||
name: (identifier) @name.definition.interface) @definition.interface
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(class_declaration
|
||||
name: (_) @name) @body
|
||||
|
||||
(function_declaration
|
||||
name: (_) @name) @body
|
||||
|
||||
(method_definition
|
||||
name: (_) @name) @body
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
(value_definition
|
||||
(let_binding
|
||||
pattern: (_) @name)
|
||||
) @body
|
||||
|
||||
(module_type_definition
|
||||
name: (_) @name) @body
|
||||
|
||||
(class_definition
|
||||
(class_binding
|
||||
name: (_) @name)
|
||||
) @body
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(class_declaration
|
||||
name: (name) @name) @body
|
||||
|
||||
(function_definition
|
||||
name: (name) @name) @body
|
||||
|
||||
(method_declaration
|
||||
name: (name) @name) @body
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(class_definition
|
||||
name: (_) @name) @body
|
||||
|
||||
(function_definition
|
||||
name: (_) @name) @body
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
(classlessPredicate
|
||||
name: (predicateName) @name.definition.function) @definition.function
|
||||
|
||||
(memberPredicate
|
||||
name: (predicateName) @name.definition.method) @definition.method
|
||||
|
||||
(aritylessPredicateExpr
|
||||
name: (literalId) @name.reference.call) @reference.call
|
||||
|
||||
(module
|
||||
name: (moduleName) @name.definition.module) @definition.module
|
||||
|
||||
(dataclass
|
||||
name: (className) @name.definition.class) @definition.class
|
||||
|
||||
(datatype
|
||||
name: (className) @name.definition.class) @definition.class
|
||||
|
||||
(datatypeBranch
|
||||
name: (className) @name.definition.class) @definition.class
|
||||
|
||||
(qualifiedRhs
|
||||
name: (predicateName) @name.reference.call) @reference.call
|
||||
|
||||
(typeExpr
|
||||
name: (className) @name.reference.type) @reference.type
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(function_item
|
||||
name: (_) @name) @body
|
||||
|
||||
(struct_item
|
||||
name: (_) @name) @body
|
||||
|
||||
(impl_item
|
||||
type: (_) @name) @body
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
(class_declaration
|
||||
name: (_) @name) @body
|
||||
|
||||
(function_declaration
|
||||
name: (_) @name) @body
|
||||
|
||||
(method_definition
|
||||
name: (_) @name) @body
|
||||
|
||||
(interface_declaration
|
||||
name: (_) @name) @body
|
||||
Loading…
Add table
Reference in a new issue