mirror of
https://github.com/safishamsi/graphify.git
synced 2026-09-23 22:15:46 +00:00
feat: add VB.NET (.vb) language support via tree-sitter
This commit adds full VB.NET language support to graphify, raising the supported language count from 25 to 26. The implementation follows the established LanguageConfig pattern used by all other tree-sitter-backed extractors. New dependency: - Adds optional extra [vbnet] backed by tree-sitter-vbnet (published to PyPI at https://pypi.org/project/tree-sitter-vbnet/0.1.0/). Install with: pip install graphifyy[vbnet] graphify/detect.py: - Added .vb to CODE_EXTENSIONS so VB.NET files are discovered during corpus ingestion and file-system watching. graphify/extract.py: - _import_vbnet(): import handler for imports_statement nodes; emits imports edges using the namespace_name child text. - _vbnet_extra_walk(): extra-walk hook that intercepts namespace_block nodes, emits a namespace node, and recurses. - _VBNET_CONFIG: full LanguageConfig covering class_block / module_block / structure_block / interface_block as class types; method_declaration / constructor_declaration / property_declaration as function types; invocation call nodes with target/member_access fields. - VB.NET-specific branches in _extract_generic: * Class body: VB.NET has no wrapper body node; inherits and implements are named fields directly on the class_block. Emits separate inherits and implements edges for each base type, stripping generic arguments. * Constructor name: constructor_declaration carries no name field in the grammar; always resolves to New. * Function body: uses the declaration node itself as body sentinel so the call-graph pass can find invocations inside methods. - extract_vbnet(path): public wrapper that delegates to _extract_generic. - _DISPATCH['.vb']: routes .vb files to extract_vbnet. pyproject.toml: - Added vbnet = ['tree-sitter-vbnet'] optional dependency group. - Added 'tree-sitter-vbnet' to the all extra. tests/fixtures/sample.vb: - New fixture file exercising: Imports statements, Namespace block, Interface, Class with Inherits + Implements, Module, Structure, Sub/Function/Property methods, and method calls. tests/test_languages.py: - Added 13 tests covering: no-error, class/interface/module/structure detection, method detection, imports relation, inherits edge, implements edge, and no-dangling-edges invariant. README.md: - Updated language count 25 to 26. - Added VB.NET to language list and file-extension table.
This commit is contained in:
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
Imports System
|
||||
Imports System.Collections.Generic
|
||||
Imports System.Net.Http
|
||||
|
||||
Namespace GraphifyDemo
|
||||
|
||||
Public Interface IProcessor
|
||||
Function Process(items As List(Of String)) As List(Of String)
|
||||
End Interface
|
||||
|
||||
Public Class DataProcessor
|
||||
Inherits BaseProcessor
|
||||
Implements IProcessor
|
||||
|
||||
Private ReadOnly _client As HttpClient
|
||||
|
||||
Public Sub New()
|
||||
_client = New HttpClient()
|
||||
End Sub
|
||||
|
||||
Public Function Process(items As List(Of String)) As List(Of String)
|
||||
Return Validate(items)
|
||||
End Function
|
||||
|
||||
Private Function Validate(items As List(Of String)) As List(Of String)
|
||||
Dim result As New List(Of String)
|
||||
For Each item In items
|
||||
If Not String.IsNullOrEmpty(item) Then
|
||||
result.Add(item.Trim())
|
||||
End If
|
||||
Next
|
||||
Return result
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
Public Module AppHelper
|
||||
|
||||
Public Sub Run(processor As IProcessor)
|
||||
Dim data As New List(Of String)
|
||||
data.Add("hello")
|
||||
processor.Process(data)
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
|
||||
Public Structure Point
|
||||
Implements IComparable
|
||||
|
||||
Public X As Double
|
||||
Public Y As Double
|
||||
|
||||
Public Function CompareTo(obj As Object) As Integer
|
||||
Return 0
|
||||
End Function
|
||||
|
||||
End Structure
|
||||
|
||||
End Namespace
|
||||
+73
-2
@@ -1,11 +1,11 @@
|
||||
"""Tests for language extractors: Java, C, C++, Ruby, C#, Kotlin, Scala, PHP, Swift, Go, Julia."""
|
||||
"""Tests for language extractors: Java, C, C++, Ruby, C#, Kotlin, Scala, PHP, Swift, Go, Julia, VB.NET."""
|
||||
from __future__ import annotations
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from graphify.extract import (
|
||||
extract_java, extract_c, extract_cpp, extract_ruby,
|
||||
extract_csharp, extract_kotlin, extract_scala, extract_php,
|
||||
extract_swift, extract_go, extract_julia,
|
||||
extract_swift, extract_go, extract_julia, extract_vbnet,
|
||||
)
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
@@ -405,6 +405,77 @@ def test_swift_emits_calls():
|
||||
calls = _calls(r)
|
||||
assert any("process" in src and "validate" in tgt for src, tgt in calls)
|
||||
|
||||
# ── VB.NET ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_vbnet_no_error():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert "error" not in r
|
||||
|
||||
def test_vbnet_finds_class():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert any("DataProcessor" in l for l in _labels(r))
|
||||
|
||||
def test_vbnet_finds_interface():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert any("IProcessor" in l for l in _labels(r))
|
||||
|
||||
def test_vbnet_finds_module():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert any("AppHelper" in l for l in _labels(r))
|
||||
|
||||
def test_vbnet_finds_structure():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert any("Point" in l for l in _labels(r))
|
||||
|
||||
def test_vbnet_finds_methods():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
labels = _labels(r)
|
||||
assert any("Process" in l for l in labels)
|
||||
assert any("Validate" in l for l in labels)
|
||||
|
||||
def test_vbnet_finds_sub():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert any("Run" in l for l in _labels(r))
|
||||
|
||||
def test_vbnet_finds_imports():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
assert "imports" in _relations(r)
|
||||
|
||||
def test_vbnet_inherits_edge():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
inherits = [e for e in r["edges"] if e["relation"] == "inherits"]
|
||||
assert len(inherits) >= 1
|
||||
|
||||
def test_vbnet_inherits_baseprovessor():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
node_by_id = {n["id"]: n["label"] for n in r["nodes"]}
|
||||
found = any(
|
||||
"DataProcessor" in node_by_id.get(e["source"], "") and
|
||||
"BaseProcessor" in node_by_id.get(e["target"], "")
|
||||
for e in r["edges"] if e["relation"] == "inherits"
|
||||
)
|
||||
assert found, "DataProcessor should have inherits edge to BaseProcessor"
|
||||
|
||||
def test_vbnet_implements_edge():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
implements = [e for e in r["edges"] if e["relation"] == "implements"]
|
||||
assert len(implements) >= 1
|
||||
|
||||
def test_vbnet_implements_iprocessor():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
node_by_id = {n["id"]: n["label"] for n in r["nodes"]}
|
||||
found = any(
|
||||
"DataProcessor" in node_by_id.get(e["source"], "") and
|
||||
"IProcessor" in node_by_id.get(e["target"], "")
|
||||
for e in r["edges"] if e["relation"] == "implements"
|
||||
)
|
||||
assert found, "DataProcessor should have implements edge to IProcessor"
|
||||
|
||||
def test_vbnet_no_dangling_edges():
|
||||
r = extract_vbnet(FIXTURES / "sample.vb")
|
||||
node_ids = {n["id"] for n in r["nodes"]}
|
||||
for e in r["edges"]:
|
||||
assert e["source"] in node_ids
|
||||
|
||||
# ── Elixir ────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user