tree-sitter-analyzer 0.2.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

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.

Potentially problematic release.


This version of tree-sitter-analyzer might be problematic. Click here for more details.

Files changed (78) hide show
  1. tree_sitter_analyzer/__init__.py +134 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +533 -539
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -13
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -27
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +160 -155
  9. tree_sitter_analyzer/cli/commands/default_command.py +18 -19
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -133
  11. tree_sitter_analyzer/cli/commands/query_command.py +81 -82
  12. tree_sitter_analyzer/cli/commands/structure_command.py +138 -121
  13. tree_sitter_analyzer/cli/commands/summary_command.py +101 -93
  14. tree_sitter_analyzer/cli/commands/table_command.py +235 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +278 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +555 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +559 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +502 -502
  23. tree_sitter_analyzer/encoding_utils.py +456 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +210 -222
  26. tree_sitter_analyzer/formatters/__init__.py +1 -1
  27. tree_sitter_analyzer/formatters/base_formatter.py +167 -168
  28. tree_sitter_analyzer/formatters/formatter_factory.py +78 -74
  29. tree_sitter_analyzer/formatters/java_formatter.py +291 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +259 -235
  31. tree_sitter_analyzer/interfaces/__init__.py +9 -10
  32. tree_sitter_analyzer/interfaces/cli.py +528 -557
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +343 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +187 -219
  37. tree_sitter_analyzer/language_detector.py +398 -400
  38. tree_sitter_analyzer/language_loader.py +224 -228
  39. tree_sitter_analyzer/languages/__init__.py +10 -11
  40. tree_sitter_analyzer/languages/java_plugin.py +1174 -1113
  41. tree_sitter_analyzer/{plugins → languages}/javascript_plugin.py +446 -439
  42. tree_sitter_analyzer/languages/python_plugin.py +747 -712
  43. tree_sitter_analyzer/mcp/__init__.py +31 -32
  44. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  45. tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -213
  46. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +555 -550
  47. tree_sitter_analyzer/mcp/server.py +333 -345
  48. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +654 -557
  50. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -245
  51. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  52. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  53. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  54. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  55. tree_sitter_analyzer/mcp/utils/__init__.py +107 -106
  56. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  57. tree_sitter_analyzer/models.py +470 -481
  58. tree_sitter_analyzer/output_manager.py +255 -264
  59. tree_sitter_analyzer/plugins/__init__.py +280 -334
  60. tree_sitter_analyzer/plugins/base.py +496 -446
  61. tree_sitter_analyzer/plugins/manager.py +379 -355
  62. tree_sitter_analyzer/queries/__init__.py +26 -27
  63. tree_sitter_analyzer/queries/java.py +391 -394
  64. tree_sitter_analyzer/queries/javascript.py +148 -149
  65. tree_sitter_analyzer/queries/python.py +285 -286
  66. tree_sitter_analyzer/queries/typescript.py +229 -230
  67. tree_sitter_analyzer/query_loader.py +257 -260
  68. tree_sitter_analyzer/table_formatter.py +471 -448
  69. tree_sitter_analyzer/utils.py +277 -277
  70. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/METADATA +23 -8
  71. tree_sitter_analyzer-0.4.0.dist-info/RECORD +73 -0
  72. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/entry_points.txt +2 -1
  73. tree_sitter_analyzer/plugins/java_plugin.py +0 -625
  74. tree_sitter_analyzer/plugins/plugin_loader.py +0 -83
  75. tree_sitter_analyzer/plugins/python_plugin.py +0 -598
  76. tree_sitter_analyzer/plugins/registry.py +0 -366
  77. tree_sitter_analyzer-0.2.0.dist-info/RECORD +0 -77
  78. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/WHEEL +0 -0
