tree-sitter-analyzer 0.2.0__py3-none-any.whl → 0.3.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 +133 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +531 -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 +232 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +277 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +591 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +557 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +494 -502
  23. tree_sitter_analyzer/encoding_utils.py +458 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +217 -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 +287 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +255 -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 +322 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +180 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +218 -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 +1129 -1113
  41. tree_sitter_analyzer/languages/python_plugin.py +737 -712
  42. tree_sitter_analyzer/mcp/__init__.py +31 -32
  43. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  44. tree_sitter_analyzer/mcp/resources/code_file_resource.py +212 -213
  45. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +560 -550
  46. tree_sitter_analyzer/mcp/server.py +333 -345
  47. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  48. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +621 -557
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +242 -245
  50. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  51. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  52. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  53. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  54. tree_sitter_analyzer/mcp/utils/__init__.py +105 -106
  55. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  56. tree_sitter_analyzer/models.py +470 -481
  57. tree_sitter_analyzer/output_manager.py +261 -264
  58. tree_sitter_analyzer/plugins/__init__.py +333 -334
  59. tree_sitter_analyzer/plugins/base.py +477 -446
  60. tree_sitter_analyzer/plugins/java_plugin.py +608 -625
  61. tree_sitter_analyzer/plugins/javascript_plugin.py +446 -439
  62. tree_sitter_analyzer/plugins/manager.py +362 -355
  63. tree_sitter_analyzer/plugins/plugin_loader.py +85 -83
  64. tree_sitter_analyzer/plugins/python_plugin.py +606 -598
  65. tree_sitter_analyzer/plugins/registry.py +374 -366
  66. tree_sitter_analyzer/queries/__init__.py +26 -27
  67. tree_sitter_analyzer/queries/java.py +391 -394
  68. tree_sitter_analyzer/queries/javascript.py +148 -149
  69. tree_sitter_analyzer/queries/python.py +285 -286
  70. tree_sitter_analyzer/queries/typescript.py +229 -230
  71. tree_sitter_analyzer/query_loader.py +254 -260
  72. tree_sitter_analyzer/table_formatter.py +468 -448
  73. tree_sitter_analyzer/utils.py +277 -277
  74. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/METADATA +21 -6
  75. tree_sitter_analyzer-0.3.0.dist-info/RECORD +77 -0
  76. tree_sitter_analyzer-0.2.0.dist-info/RECORD +0 -77
  77. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/WHEEL +0 -0
  78. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,230 +1,229 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- TypeScript Tree-sitter queries for code analysis.
