tree-sitter-analyzer 0.1.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 +121 -0
  2. tree_sitter_analyzer/__main__.py +12 -0
  3. tree_sitter_analyzer/api.py +539 -0
  4. tree_sitter_analyzer/cli/__init__.py +39 -0
  5. tree_sitter_analyzer/cli/__main__.py +13 -0
  6. tree_sitter_analyzer/cli/commands/__init__.py +27 -0
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -0
  8. tree_sitter_analyzer/cli/commands/base_command.py +155 -0
  9. tree_sitter_analyzer/cli/commands/default_command.py +19 -0
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +133 -0
  11. tree_sitter_analyzer/cli/commands/query_command.py +82 -0
  12. tree_sitter_analyzer/cli/commands/structure_command.py +121 -0
  13. tree_sitter_analyzer/cli/commands/summary_command.py +93 -0
  14. tree_sitter_analyzer/cli/commands/table_command.py +233 -0
  15. tree_sitter_analyzer/cli/info_commands.py +121 -0
  16. tree_sitter_analyzer/cli_main.py +276 -0
  17. tree_sitter_analyzer/core/__init__.py +20 -0
  18. tree_sitter_analyzer/core/analysis_engine.py +574 -0
  19. tree_sitter_analyzer/core/cache_service.py +330 -0
  20. tree_sitter_analyzer/core/engine.py +560 -0
  21. tree_sitter_analyzer/core/parser.py +288 -0
  22. tree_sitter_analyzer/core/query.py +502 -0
  23. tree_sitter_analyzer/encoding_utils.py +460 -0
  24. tree_sitter_analyzer/exceptions.py +340 -0
  25. tree_sitter_analyzer/file_handler.py +222 -0
  26. tree_sitter_analyzer/formatters/__init__.py +1 -0
  27. tree_sitter_analyzer/formatters/base_formatter.py +168 -0
  28. tree_sitter_analyzer/formatters/formatter_factory.py +74 -0
  29. tree_sitter_analyzer/formatters/java_formatter.py +270 -0
  30. tree_sitter_analyzer/formatters/python_formatter.py +235 -0
  31. tree_sitter_analyzer/interfaces/__init__.py +10 -0
  32. tree_sitter_analyzer/interfaces/cli.py +557 -0
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +319 -0
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +170 -0
  35. tree_sitter_analyzer/interfaces/mcp_server.py +416 -0
  36. tree_sitter_analyzer/java_analyzer.py +219 -0
  37. tree_sitter_analyzer/language_detector.py +400 -0
  38. tree_sitter_analyzer/language_loader.py +228 -0
  39. tree_sitter_analyzer/languages/__init__.py +11 -0
  40. tree_sitter_analyzer/languages/java_plugin.py +1113 -0
  41. tree_sitter_analyzer/languages/python_plugin.py +712 -0
  42. tree_sitter_analyzer/mcp/__init__.py +32 -0
  43. tree_sitter_analyzer/mcp/resources/__init__.py +47 -0
  44. tree_sitter_analyzer/mcp/resources/code_file_resource.py +213 -0
  45. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +550 -0
  46. tree_sitter_analyzer/mcp/server.py +319 -0
  47. tree_sitter_analyzer/mcp/tools/__init__.py +36 -0
  48. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +558 -0
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +245 -0
  50. tree_sitter_analyzer/mcp/tools/base_tool.py +55 -0
  51. tree_sitter_analyzer/mcp/tools/get_positions_tool.py +448 -0
  52. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +302 -0
  53. tree_sitter_analyzer/mcp/tools/table_format_tool.py +359 -0
  54. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +476 -0
  55. tree_sitter_analyzer/mcp/utils/__init__.py +106 -0
  56. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -0
  57. tree_sitter_analyzer/models.py +481 -0
  58. tree_sitter_analyzer/output_manager.py +264 -0
  59. tree_sitter_analyzer/plugins/__init__.py +334 -0
  60. tree_sitter_analyzer/plugins/base.py +446 -0
  61. tree_sitter_analyzer/plugins/java_plugin.py +625 -0
  62. tree_sitter_analyzer/plugins/javascript_plugin.py +439 -0
  63. tree_sitter_analyzer/plugins/manager.py +355 -0
  64. tree_sitter_analyzer/plugins/plugin_loader.py +83 -0
  65. tree_sitter_analyzer/plugins/python_plugin.py +598 -0
  66. tree_sitter_analyzer/plugins/registry.py +366 -0
  67. tree_sitter_analyzer/queries/__init__.py +27 -0
  68. tree_sitter_analyzer/queries/java.py +394 -0
  69. tree_sitter_analyzer/queries/javascript.py +149 -0
  70. tree_sitter_analyzer/queries/python.py +286 -0
  71. tree_sitter_analyzer/queries/typescript.py +230 -0
  72. tree_sitter_analyzer/query_loader.py +260 -0
  73. tree_sitter_analyzer/table_formatter.py +448 -0
  74. tree_sitter_analyzer/utils.py +201 -0
  75. tree_sitter_analyzer-0.1.0.dist-info/METADATA +581 -0
  76. tree_sitter_analyzer-0.1.0.dist-info/RECORD +78 -0
  77. tree_sitter_analyzer-0.1.0.dist-info/WHEEL +4 -0
  78. tree_sitter_analyzer-0.1.0.dist-info/entry_points.txt +8 -0
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Python Tree-sitter queries for code analysis.
5
+ """
6
+
7
+ # Function definitions
8
+ FUNCTIONS = """
9
+ (function_definition
10
+ name: (identifier) @function.name
11
+ parameters: (parameters) @function.params
12
+ body: (block) @function.body) @function.definition
13
+
14
+ (function_definition
15
+ name: (identifier) @function.name
16
+ parameters: (parameters) @function.params
17
+ body: (block) @function.body) @function.async
18
+ """
19
+
20
+ # Class definitions
21
+ CLASSES = """
22
+ (class_definition
23
+ name: (identifier) @class.name
24
+ superclasses: (argument_list)? @class.superclasses
25
+ body: (block) @class.body) @class.definition
26
+ """
27
+
28
+ # Import statements
29
+ IMPORTS = """
30
+ (import_statement
31
+ name: (dotted_name) @import.name) @import.statement
32
+
33
+ (import_from_statement
34
+ module_name: (dotted_name)? @import.module
35
+ name: (dotted_name) @import.name) @import.from
36
+
37
+ (import_from_statement
38
+ module_name: (dotted_name)? @import.module
39
+ name: (import_list) @import.list) @import.from_list
40
+
41
+ (aliased_import
42
+ name: (dotted_name) @import.name
43
+ alias: (identifier) @import.alias) @import.aliased
44
+ """
45
+
46
+ # Variable assignments
47
+ VARIABLES = """
48
+ (assignment
49
+ left: (identifier) @variable.name
50
+ right: (_) @variable.value) @variable.assignment
51
+
52
+ (assignment
53
+ left: (pattern_list) @variable.pattern
54
+ right: (_) @variable.value) @variable.multiple
55
+
56
+ (augmented_assignment
57
+ left: (identifier) @variable.name
58
+ right: (_) @variable.value) @variable.augmented
59
+ """
60
+
61
+ # Decorators
62
+ DECORATORS = """
63
+ (decorator
64
+ (identifier) @decorator.name) @decorator.simple
65
+
66
+ (decorator
67
+ (call
68
+ function: (identifier) @decorator.name
69
+ arguments: (argument_list) @decorator.args)) @decorator.call
70
+
71
+ (decorator
72
+ (attribute
73
+ object: (identifier) @decorator.object
74
+ attribute: (identifier) @decorator.name)) @decorator.attribute
75
+ """
76
+
77
+ # Method definitions
78
+ METHODS = """
79
+ (function_definition
80
+ name: (identifier) @method.name
81
+ parameters: (parameters
82
+ (identifier) @method.self
83
+ . (_)*) @method.params
84
+ body: (block) @method.body) @method.definition
85
+ """
86
+
87
+ # Exception handling
88
+ EXCEPTIONS = """
89
+ (try_statement
90
+ body: (block) @try.body
91
+ (except_clause
92
+ type: (_)? @except.type
93
+ name: (identifier)? @except.name
94
+ body: (block) @except.body)*
95
+ (else_clause
96
+ body: (block) @else.body)?
97
+ (finally_clause
98
+ body: (block) @finally.body)?) @try.statement
99
+
100
+ (raise_statement
101
+ (call
102
+ function: (identifier) @exception.name
103
+ arguments: (argument_list)? @exception.args)) @raise.statement
104
+ """
105
+
106
+ # Comprehensions
107
+ COMPREHENSIONS = """
108
+ (list_comprehension
109
+ body: (_) @comprehension.body
110
+ (for_in_clause
111
+ left: (_) @comprehension.var
112
+ right: (_) @comprehension.iter)) @list.comprehension
113
+
114
+ (dictionary_comprehension
115
+ body: (pair
116
+ key: (_) @comprehension.key
117
+ value: (_) @comprehension.value)
118
+ (for_in_clause
119
+ left: (_) @comprehension.var
120
+ right: (_) @comprehension.iter)) @dict.comprehension
121
+
122
+ (set_comprehension
123
+ body: (_) @comprehension.body
124
+ (for_in_clause
125
+ left: (_) @comprehension.var
126
+ right: (_) @comprehension.iter)) @set.comprehension
127
+ """
128
+
129
+ # Comments and docstrings
130
+ COMMENTS = """
131
+ (comment) @comment
132
+
133
+ (expression_statement
134
+ (string) @docstring)
135
+ """
136
+
137
+ # Type hints and annotations
138
+ TYPE_HINTS = """
139
+ (function_definition
140
+ parameters: (parameters
141
+ (typed_parameter
142
+ type: (_) @type.param)) @type.function_param)
143
+
144
+ (function_definition
145
+ return_type: (_) @type.return) @type.function_return
146
+
147
+ (assignment
148
+ type: (_) @type.variable) @type.variable_annotation
149
+ """
150
+
151
+ # Async/await patterns
152
+ ASYNC_PATTERNS = """
153
+ (function_definition) @async.function
154
+
155
+ (await
156
+ (call) @async.await_call) @async.await
157
+
158
+ (async_for_statement) @async.for
159
+
160
+ (async_with_statement) @async.with
161
+ """
162
+
163
+ # F-strings and string formatting
164
+ STRING_FORMATTING = """
165
+ (formatted_string
166
+ (interpolation) @string.interpolation) @string.fstring
167
+
168
+ (call
169
+ function: (attribute
170
+ object: (_)
171
+ attribute: (identifier) @string.format_method))
172
+ """
173
+
174
+ # Context managers
175
+ CONTEXT_MANAGERS = """
176
+ (with_statement
177
+ (with_clause
178
+ (with_item
179
+ value: (_) @context.manager)) @context.clause) @context.with
180
+
181
+ (async_with_statement
182
+ (with_clause
183
+ (with_item
184
+ value: (_) @context.manager)) @context.clause) @context.async_with
185
+ """
186
+
187
+ # Lambda expressions
188
+ LAMBDAS = """
189
+ (lambda
190
+ parameters: (lambda_parameters)? @lambda.params
191
+ body: (_) @lambda.body) @lambda.expression
192
+ """
193
+
194
+ # Modern Python patterns
195
+ MODERN_PATTERNS = """
196
+ (match_statement
197
+ subject: (_) @match.subject
198
+ body: (case_clause)+ @match.cases) @pattern.match
199
+
200
+ (case_clause
201
+ pattern: (_) @case.pattern
202
+ guard: (_)? @case.guard
203
+ consequence: (block) @case.body) @pattern.case
204
+
205
+ (walrus_operator
206
+ left: (_) @walrus.target
207
+ right: (_) @walrus.value) @assignment.walrus
208
+ """
209
+
210
+ # All queries combined
211
+ ALL_QUERIES = {
212
+ "functions": {
213
+ "query": FUNCTIONS,
214
+ "description": "すべての関数定義(async含む)を検索",
215
+ },
216
+ "classes": {"query": CLASSES, "description": "すべてのクラス定義を検索"},
217
+ "imports": {"query": IMPORTS, "description": "すべてのインポート文を検索"},
218
+ "variables": {"query": VARIABLES, "description": "すべての変数代入を検索"},
219
+ "decorators": {"query": DECORATORS, "description": "すべてのデコレータを検索"},
220
+ "methods": {
221
+ "query": METHODS,
222
+ "description": "クラス内のすべてのメソッド定義を検索",
223
+ },
224
+ "exceptions": {
225
+ "query": EXCEPTIONS,
226
+ "description": "例外処理とraise文を検索",
227
+ },
228
+ "comprehensions": {
229
+ "query": COMPREHENSIONS,
230
+ "description": "リスト、辞書、セット内包表記を検索",
231
+ },
232
+ "comments": {"query": COMMENTS, "description": "コメントとdocstringを検索"},
233
+ "type_hints": {
234
+ "query": TYPE_HINTS,
235
+ "description": "型ヒントとアノテーションを検索",
236
+ },
237
+ "async_patterns": {
238
+ "query": ASYNC_PATTERNS,
239
+ "description": "async/awaitパターンを検索",
240
+ },
241
+ "string_formatting": {
242
+ "query": STRING_FORMATTING,
243
+ "description": "f文字列と文字列フォーマットを検索",
244
+ },
245
+ "context_managers": {
246
+ "query": CONTEXT_MANAGERS,
247
+ "description": "コンテキストマネージャー(with文)を検索",
248
+ },
249
+ "lambdas": {"query": LAMBDAS, "description": "ラムダ式を検索"},
250
+ "modern_patterns": {
251
+ "query": MODERN_PATTERNS,
252
+ "description": "モダンなPythonパターン(match/case、セイウチ演算子)を検索",
253
+ },
254
+ # Convenience aliases
255
+ "function_names": {
256
+ "query": FUNCTIONS,
257
+ "description": "関数のエイリアス - すべての関数定義を検索",
258
+ },
259
+ "class_names": {
260
+ "query": CLASSES,
261
+ "description": "クラスのエイリアス - すべてのクラス定義を検索",
262
+ },
263
+ "all_declarations": {
264
+ "query": FUNCTIONS + "\n\n" + CLASSES + "\n\n" + VARIABLES,
265
+ "description": "すべての関数、クラス、変数宣言を検索",
266
+ },
267
+ }
268
+
269
+
270
+ def get_query(name: str) -> str:
271
+ """Get a specific query by name."""
272
+ if name in ALL_QUERIES:
273
+ return ALL_QUERIES[name]["query"]
274
+ raise ValueError(
275
+ f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
276
+ )
277
+
278
+
279
+ def get_all_queries() -> dict:
280
+ """Get all available queries."""
281
+ return ALL_QUERIES
282
+
283
+
284
+ def list_queries() -> list:
285
+ """List all available query names."""
286
+ return list(ALL_QUERIES.keys())
@@ -0,0 +1,230 @@
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())