@@ -1,334 +1,280 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Plugin System for Multi-Language Code Analysis
5
-
6
- This package provides a plugin-based architecture for extending
7
- the tree-sitter analyzer with language-specific parsers and extractors.
8
- """
9
-
10
- from abc import ABC, abstractmethod
11
- from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type
12
-
13
- if TYPE_CHECKING:
14
- import tree_sitter
15
-
16
- from ..models import Class as ModelClass
17
- from ..models import (
18
- CodeElement,
19
- )
20
- from ..models import Function as ModelFunction
21
- from ..models import Import as ModelImport
22
- from ..models import Variable as ModelVariable
23
- from ..utils import log_debug, log_error, log_warning
24
-
25
- __all__ = ["LanguagePlugin", "ElementExtractor", "PluginRegistry", "plugin_registry"]
26
-
27
-
28
- class ElementExtractor(ABC):
29
- """Abstract base class for language-specific element extractors"""
30
-
31
- @abstractmethod
32
- def extract_functions(
33
- self, tree: "tree_sitter.Tree", source_code: str
34
- ) -> List[ModelFunction]:
35
- """Extract function definitions from the syntax tree"""
36
- log_warning("extract_functions not implemented in subclass")
37
- return []
38
-
39
- @abstractmethod
40
- def extract_classes(
41
- self, tree: "tree_sitter.Tree", source_code: str
42
- ) -> List[ModelClass]:
43
- """Extract class definitions from the syntax tree"""
44
- log_warning("extract_classes not implemented in subclass")
45
- return []
46
-
47
- @abstractmethod
48
- def extract_variables(
49
- self, tree: "tree_sitter.Tree", source_code: str
50
- ) -> List[ModelVariable]:
51
- """Extract variable declarations from the syntax tree"""
52
- log_warning("extract_variables not implemented in subclass")
53
- return []
54
-
55
- @abstractmethod
56
- def extract_imports(
57
- self, tree: "tree_sitter.Tree", source_code: str
58
- ) -> List[ModelImport]:
59
- """Extract import statements from the syntax tree"""
60
- log_warning("extract_imports not implemented in subclass")
61
- return []
62
-
63
-
64
- class LanguagePlugin(ABC):
65
- """Abstract base class for language-specific plugins"""
66
-
67
- @abstractmethod
68
- def get_language_name(self) -> str:
69
- """Return the name of the programming language this plugin supports"""
70
- return "unknown"
71
-
72
- @abstractmethod
73
- def get_file_extensions(self) -> List[str]:
74
- """Return list of file extensions this plugin supports"""
75
- return []
76
-
77
- @abstractmethod
78
- def create_extractor(self) -> ElementExtractor:
79
- """Create and return an element extractor for this language"""
80
- return DefaultExtractor()
81
-
82
- def is_applicable(self, file_path: str) -> bool:
83
- """Check if this plugin is applicable for the given file"""
84
- extensions = self.get_file_extensions()
85
- return any(file_path.lower().endswith(ext.lower()) for ext in extensions)
86
-
87
-
88
- class DefaultExtractor(ElementExtractor):
89
- """Default implementation of ElementExtractor with basic functionality"""
90
-
91
- def extract_functions(
92
- self, tree: "tree_sitter.Tree", source_code: str
93
- ) -> List[ModelFunction]:
94
- """Basic function extraction implementation"""
95
- functions: List[ModelFunction] = []
96
- try:
97
- if hasattr(tree, "root_node"):
98
- # Generic function extraction logic
99
- self._traverse_for_functions(
100
- tree.root_node, functions, source_code.splitlines()
101
- )
102
- except Exception as e:
103
- log_error(f"Error in function extraction: {e}")
104
- return functions
105
-
106
- def extract_classes(
107
- self, tree: "tree_sitter.Tree", source_code: str
108
- ) -> List[ModelClass]:
109
- """Basic class extraction implementation"""
110
- classes: List[ModelClass] = []
111
- try:
112
- if hasattr(tree, "root_node"):
113
- # Generic class extraction logic
114
- self._traverse_for_classes(
115
- tree.root_node, classes, source_code.splitlines()
116
- )
117
- except Exception as e:
118
- log_error(f"Error in class extraction: {e}")
119
- return classes
120
-
121
- def extract_variables(
122
- self, tree: "tree_sitter.Tree", source_code: str
123
- ) -> List[ModelVariable]:
124
- """Basic variable extraction implementation"""
125
- variables: List[ModelVariable] = []
126
- try:
127
- if hasattr(tree, "root_node"):
128
- # Generic variable extraction logic
129
- self._traverse_for_variables(
130
- tree.root_node, variables, source_code.splitlines()
131
- )
132
- except Exception as e:
133
- log_error(f"Error in variable extraction: {e}")
134
- return variables
135
-
136
- def extract_imports(
137
- self, tree: "tree_sitter.Tree", source_code: str
138
- ) -> List[ModelImport]:
139
- """Basic import extraction implementation"""
140
- imports: List[ModelImport] = []
141
- try:
142
- if hasattr(tree, "root_node"):
143
- # Generic import extraction logic
144
- self._traverse_for_imports(
145
- tree.root_node, imports, source_code.splitlines()
146
- )
147
- except Exception as e:
148
- log_error(f"Error in import extraction: {e}")
149
- return imports
150
-
151
- def _traverse_for_functions(
152
- self, node: "tree_sitter.Node", functions: List[ModelFunction], lines: List[str]
153
- ) -> None:
154
- """Traverse tree to find function-like nodes"""
155
- if hasattr(node, "type") and "function" in node.type.lower():
156
- try:
157
- func = ModelFunction(
158
- name=self._extract_node_name(node) or "unknown",
159
- start_line=(
160
- node.start_point[0] + 1 if hasattr(node, "start_point") else 0
161
- ),
162
- end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
163
- raw_text="",
164
- language="unknown",
165
- )
166
- functions.append(func)
167
- except Exception as e:
168
- log_debug(f"Failed to extract function: {e}")
169
-
170
- if hasattr(node, "children"):
171
- for child in node.children:
172
- self._traverse_for_functions(child, functions, lines)
173
-
174
- def _traverse_for_classes(
175
- self, node: "tree_sitter.Node", classes: List[ModelClass], lines: List[str]
176
- ) -> None:
177
- """Traverse tree to find class-like nodes"""
178
- if hasattr(node, "type") and "class" in node.type.lower():
179
- try:
180
- cls = ModelClass(
181
- name=self._extract_node_name(node) or "unknown",
182
- start_line=(
183
- node.start_point[0] + 1 if hasattr(node, "start_point") else 0
184
- ),
185
- end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
186
- raw_text="",
187
- language="unknown",
188
- )
189
- classes.append(cls)
190
- except Exception as e:
191
- log_debug(f"Failed to extract class: {e}")
192
-
193
- if hasattr(node, "children"):
194
- for child in node.children:
195
- self._traverse_for_classes(child, classes, lines)
196
-
197
- def _traverse_for_variables(
198
- self, node: "tree_sitter.Node", variables: List[ModelVariable], lines: List[str]
199
- ) -> None:
200
- """Traverse tree to find variable declarations"""
201
- if hasattr(node, "type") and (
202
- "variable" in node.type.lower() or "declaration" in node.type.lower()
203
- ):
204
- try:
205
- var = ModelVariable(
206
- name=self._extract_node_name(node) or "unknown",
207
- start_line=(
208
- node.start_point[0] + 1 if hasattr(node, "start_point") else 0
209
- ),
210
- end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
211
- raw_text="",
212
- language="unknown",
213
- )
214
- variables.append(var)
215
- except Exception as e:
216
- log_debug(f"Failed to extract variable: {e}")
217
-
218
- if hasattr(node, "children"):
219
- for child in node.children:
220
- self._traverse_for_variables(child, variables, lines)
221
-
222
- def _traverse_for_imports(
223
- self, node: "tree_sitter.Node", imports: List[ModelImport], lines: List[str]
224
- ) -> None:
225
- """Traverse tree to find import statements"""
226
- if hasattr(node, "type") and "import" in node.type.lower():
227
- try:
228
- imp = ModelImport(
229
- name=self._extract_node_name(node) or "unknown",
230
- start_line=(
231
- node.start_point[0] + 1 if hasattr(node, "start_point") else 0
232
- ),
233
- end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
234
- raw_text="",
235
- language="unknown",
236
- )
237
- imports.append(imp)
238
- except Exception as e:
239
- log_debug(f"Failed to extract import: {e}")
240
-
241
- if hasattr(node, "children"):
242
- for child in node.children:
243
- self._traverse_for_imports(child, imports, lines)
244
-
245
- def _extract_node_name(self, node: "tree_sitter.Node") -> Optional[str]:
246
- """Extract name from a tree-sitter node"""
247
- try:
248
- # Look for identifier children
249
- if hasattr(node, "children"):
250
- for child in node.children:
251
- if hasattr(child, "type") and child.type == "identifier":
252
- # This would need actual text extraction in real implementation
253
- return f"element_{child.start_point[0]}_{child.start_point[1]}"
254
- return None
255
- except Exception:
256
- return None
257
-
258
-
259
- class PluginRegistry:
260
- """Registry for managing language plugins"""
261
-
262
- def __init__(self) -> None:
263
- self._plugins: Dict[str, LanguagePlugin] = {}
264
- self._extension_map: Dict[str, LanguagePlugin] = {}
265
- self._default_plugin = DefaultLanguagePlugin()
266
-
267
- def register_plugin(self, plugin: LanguagePlugin) -> None:
268
- """Register a language plugin"""
269
- try:
270
- language = plugin.get_language_name()
271
- self._plugins[language] = plugin
272
-
273
- # Register file extensions
274
- for ext in plugin.get_file_extensions():
275
- self._extension_map[ext] = plugin
276
-
277
- log_debug(f"Registered plugin for language: {language}")
278
- except Exception as e:
279
- log_error(f"Failed to register plugin: {e}")
280
-
281
- def get_plugin(self, language: str) -> Optional[LanguagePlugin]:
282
- """Get plugin for specified language"""
283
- return self._plugins.get(language)
284
-
285
- def get_plugin_by_extension(self, extension: str) -> Optional[LanguagePlugin]:
286
- """Get plugin for specified file extension"""
287
- return self._extension_map.get(extension)
288
-
289
- def get_plugin_for_file(self, file_path: str) -> LanguagePlugin:
290
- """Get appropriate plugin for a file"""
291
- for plugin in self._plugins.values():
292
- if plugin.is_applicable(file_path):
293
- return plugin
294
- return self._default_plugin
295
-
296
- def list_supported_languages(self) -> List[str]:
297
- """List all supported languages"""
298
- return list(self._plugins.keys())
299
-
300
- def list_supported_extensions(self) -> List[str]:
301
- """List all supported file extensions"""
302
- return list(self._extension_map.keys())
303
-
304
-
305
- class DefaultLanguagePlugin(LanguagePlugin):
306
- """Default plugin that provides basic functionality for any language"""
307
-
308
- def get_language_name(self) -> str:
309
- return "generic"
310
-
311
- def get_file_extensions(self) -> List[str]:
312
- return [".txt", ".md"] # Fallback extensions
313
-
314
- def create_extractor(self) -> ElementExtractor:
315
- return DefaultExtractor()
316
-
317
-
318
- # Global plugin registry instance
319
- plugin_registry = PluginRegistry()
320
-
321
-
322
- # Auto-load all plugins when the package is imported
323
- try:
324
- from .plugin_loader import (
325
- get_supported_extensions,
326
- get_supported_languages,
327
- load_all_plugins,
328
- )
329
-
330
- # Plugins are automatically loaded when plugin_loader is imported
331
- except ImportError as e:
332
- from ..utils import log_warning
333
-
334
- log_warning(f"Could not load plugin loader: {e}")
1
+ #!/usr/bin/env python3
2
+ """
3
+ Plugin System for Multi-Language Code Analysis
4
+
5
+ This package provides a plugin-based architecture for extending
6
+ the tree-sitter analyzer with language-specific parsers and extractors.
7
+ """
8
+
9
+ from abc import ABC, abstractmethod
10
+ from typing import TYPE_CHECKING
11
+
12
+ if TYPE_CHECKING:
13
+ import tree_sitter
14
+
15
+ # from ..models import (
16
+ # CodeElement,
17
+ # ) # Not used currently
18
+ from ..models import Class as ModelClass
19
+ from ..models import Function as ModelFunction
20
+ from ..models import Import as ModelImport
21
+ from ..models import Variable as ModelVariable
22
+ from ..utils import log_debug, log_error, log_warning
23
+
24
+ __all__ = [
25
+ "LanguagePlugin",
26
+ "ElementExtractor",
27
+ "DefaultExtractor",
28
+ "DefaultLanguagePlugin",
29
+ ]
30
+
31
+
32
+ class ElementExtractor(ABC):
33
+ """Abstract base class for language-specific element extractors"""
34
+
35
+ @abstractmethod
36
+ def extract_functions(
37
+ self, tree: "tree_sitter.Tree", source_code: str
38
+ ) -> list[ModelFunction]:
39
+ """Extract function definitions from the syntax tree"""
40
+ log_warning("extract_functions not implemented in subclass")
41
+ return []
42
+
43
+ @abstractmethod
44
+ def extract_classes(
45
+ self, tree: "tree_sitter.Tree", source_code: str
46
+ ) -> list[ModelClass]:
47
+ """Extract class definitions from the syntax tree"""
48
+ log_warning("extract_classes not implemented in subclass")
49
+ return []
50
+
51
+ @abstractmethod
52
+ def extract_variables(
53
+ self, tree: "tree_sitter.Tree", source_code: str
54
+ ) -> list[ModelVariable]:
55
+ """Extract variable declarations from the syntax tree"""
56
+ log_warning("extract_variables not implemented in subclass")
57
+ return []
58
+
59
+ @abstractmethod
60
+ def extract_imports(
61
+ self, tree: "tree_sitter.Tree", source_code: str
62
+ ) -> list[ModelImport]:
63
+ """Extract import statements from the syntax tree"""
64
+ log_warning("extract_imports not implemented in subclass")
65
+ return []
66
+
67
+
68
+ class LanguagePlugin(ABC):
69
+ """Abstract base class for language-specific plugins"""
70
+
71
+ @abstractmethod
72
+ def get_language_name(self) -> str:
73
+ """Return the name of the programming language this plugin supports"""
74
+ return "unknown"
75
+
76
+ @abstractmethod
77
+ def get_file_extensions(self) -> list[str]:
78
+ """Return list of file extensions this plugin supports"""
79
+ return []
80
+
81
+ @abstractmethod
82
+ def create_extractor(self) -> ElementExtractor:
83
+ """Create and return an element extractor for this language"""
84
+ return DefaultExtractor()
85
+
86
+ def is_applicable(self, file_path: str) -> bool:
87
+ """Check if this plugin is applicable for the given file"""
88
+ extensions = self.get_file_extensions()
89
+ return any(file_path.lower().endswith(ext.lower()) for ext in extensions)
90
+
91
+
92
+ class DefaultExtractor(ElementExtractor):
93
+ """Default implementation of ElementExtractor with basic functionality"""
94
+
95
+ def extract_functions(
96
+ self, tree: "tree_sitter.Tree", source_code: str
97
+ ) -> list[ModelFunction]:
98
+ """Basic function extraction implementation"""
99
+ functions: list[ModelFunction] = []
100
+ try:
101
+ if hasattr(tree, "root_node"):
102
+ # Generic function extraction logic
103
+ self._traverse_for_functions(
104
+ tree.root_node, functions, source_code.splitlines()
105
+ )
106
+ except Exception as e:
107
+ log_error(f"Error in function extraction: {e}")
108
+ return functions
109
+
110
+ def extract_classes(
111
+ self, tree: "tree_sitter.Tree", source_code: str
112
+ ) -> list[ModelClass]:
113
+ """Basic class extraction implementation"""
114
+ classes: list[ModelClass] = []
115
+ try:
116
+ if hasattr(tree, "root_node"):
117
+ # Generic class extraction logic
118
+ self._traverse_for_classes(
119
+ tree.root_node, classes, source_code.splitlines()
120
+ )
121
+ except Exception as e:
122
+ log_error(f"Error in class extraction: {e}")
123
+ return classes
124
+
125
+ def extract_variables(
126
+ self, tree: "tree_sitter.Tree", source_code: str
127
+ ) -> list[ModelVariable]:
128
+ """Basic variable extraction implementation"""
129
+ variables: list[ModelVariable] = []
130
+ try:
131
+ if hasattr(tree, "root_node"):
132
+ # Generic variable extraction logic
133
+ self._traverse_for_variables(
134
+ tree.root_node, variables, source_code.splitlines()
135
+ )
136
+ except Exception as e:
137
+ log_error(f"Error in variable extraction: {e}")
138
+ return variables
139
+
140
+ def extract_imports(
141
+ self, tree: "tree_sitter.Tree", source_code: str
142
+ ) -> list[ModelImport]:
143
+ """Basic import extraction implementation"""
144
+ imports: list[ModelImport] = []
145
+ try:
146
+ if hasattr(tree, "root_node"):
147
+ # Generic import extraction logic
148
+ self._traverse_for_imports(
149
+ tree.root_node, imports, source_code.splitlines()
150
+ )
151
+ except Exception as e:
152
+ log_error(f"Error in import extraction: {e}")
153
+ return imports
154
+
155
+ def _traverse_for_functions(
156
+ self, node: "tree_sitter.Node", functions: list[ModelFunction], lines: list[str]
157
+ ) -> None:
158
+ """Traverse tree to find function-like nodes"""
159
+ if hasattr(node, "type") and "function" in node.type.lower():
160
+ try:
161
+ func = ModelFunction(
162
+ name=self._extract_node_name(node) or "unknown",
163
+ start_line=(
164
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
165
+ ),
166
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
167
+ raw_text="",
168
+ language="unknown",
169
+ )
170
+ functions.append(func)
171
+ except Exception as e:
172
+ log_debug(f"Failed to extract function: {e}")
173
+
174
+ if hasattr(node, "children"):
175
+ for child in node.children:
176
+ self._traverse_for_functions(child, functions, lines)
177
+
178
+ def _traverse_for_classes(
179
+ self, node: "tree_sitter.Node", classes: list[ModelClass], lines: list[str]
180
+ ) -> None:
181
+ """Traverse tree to find class-like nodes"""
182
+ if hasattr(node, "type") and "class" in node.type.lower():
183
+ try:
184
+ cls = ModelClass(
185
+ name=self._extract_node_name(node) or "unknown",
186
+ start_line=(
187
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
188
+ ),
189
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
190
+ raw_text="",
191
+ language="unknown",
192
+ )
193
+ classes.append(cls)
194
+ except Exception as e:
195
+ log_debug(f"Failed to extract class: {e}")
196
+
197
+ if hasattr(node, "children"):
198
+ for child in node.children:
199
+ self._traverse_for_classes(child, classes, lines)
200
+
201
+ def _traverse_for_variables(
202
+ self, node: "tree_sitter.Node", variables: list[ModelVariable], lines: list[str]
203
+ ) -> None:
204
+ """Traverse tree to find variable declarations"""
205
+ if hasattr(node, "type") and (
206
+ "variable" in node.type.lower() or "declaration" in node.type.lower()
207
+ ):
208
+ try:
209
+ var = ModelVariable(
210
+ name=self._extract_node_name(node) or "unknown",
211
+ start_line=(
212
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
213
+ ),
214
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
215
+ raw_text="",
216
+ language="unknown",
217
+ )
218
+ variables.append(var)
219
+ except Exception as e:
220
+ log_debug(f"Failed to extract variable: {e}")
221
+
222
+ if hasattr(node, "children"):
223
+ for child in node.children:
224
+ self._traverse_for_variables(child, variables, lines)
225
+
226
+ def _traverse_for_imports(
227
+ self, node: "tree_sitter.Node", imports: list[ModelImport], lines: list[str]
228
+ ) -> None:
229
+ """Traverse tree to find import statements"""
230
+ if hasattr(node, "type") and "import" in node.type.lower():
231
+ try:
232
+ imp = ModelImport(
233
+ name=self._extract_node_name(node) or "unknown",
234
+ start_line=(
235
+ node.start_point[0] + 1 if hasattr(node, "start_point") else 0
236
+ ),
237
+ end_line=node.end_point[0] + 1 if hasattr(node, "end_point") else 0,
238
+ raw_text="",
239
+ language="unknown",
240
+ )
241
+ imports.append(imp)
242
+ except Exception as e:
243
+ log_debug(f"Failed to extract import: {e}")
244
+
245
+ if hasattr(node, "children"):
246
+ for child in node.children:
247
+ self._traverse_for_imports(child, imports, lines)
248
+
249
+ def _extract_node_name(self, node: "tree_sitter.Node") -> str | None:
250
+ """Extract name from a tree-sitter node"""
251
+ try:
252
+ # Look for identifier children
253
+ if hasattr(node, "children"):
254
+ for child in node.children:
255
+ if hasattr(child, "type") and child.type == "identifier":
256
+ # This would need actual text extraction in real implementation
257
+ return f"element_{child.start_point[0]}_{child.start_point[1]}"
258
+ return None
259
+ except Exception:
260
+ return None
261
+
262
+
263
+ # Legacy PluginRegistry removed - now using PluginManager from .manager
264
+
265
+
266
+ class DefaultLanguagePlugin(LanguagePlugin):
267
+ """Default plugin that provides basic functionality for any language"""
268
+
269
+ def get_language_name(self) -> str:
270
+ return "generic"
271
+
272
+ def get_file_extensions(self) -> list[str]:
273
+ return [".txt", ".md"] # Fallback extensions
274
+
275
+ def create_extractor(self) -> ElementExtractor:
276
+ return DefaultExtractor()
277
+
278
+
279
+ # Legacy plugin registry removed - now using PluginManager
280
+ # from .manager import PluginManager