5
- """
6
-
7
- # Function declarations and expressions
8
- FUNCTIONS = """
9
- (function_declaration
10
- name: (identifier) @function.name
11
- parameters: (formal_parameters) @function.params
12
- return_type: (type_annotation)? @function.return_type
13
- body: (statement_block) @function.body) @function.declaration
14
-
15
- (function_expression
16
- name: (identifier)? @function.name
17
- parameters: (formal_parameters) @function.params
18
- return_type: (type_annotation)? @function.return_type
19
- body: (statement_block) @function.body) @function.expression
20
-
21
- (arrow_function
22
- parameters: (_) @function.params
23
- return_type: (type_annotation)? @function.return_type
24
- body: (_) @function.body) @function.arrow
25
-
26
- (method_definition
27
- name: (_) @function.name
28
- parameters: (formal_parameters) @function.params
29
- return_type: (type_annotation)? @function.return_type
30
- body: (statement_block) @function.body) @method.definition
31
- """
32
-
33
- # Class declarations
34
- CLASSES = """
35
- (class_declaration
36
- name: (type_identifier) @class.name
37
- type_parameters: (type_parameters)? @class.generics
38
- superclass: (class_heritage)? @class.superclass
39
- body: (class_body) @class.body) @class.declaration
40
-
41
- (abstract_class_declaration
42
- name: (type_identifier) @class.name
43
- type_parameters: (type_parameters)? @class.generics
44
- superclass: (class_heritage)? @class.superclass
45
- body: (class_body) @class.body) @class.abstract
46
- """
47
-
48
- # Interface declarations
49
- INTERFACES = """
50
- (interface_declaration
51
- name: (type_identifier) @interface.name
52
- type_parameters: (type_parameters)? @interface.generics
53
- body: (object_type) @interface.body) @interface.declaration
54
- """
55
-
56
- # Type aliases
57
- TYPE_ALIASES = """
58
- (type_alias_declaration
59
- name: (type_identifier) @type.name
60
- type_parameters: (type_parameters)? @type.generics
61
- value: (_) @type.value) @type.alias
62
- """
63
-
64
- # Enum declarations
65
- ENUMS = """
66
- (enum_declaration
67
- name: (identifier) @enum.name
68
- body: (enum_body) @enum.body) @enum.declaration
69
- """
70
-
71
- # Variable declarations with types
72
- VARIABLES = """
73
- (variable_declaration
74
- (variable_declarator
75
- name: (identifier) @variable.name
76
- type: (type_annotation)? @variable.type
77
- value: (_)? @variable.value)) @variable.declaration
78
-
79
- (lexical_declaration
80
- (variable_declarator
81
- name: (identifier) @variable.name
82
- type: (type_annotation)? @variable.type
83
- value: (_)? @variable.value)) @variable.lexical
84
- """
85
-
86
- # Import and export statements
87
- IMPORTS = """
88
- (import_statement
89
- source: (string) @import.source) @import.statement
90
-
91
- (import_statement
92
- (import_clause
93
- (named_imports
94
- (import_specifier
95
- name: (identifier) @import.name
96
- alias: (identifier)? @import.alias))) @import.named
97
-
98
- (import_statement
99
- (import_clause
100
- (import_default_specifier
101
- (identifier) @import.default))) @import.default
102
-
103
- (import_statement
104
- (import_clause
105
- (namespace_import
106
- (identifier) @import.namespace))) @import.namespace
107
-
108
- (type_import
109
- (import_clause
110
- (named_imports
111
- (import_specifier
112
- name: (identifier) @import.type.name
113
- alias: (identifier)? @import.type.alias)))) @import.type
114
- """
115
-
116
- EXPORTS = """
117
- (export_statement
118
- declaration: (_) @export.declaration) @export.statement
119
-
120
- (export_statement
121
- (export_clause
122
- (export_specifier
123
- name: (identifier) @export.name
124
- alias: (identifier)? @export.alias))) @export.named
125
- """
126
-
127
- # Decorators (TypeScript specific)
128
- DECORATORS = """
129
- (decorator
130
- (identifier) @decorator.name) @decorator.simple
131
-
132
- (decorator
133
- (call_expression
134
- function: (identifier) @decorator.name
135
- arguments: (arguments) @decorator.args)) @decorator.call
136
-
137
- (decorator
138
- (member_expression
139
- object: (identifier) @decorator.object
140
- property: (property_identifier) @decorator.name)) @decorator.member
141
- """
142
-
143
- # Generic type parameters
144
- GENERICS = """
145
- (type_parameters
146
- (type_parameter
147
- name: (type_identifier) @generic.name
148
- constraint: (type_annotation)? @generic.constraint
149
- default: (type_annotation)? @generic.default)) @generic.parameter
150
- """
151
-
152
- # Property signatures and method signatures
153
- SIGNATURES = """
154
- (property_signature
155
- name: (_) @property.name
156
- type: (type_annotation) @property.type) @property.signature
157
-
158
- (method_signature
159
- name: (_) @method.name
160
- parameters: (formal_parameters) @method.params
161
- return_type: (type_annotation)? @method.return_type) @method.signature
162
-
163
- (construct_signature
164
- parameters: (formal_parameters) @constructor.params
165
- return_type: (type_annotation)? @constructor.return_type) @constructor.signature
166
- """
167
-
168
- # Comments
169
- COMMENTS = """
170
- (comment) @comment
171
- """
172
-
173
- # All queries combined
174
- ALL_QUERIES = {
175
- "functions": {
176
- "query": FUNCTIONS,
177
- "description": "型アノテーション付きのすべての関数宣言、式、メソッドを検索",
178
- },
179
- "classes": {
180
- "query": CLASSES,
181
- "description": "抽象クラスを含むすべてのクラス宣言を検索",
182
- },
183
- "interfaces": {
184
- "query": INTERFACES,
185
- "description": "すべてのインターフェース宣言を検索",
186
- },
187
- "type_aliases": {
188
- "query": TYPE_ALIASES,
189
- "description": "すべての型エイリアス宣言を検索",
190
- },
191
- "enums": {"query": ENUMS, "description": "すべての列挙型宣言を検索"},
192
- "variables": {
193
- "query": VARIABLES,
194
- "description": "型アノテーション付きのすべての変数宣言を検索",
195
- },
196
- "imports": {
197
- "query": IMPORTS,
198
- "description": "型インポートを含むすべてのインポート文を検索",
199
- },
200
- "exports": {"query": EXPORTS, "description": "すべてのエクスポート文を検索"},
201
- "decorators": {"query": DECORATORS, "description": "すべてのデコレータを検索"},
202
- "generics": {
203
- "query": GENERICS,
204
- "description": "すべてのジェネリック型パラメータを検索",
205
- },
206
- "signatures": {
207
- "query": SIGNATURES,
208
- "description": "プロパティシグネチャ、メソッドシグネチャ、コンストラクタシグネチャを検索",
209
- },
210
- "comments": {"query": COMMENTS, "description": "すべてのコメントを検索"},
211
- }
212
-
213
-
214
- def get_query(name: str) -> str:
215
- """Get a specific query by name."""
216
- if name in ALL_QUERIES:
217
- return ALL_QUERIES[name]["query"]
218
- raise ValueError(
219
- f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
220
- )
221
-
222
-
223
- def get_all_queries() -> dict:
224
- """Get all available queries."""
225
- return ALL_QUERIES
226
-
227
-
228
- def list_queries() -> list:
229
- """List all available query names."""
230
- return list(ALL_QUERIES.keys())
1
+ #!/usr/bin/env python3
2
+ """
3
+ TypeScript Tree-sitter queries for code analysis.
4
+ """
5
+
6
+ # Function declarations and expressions
7
+ FUNCTIONS = """
8
+ (function_declaration
9
+ name: (identifier) @function.name
10
+ parameters: (formal_parameters) @function.params
11
+ return_type: (type_annotation)? @function.return_type
12
+ body: (statement_block) @function.body) @function.declaration
13
+
14
+ (function_expression
15
+ name: (identifier)? @function.name
16
+ parameters: (formal_parameters) @function.params
17
+ return_type: (type_annotation)? @function.return_type
18
+ body: (statement_block) @function.body) @function.expression
19
+
20
+ (arrow_function
21
+ parameters: (_) @function.params
22
+ return_type: (type_annotation)? @function.return_type
23
+ body: (_) @function.body) @function.arrow
24
+
25
+ (method_definition
26
+ name: (_) @function.name
27
+ parameters: (formal_parameters) @function.params
28
+ return_type: (type_annotation)? @function.return_type
29
+ body: (statement_block) @function.body) @method.definition
30
+ """
31
+
32
+ # Class declarations
33
+ CLASSES = """
34
+ (class_declaration
35
+ name: (type_identifier) @class.name
36
+ type_parameters: (type_parameters)? @class.generics
37
+ superclass: (class_heritage)? @class.superclass
38
+ body: (class_body) @class.body) @class.declaration
39
+
40
+ (abstract_class_declaration
41
+ name: (type_identifier) @class.name
42
+ type_parameters: (type_parameters)? @class.generics
43
+ superclass: (class_heritage)? @class.superclass
44
+ body: (class_body) @class.body) @class.abstract
45
+ """
46
+
47
+ # Interface declarations
48
+ INTERFACES = """
49
+ (interface_declaration
50
+ name: (type_identifier) @interface.name
51
+ type_parameters: (type_parameters)? @interface.generics
52
+ body: (object_type) @interface.body) @interface.declaration
53
+ """
54
+
55
+ # Type aliases
56
+ TYPE_ALIASES = """
57
+ (type_alias_declaration
58
+ name: (type_identifier) @type.name
59
+ type_parameters: (type_parameters)? @type.generics
60
+ value: (_) @type.value) @type.alias
61
+ """
62
+
63
+ # Enum declarations
64
+ ENUMS = """
65
+ (enum_declaration
66
+ name: (identifier) @enum.name
67
+ body: (enum_body) @enum.body) @enum.declaration
68
+ """
69
+
70
+ # Variable declarations with types
71
+ VARIABLES = """
72
+ (variable_declaration
73
+ (variable_declarator
74
+ name: (identifier) @variable.name
75
+ type: (type_annotation)? @variable.type
76
+ value: (_)? @variable.value)) @variable.declaration
77
+
78
+ (lexical_declaration
79
+ (variable_declarator
80
+ name: (identifier) @variable.name
81
+ type: (type_annotation)? @variable.type
82
+ value: (_)? @variable.value)) @variable.lexical
83
+ """
84
+
85
+ # Import and export statements
86
+ IMPORTS = """
87
+ (import_statement
88
+ source: (string) @import.source) @import.statement
89
+
90
+ (import_statement
91
+ (import_clause
92
+ (named_imports
93
+ (import_specifier
94
+ name: (identifier) @import.name
95
+ alias: (identifier)? @import.alias))) @import.named
96
+
97
+ (import_statement
98
+ (import_clause
99
+ (import_default_specifier
100
+ (identifier) @import.default))) @import.default
101
+
102
+ (import_statement
103
+ (import_clause
104
+ (namespace_import
105
+ (identifier) @import.namespace))) @import.namespace
106
+
107
+ (type_import
108
+ (import_clause
109
+ (named_imports
110
+ (import_specifier
111
+ name: (identifier) @import.type.name
112
+ alias: (identifier)? @import.type.alias)))) @import.type
113
+ """
114
+
115
+ EXPORTS = """
116
+ (export_statement
117
+ declaration: (_) @export.declaration) @export.statement
118
+
119
+ (export_statement
120
+ (export_clause
121
+ (export_specifier
122
+ name: (identifier) @export.name
123
+ alias: (identifier)? @export.alias))) @export.named
124
+ """
125
+
126
+ # Decorators (TypeScript specific)
127
+ DECORATORS = """
128
+ (decorator
129
+ (identifier) @decorator.name) @decorator.simple
130
+
131
+ (decorator
132
+ (call_expression
133
+ function: (identifier) @decorator.name
134
+ arguments: (arguments) @decorator.args)) @decorator.call
135
+
136
+ (decorator
137
+ (member_expression
138
+ object: (identifier) @decorator.object
139
+ property: (property_identifier) @decorator.name)) @decorator.member
140
+ """
141
+
142
+ # Generic type parameters
143
+ GENERICS = """
144
+ (type_parameters
145
+ (type_parameter
146
+ name: (type_identifier) @generic.name
147
+ constraint: (type_annotation)? @generic.constraint
148
+ default: (type_annotation)? @generic.default)) @generic.parameter
149
+ """
150
+
151
+ # Property signatures and method signatures
152
+ SIGNATURES = """
153
+ (property_signature
154
+ name: (_) @property.name
155
+ type: (type_annotation) @property.type) @property.signature
156
+
157
+ (method_signature
158
+ name: (_) @method.name
159
+ parameters: (formal_parameters) @method.params
160
+ return_type: (type_annotation)? @method.return_type) @method.signature
161
+
162
+ (construct_signature
163
+ parameters: (formal_parameters) @constructor.params
164
+ return_type: (type_annotation)? @constructor.return_type) @constructor.signature
165
+ """
166
+
167
+ # Comments
168
+ COMMENTS = """
169
+ (comment) @comment
170
+ """
171
+
172
+ # All queries combined
173
+ ALL_QUERIES = {
174
+ "functions": {
175
+ "query": FUNCTIONS,
176
+ "description": "型アノテーション付きのすべての関数宣言、式、メソッドを検索",
177
+ },
178
+ "classes": {
179
+ "query": CLASSES,
180
+ "description": "抽象クラスを含むすべてのクラス宣言を検索",
181
+ },
182
+ "interfaces": {
183
+ "query": INTERFACES,
184
+ "description": "すべてのインターフェース宣言を検索",
185
+ },
186
+ "type_aliases": {
187
+ "query": TYPE_ALIASES,
188
+ "description": "すべての型エイリアス宣言を検索",
189
+ },
190
+ "enums": {"query": ENUMS, "description": "すべての列挙型宣言を検索"},
191
+ "variables": {
192
+ "query": VARIABLES,
193
+ "description": "型アノテーション付きのすべての変数宣言を検索",
194
+ },
195
+ "imports": {
196
+ "query": IMPORTS,
197
+ "description": "型インポートを含むすべてのインポート文を検索",
198
+ },
199
+ "exports": {"query": EXPORTS, "description": "すべてのエクスポート文を検索"},
200
+ "decorators": {"query": DECORATORS, "description": "すべてのデコレータを検索"},
201
+ "generics": {
202
+ "query": GENERICS,
203
+ "description": "すべてのジェネリック型パラメータを検索",
204
+ },
205
+ "signatures": {
206
+ "query": SIGNATURES,
207
+ "description": "プロパティシグネチャ、メソッドシグネチャ、コンストラクタシグネチャを検索",
208
+ },
209
+ "comments": {"query": COMMENTS, "description": "すべてのコメントを検索"},
210
+ }
211
+
212
+
213
+ def get_query(name: str) -> str:
214
+ """Get a specific query by name."""
215
+ if name in ALL_QUERIES:
216
+ return ALL_QUERIES[name]["query"]
217
+ raise ValueError(
218
+ f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
219
+ )
220
+
221
+
222
+ def get_all_queries() -> dict:
223
+ """Get all available queries."""
224
+ return ALL_QUERIES
225
+
226
+
227
+ def list_queries() -> list:
228
+ """List all available query names."""
229
+ return list(ALL_QUERIES.keys())