-
Notifications
You must be signed in to change notification settings - Fork 0
Improve codemark skill with fine-grained execution logic queries #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,37 @@ Any exported (capitalized) function: | |
| (#eq? @type "string")))) @target | ||
| ``` | ||
|
|
||
| ### Call Expression (Function Call) | ||
|
|
||
| Target where a specific function is invoked: | ||
|
|
||
| ```scheme | ||
| (call_expression | ||
| function: (identifier) @func | ||
| (#eq? @func "VerifyToken")) @target | ||
| ``` | ||
|
|
||
| ### Switch Statement | ||
|
|
||
| Target complex branching logic: | ||
|
|
||
| ```scheme | ||
| (switch_statement | ||
| value: (identifier) @val | ||
| (#eq? @val "action")) @target | ||
| ``` | ||
|
Comment on lines
+112
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the correct Go switch node kind.
🔧 Proposed fix-(switch_statement
+(expression_switch_statement
value: (identifier) `@val`
(`#eq`? `@val` "action")) `@target`#!/bin/bash
# Verify switch node names in official tree-sitter-go metadata.
python - <<'PY'
import urllib.request
url = "https://raw.githubusercontent.com/tree-sitter/tree-sitter-go/master/src/node-types.json"
s = urllib.request.urlopen(url).read().decode()
for token in ["switch_statement", "expression_switch_statement", "type_switch_statement"]:
print(f"{token}: {token in s}")
PY🤖 Prompt for AI Agents |
||
|
|
||
| ### If Statement | ||
|
|
||
| Target specific logical decision points: | ||
|
|
||
| ```scheme | ||
| (if_statement | ||
| condition: (call_expression | ||
| function: (identifier) @func | ||
| (#eq? @func "IsAuthorized"))) @target | ||
| ``` | ||
|
|
||
| ## Module Tagging | ||
|
|
||
| Go uses `package:<path>` with the full package path relative to module root (using dots): | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -110,6 +110,38 @@ Any static method: | |||||||||||||||||
| (#eq? @type "String")))) @target | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Call Expression (Method Call) | ||||||||||||||||||
|
|
||||||||||||||||||
| Target where a specific method is invoked: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```scheme | ||||||||||||||||||
| (method_invocation | ||||||||||||||||||
| name: (identifier) @method | ||||||||||||||||||
| (#eq? @method "verifyToken")) @target | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Switch Statement | ||||||||||||||||||
|
|
||||||||||||||||||
| Target complex branching logic: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```scheme | ||||||||||||||||||
| (switch_statement | ||||||||||||||||||
| condition: (parenthesized_expression | ||||||||||||||||||
| (identifier) @val | ||||||||||||||||||
| (#eq? @val "action"))) @target | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
Comment on lines
+128
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify Java switch node/field names in official grammar metadata.
python - <<'PY'
import urllib.request
url = "https://raw.githubusercontent.com/tree-sitter/tree-sitter-java/master/src/node-types.json"
s = urllib.request.urlopen(url).read().decode()
for token in ["switch_statement", "switch_expression", "\"value\""]:
print(f"{token}: {token in s}")
PYRepository: DanielCardonaRojas/codemark Length of output: 2652 🏁 Script executed: # First, check the actual file content
cat -n extras/skills/codemark/queries/java.md | sed -n '120,140p'Repository: DanielCardonaRojas/codemark Length of output: 571 🏁 Script executed: # Search for any tree-sitter Java grammar files in the repo
find . -name "*.json" -path "*/java*" -o -name "*grammar*" -type f | grep -i javaRepository: DanielCardonaRojas/codemark Length of output: 53 🏁 Script executed: # Look for other Java query examples or test files that might show correct usage
fd -t f "java" | head -20Repository: DanielCardonaRojas/codemark Length of output: 146 🏁 Script executed: # Check the Java test file for switch examples
cat tests/fixtures/java/AuthService.java | head -100Repository: DanielCardonaRojas/codemark Length of output: 2884 🏁 Script executed: # Search for any node-types or grammar references in the repo
find . -name "node-types.json" -o -name "*grammar*" | grep -i javaRepository: DanielCardonaRojas/codemark Length of output: 53 🏁 Script executed: # Search for any documentation or comments about tree-sitter Java in the codebase
rg -i "switch_statement|switch_expression" --type md --type txtRepository: DanielCardonaRojas/codemark Length of output: 607 🏁 Script executed: # Check if there's a package.json or similar that shows tree-sitter-java version
cat package.json 2>/dev/null || cat package-lock.json 2>/dev/null | head -50Repository: DanielCardonaRojas/codemark Length of output: 53 🏁 Script executed: # Look for tree-sitter config files or dependencies
rg -i "tree.sitter|grammar" --type json --type toml --type yaml | head -20Repository: DanielCardonaRojas/codemark Length of output: 963 🏁 Script executed: # Check if there's a .tree-sitter or similar directory
find . -type d -name "*tree*" -o -name "*grammar*"Repository: DanielCardonaRojas/codemark Length of output: 53 🏁 Script executed: # Search for any comments or documentation in the markdown files about node names
rg "node.*type|grammar|switch" extras/skills/codemark/queries/java.md -B 2 -A 2Repository: DanielCardonaRojas/codemark Length of output: 162 🏁 Script executed: # Look at how conditions are used in other query patterns (comparison check)
rg "condition:" extras/skills/codemark/queries/java.mdRepository: DanielCardonaRojas/codemark Length of output: 148 🌐 Web query:
💡 Result: In tree-sitter-java version 0.23.x (latest v0.23.5 as of Dec 2024), the grammar supports both traditional and enhanced switch statements/expressions from Java 14+ (PR Citations:
🌐 Web query:
💡 Result: In tree-sitter-java, the enhanced switch construct is represented by the node type "switch_construct" (it’s both an expression and a statement), rather than separate node types named "switch_expression" or "switch_statement". So, for your query: - switch_expression node type: not found as a distinct node type name in tree-sitter-java; the grammar uses switch_construct instead. - switch_statement node type: not found as a distinct node type name in tree-sitter-java; the grammar uses switch_construct instead. The related internal node names mentioned in the grammar update include "switch_block" and "switch_line" / "arrow_switch_line" (for the traditional and arrow forms of cases). Citations:
🌐 Web query:
💡 Result: The tree-sitter-java grammar defines a "switch_construct" node type for enhanced switch statements/expressions (introduced in Java 14+). This node appears in src/node-types.json, which is auto-generated from grammar.js via tree-sitter generate. No search results provided the exact JSON entry for "switch_construct" fields, as the file content is not directly quoted in snippets. However, Tree-sitter node types with fields are defined in grammar.js using field(name, rule) syntax, which populates the "fields" object in node-types.json with keys as field names. From PR Citations:
🌐 Web query:
💡 Result: In the tree-sitter-java grammar, "switch_construct" is the node type for Java switch statements and expressions (introduced for enhanced switch support in Java 14+). It serves as both an expression and statement. No sources explicitly document specific named fields like "value" or "condition" for this node, nor "OR condition". The grammar defines switch_construct with substructures like switch_block containing switch_line or arrow_switch_line, but detailed field names are in src/node-types.json (not directly accessible in results). Pattern matching updates (Java 21) added "guard" nonterminal for when-clauses, but no "value" or "condition" fields mentioned. Likely fields include selector (the switch expression), cases (list of switch labels/rules), and body (switch block), based on typical Tree-sitter Java grammar conventions from PR discussions, but unconfirmed explicitly. Citations:
🌐 Web query:
💡 Result: "switch_construct" is a non-terminal (grammar rule name) in the Tree-sitter Java parser grammar (defined in grammar.scm). It represents the enhanced switch statement/expression syntax introduced in Java 14+, supporting both traditional switch statements and switch expressions with arrow syntax (case L -> expr). It is used in both expression and statement contexts, as noted in development PRs for Tree-sitter Java grammar updates. "SCM" refers to the Scheme-based grammar file format used by Tree-sitter (grammar.scm). The "query scm" likely refers to Tree-sitter queries (in queries/*.scm files), but no direct query named or using "switch_construct" was found; highlights.scm exists but does not reference it explicitly. No connection to general Source Control Management (SCM) tools found. Citations:
🌐 Web query:
💡 Result: The query "queries highlights 'switch'" refers to Tree-sitter syntax highlighting queries for the Java grammar, where "switch" is highlighted as a keyword. Tree-sitter uses .scm files like queries/highlights.scm to define syntax highlighting rules for code editors and tools. In the Java grammar, "switch" is explicitly listed under Citations:
🏁 Script executed: # Check if there are any test cases or examples using switch in the codemark repo
rg "switch" tests/ -A 3 -B 3Repository: DanielCardonaRojas/codemark Length of output: 53 🌐 Web query:
💡 Result: In tree-sitter-java, the highlights.scm file defines syntax highlighting queries for Java code using Tree-sitter queries. The keyword "switch" is highlighted as Citations:
🌐 Web query:
💡 Result: A Tree-sitter query example pattern matching "switch_construct" in the tree-sitter-java grammar is: (switch_construct) Citations:
Correct the Java switch query node type and field. The pattern uses 🔧 Proposed fix-(switch_statement
- condition: (parenthesized_expression
- (identifier) `@val`
- (`#eq`? `@val` "action"))) `@target`
+(switch_construct
+ selector: (identifier) `@val`
+ (`#eq`? `@val` "action")) `@target`📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| ### If Statement | ||||||||||||||||||
|
|
||||||||||||||||||
| Target specific logical decision points: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```scheme | ||||||||||||||||||
| (if_statement | ||||||||||||||||||
| condition: (parenthesized_expression | ||||||||||||||||||
| (identifier) @cond | ||||||||||||||||||
| (#eq? @cond "isAdmin"))) @target | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Module Tagging | ||||||||||||||||||
|
|
||||||||||||||||||
| Java uses `package:<name>` with the full Java package name (dot notation): | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: DanielCardonaRojas/codemark
Length of output: 2652
🏁 Script executed:
# First, explore the markdown file to understand context and other examples head -100 extras/skills/codemark/examples.mdRepository: DanielCardonaRojas/codemark
Length of output: 4405
🏁 Script executed:
Repository: DanielCardonaRojas/codemark
Length of output: 3170
🌐 Web query:
Rust tree-sitter grammar node types member_expression property_identifier💡 Result:
In the tree-sitter Rust grammar (https://github.com/tree-sitter/tree-sitter-rust), method calls like vec.len and field access like obj.field are parsed as field_expression nodes. A field_expression has two fields: receiver (the base expression or scoped_identifier) and field (a field_identifier node containing the property name as text). There are no member_expression or property_identifier node types in this grammar. field_identifier nodes are highlighted as
@propertyin queries/highlights.scm. The full node types are in src/node-types.json (96.7KB file in the repo) and can be used to generate Rust enums via crates like tss-rust or type-sitter. In Rust tree-sitter bindings, access the property name via node.child_by_field_name("field").utf8_text(source_code).to_string.Citations:
Use Rust-compatible query syntax for the
.rsfile example.The query uses JavaScript/TypeScript node types (
member_expression,property_identifier) but targets a Rust file (src/db/repo.rs). In Rust's tree-sitter grammar, method calls usefield_expressionandfield_identifierinstead. This query will not match.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents