tree-sitter-analyzer 0.7.0__py3-none-any.whl → 0.8.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 (69) hide show
  1. tree_sitter_analyzer/__init__.py +132 -132
  2. tree_sitter_analyzer/__main__.py +11 -11
  3. tree_sitter_analyzer/api.py +533 -533
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -12
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -26
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +160 -160
  9. tree_sitter_analyzer/cli/commands/default_command.py +18 -18
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -141
  11. tree_sitter_analyzer/cli/commands/query_command.py +81 -81
  12. tree_sitter_analyzer/cli/commands/structure_command.py +138 -138
  13. tree_sitter_analyzer/cli/commands/summary_command.py +101 -101
  14. tree_sitter_analyzer/cli/commands/table_command.py +235 -235
  15. tree_sitter_analyzer/cli/info_commands.py +121 -121
  16. tree_sitter_analyzer/cli_main.py +297 -297
  17. tree_sitter_analyzer/core/__init__.py +15 -15
  18. tree_sitter_analyzer/core/analysis_engine.py +555 -555
  19. tree_sitter_analyzer/core/cache_service.py +320 -320
  20. tree_sitter_analyzer/core/engine.py +566 -566
  21. tree_sitter_analyzer/core/parser.py +293 -293
  22. tree_sitter_analyzer/encoding_utils.py +459 -459
  23. tree_sitter_analyzer/exceptions.py +406 -337
  24. tree_sitter_analyzer/file_handler.py +210 -210
  25. tree_sitter_analyzer/formatters/__init__.py +1 -1
  26. tree_sitter_analyzer/formatters/base_formatter.py +167 -167
  27. tree_sitter_analyzer/formatters/formatter_factory.py +78 -78
  28. tree_sitter_analyzer/interfaces/__init__.py +9 -9
  29. tree_sitter_analyzer/interfaces/cli.py +528 -528
  30. tree_sitter_analyzer/interfaces/cli_adapter.py +343 -343
  31. tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -206
  32. tree_sitter_analyzer/interfaces/mcp_server.py +425 -405
  33. tree_sitter_analyzer/languages/__init__.py +10 -10
  34. tree_sitter_analyzer/languages/javascript_plugin.py +446 -446
  35. tree_sitter_analyzer/languages/python_plugin.py +755 -755
  36. tree_sitter_analyzer/mcp/__init__.py +31 -31
  37. tree_sitter_analyzer/mcp/resources/__init__.py +44 -44
  38. tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -209
  39. tree_sitter_analyzer/mcp/server.py +346 -333
  40. tree_sitter_analyzer/mcp/tools/__init__.py +30 -30
  41. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +654 -654
  42. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -247
  43. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -54
  44. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -300
  45. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -362
  46. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -543
  47. tree_sitter_analyzer/mcp/utils/__init__.py +107 -107
  48. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  49. tree_sitter_analyzer/output_manager.py +253 -253
  50. tree_sitter_analyzer/plugins/__init__.py +280 -280
  51. tree_sitter_analyzer/plugins/base.py +529 -529
  52. tree_sitter_analyzer/plugins/manager.py +379 -379
  53. tree_sitter_analyzer/queries/__init__.py +26 -26
  54. tree_sitter_analyzer/queries/java.py +391 -391
  55. tree_sitter_analyzer/queries/javascript.py +148 -148
  56. tree_sitter_analyzer/queries/python.py +285 -285
  57. tree_sitter_analyzer/queries/typescript.py +229 -229
  58. tree_sitter_analyzer/query_loader.py +257 -257
  59. tree_sitter_analyzer/security/__init__.py +22 -0
  60. tree_sitter_analyzer/security/boundary_manager.py +237 -0
  61. tree_sitter_analyzer/security/regex_checker.py +292 -0
  62. tree_sitter_analyzer/security/validator.py +224 -0
  63. tree_sitter_analyzer/table_formatter.py +652 -589
  64. tree_sitter_analyzer/utils.py +277 -277
  65. {tree_sitter_analyzer-0.7.0.dist-info → tree_sitter_analyzer-0.8.0.dist-info}/METADATA +4 -1
  66. tree_sitter_analyzer-0.8.0.dist-info/RECORD +76 -0
  67. tree_sitter_analyzer-0.7.0.dist-info/RECORD +0 -72
  68. {tree_sitter_analyzer-0.7.0.dist-info → tree_sitter_analyzer-0.8.0.dist-info}/WHEEL +0 -0
  69. {tree_sitter_analyzer-0.7.0.dist-info → tree_sitter_analyzer-0.8.0.dist-info}/entry_points.txt +0 -0
@@ -1,285 +1,285 @@
1
- #!/usr/bin/env python3
2
- """
3
- Python Tree-sitter queries for code analysis.
4
- """
5
-
6
- # Function definitions
7
- FUNCTIONS = """
8
- (function_definition
9
- name: (identifier) @function.name
10
- parameters: (parameters) @function.params
11
- body: (block) @function.body) @function.definition
12
-
13
- (function_definition
14
- name: (identifier) @function.name
15
- parameters: (parameters) @function.params
16
- body: (block) @function.body) @function.async
17
- """
18
-
19
- # Class definitions
20
- CLASSES = """
21
- (class_definition
22
- name: (identifier) @class.name
23
- superclasses: (argument_list)? @class.superclasses
24
- body: (block) @class.body) @class.definition
25
- """
26
-
27
- # Import statements
28
- IMPORTS = """
29
- (import_statement
30
- name: (dotted_name) @import.name) @import.statement
31
-
32
- (import_from_statement
33
- module_name: (dotted_name)? @import.module
34
- name: (dotted_name) @import.name) @import.from
35
-
36
- (import_from_statement
37
- module_name: (dotted_name)? @import.module
38
- name: (import_list) @import.list) @import.from_list
39
-
40
- (aliased_import
41
- name: (dotted_name) @import.name
42
- alias: (identifier) @import.alias) @import.aliased
43
- """
44
-
45
- # Variable assignments
46
- VARIABLES = """
47
- (assignment
48
- left: (identifier) @variable.name
49
- right: (_) @variable.value) @variable.assignment
50
-
51
- (assignment
52
- left: (pattern_list) @variable.pattern
53
- right: (_) @variable.value) @variable.multiple
54
-
55
- (augmented_assignment
56
- left: (identifier) @variable.name
57
- right: (_) @variable.value) @variable.augmented
58
- """
59
-
60
- # Decorators
61
- DECORATORS = """
62
- (decorator
63
- (identifier) @decorator.name) @decorator.simple
64
-
65
- (decorator
66
- (call
67
- function: (identifier) @decorator.name
68
- arguments: (argument_list) @decorator.args)) @decorator.call
69
-
70
- (decorator
71
- (attribute
72
- object: (identifier) @decorator.object
73
- attribute: (identifier) @decorator.name)) @decorator.attribute
74
- """
75
-
76
- # Method definitions
77
- METHODS = """
78
- (function_definition
79
- name: (identifier) @method.name
80
- parameters: (parameters
81
- (identifier) @method.self
82
- . (_)*) @method.params
83
- body: (block) @method.body) @method.definition
84
- """
85
-
86
- # Exception handling
87
- EXCEPTIONS = """
88
- (try_statement
89
- body: (block) @try.body
90
- (except_clause
91
- type: (_)? @except.type
92
- name: (identifier)? @except.name
93
- body: (block) @except.body)*
94
- (else_clause
95
- body: (block) @else.body)?
96
- (finally_clause
97
- body: (block) @finally.body)?) @try.statement
98
-
99
- (raise_statement
100
- (call
101
- function: (identifier) @exception.name
102
- arguments: (argument_list)? @exception.args)) @raise.statement
103
- """
104
-
105
- # Comprehensions
106
- COMPREHENSIONS = """
107
- (list_comprehension
108
- body: (_) @comprehension.body
109
- (for_in_clause
110
- left: (_) @comprehension.var
111
- right: (_) @comprehension.iter)) @list.comprehension
112
-
113
- (dictionary_comprehension
114
- body: (pair
115
- key: (_) @comprehension.key
116
- value: (_) @comprehension.value)
117
- (for_in_clause
118
- left: (_) @comprehension.var
119
- right: (_) @comprehension.iter)) @dict.comprehension
120
-
121
- (set_comprehension
122
- body: (_) @comprehension.body
123
- (for_in_clause
124
- left: (_) @comprehension.var
125
- right: (_) @comprehension.iter)) @set.comprehension
126
- """
127
-
128
- # Comments and docstrings
129
- COMMENTS = """
130
- (comment) @comment
131
-
132
- (expression_statement
133
- (string) @docstring)
134
- """
135
-
136
- # Type hints and annotations
137
- TYPE_HINTS = """
138
- (function_definition
139
- parameters: (parameters
140
- (typed_parameter
141
- type: (_) @type.param)) @type.function_param)
142
-
143
- (function_definition
144
- return_type: (_) @type.return) @type.function_return
145
-
146
- (assignment
147
- type: (_) @type.variable) @type.variable_annotation
148
- """
149
-
150
- # Async/await patterns
151
- ASYNC_PATTERNS = """
152
- (function_definition) @async.function
153
-
154
- (await
155
- (call) @async.await_call) @async.await
156
-
157
- (async_for_statement) @async.for
158
-
159
- (async_with_statement) @async.with
160
- """
161
-
162
- # F-strings and string formatting
163
- STRING_FORMATTING = """
164
- (formatted_string
165
- (interpolation) @string.interpolation) @string.fstring
166
-
167
- (call
168
- function: (attribute
169
- object: (_)
170
- attribute: (identifier) @string.format_method))
171
- """
172
-
173
- # Context managers
174
- CONTEXT_MANAGERS = """
175
- (with_statement
176
- (with_clause
177
- (with_item
178
- value: (_) @context.manager)) @context.clause) @context.with
179
-
180
- (async_with_statement
181
- (with_clause
182
- (with_item
183
- value: (_) @context.manager)) @context.clause) @context.async_with
184
- """
185
-
186
- # Lambda expressions
187
- LAMBDAS = """
188
- (lambda
189
- parameters: (lambda_parameters)? @lambda.params
190
- body: (_) @lambda.body) @lambda.expression
191
- """
192
-
193
- # Modern Python patterns
194
- MODERN_PATTERNS = """
195
- (match_statement
196
- subject: (_) @match.subject
197
- body: (case_clause)+ @match.cases) @pattern.match
198
-
199
- (case_clause
200
- pattern: (_) @case.pattern
201
- guard: (_)? @case.guard
202
- consequence: (block) @case.body) @pattern.case
203
-
204
- (walrus_operator
205
- left: (_) @walrus.target
206
- right: (_) @walrus.value) @assignment.walrus
207
- """
208
-
209
- # All queries combined
210
- ALL_QUERIES = {
211
- "functions": {
212
- "query": FUNCTIONS,
213
- "description": "Search all function definitions (including async)",
214
- },
215
- "classes": {"query": CLASSES, "description": "Search all class definitions"},
216
- "imports": {"query": IMPORTS, "description": "Search all import statements"},
217
- "variables": {"query": VARIABLES, "description": "Search all variable assignments"},
218
- "decorators": {"query": DECORATORS, "description": "Search all decorators"},
219
- "methods": {
220
- "query": METHODS,
221
- "description": "Search all method definitions within classes",
222
- },
223
- "exceptions": {
224
- "query": EXCEPTIONS,
225
- "description": "Search exception handling and raise statements",
226
- },
227
- "comprehensions": {
228
- "query": COMPREHENSIONS,
229
- "description": "Search list, dictionary, and set comprehensions",
230
- },
231
- "comments": {"query": COMMENTS, "description": "Search comments and docstrings"},
232
- "type_hints": {
233
- "query": TYPE_HINTS,
234
- "description": "Search type hints and annotations",
235
- },
236
- "async_patterns": {
237
- "query": ASYNC_PATTERNS,
238
- "description": "Search async/await patterns",
239
- },
240
- "string_formatting": {
241
- "query": STRING_FORMATTING,
242
- "description": "Search f-strings and string formatting",
243
- },
244
- "context_managers": {
245
- "query": CONTEXT_MANAGERS,
246
- "description": "Search context managers (with statements)",
247
- },
248
- "lambdas": {"query": LAMBDAS, "description": "Search lambda expressions"},
249
- "modern_patterns": {
250
- "query": MODERN_PATTERNS,
251
- "description": "Search modern Python patterns (match/case, walrus operator)",
252
- },
253
- # Convenience aliases
254
- "function_names": {
255
- "query": FUNCTIONS,
256
- "description": "Function alias - search all function definitions",
257
- },
258
- "class_names": {
259
- "query": CLASSES,
260
- "description": "Class alias - search all class definitions",
261
- },
262
- "all_declarations": {
263
- "query": FUNCTIONS + "\n\n" + CLASSES + "\n\n" + VARIABLES,
264
- "description": "Search all function, class, and variable declarations",
265
- },
266
- }
267
-
268
-
269
- def get_query(name: str) -> str:
270
- """Get a specific query by name."""
271
- if name in ALL_QUERIES:
272
- return ALL_QUERIES[name]["query"]
273
- raise ValueError(
274
- f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
275
- )
276
-
277
-
278
- def get_all_queries() -> dict:
279
- """Get all available queries."""
280
- return ALL_QUERIES
281
-
282
-
283
- def list_queries() -> list:
284
- """List all available query names."""
285
- return list(ALL_QUERIES.keys())
1
+ #!/usr/bin/env python3
2
+ """
3
+ Python Tree-sitter queries for code analysis.
4
+ """
5
+
6
+ # Function definitions
7
+ FUNCTIONS = """
8
+ (function_definition
9
+ name: (identifier) @function.name
10
+ parameters: (parameters) @function.params
11
+ body: (block) @function.body) @function.definition
12
+
13
+ (function_definition
14
+ name: (identifier) @function.name
15
+ parameters: (parameters) @function.params
16
+ body: (block) @function.body) @function.async
17
+ """
18
+
19
+ # Class definitions
20
+ CLASSES = """
21
+ (class_definition
22
+ name: (identifier) @class.name
23
+ superclasses: (argument_list)? @class.superclasses
24
+ body: (block) @class.body) @class.definition
25
+ """
26
+
27
+ # Import statements
28
+ IMPORTS = """
29
+ (import_statement
30
+ name: (dotted_name) @import.name) @import.statement
31
+
32
+ (import_from_statement
33
+ module_name: (dotted_name)? @import.module
34
+ name: (dotted_name) @import.name) @import.from
35
+
36
+ (import_from_statement
37
+ module_name: (dotted_name)? @import.module
38
+ name: (import_list) @import.list) @import.from_list
39
+
40
+ (aliased_import
41
+ name: (dotted_name) @import.name
42
+ alias: (identifier) @import.alias) @import.aliased
43
+ """
44
+
45
+ # Variable assignments
46
+ VARIABLES = """
47
+ (assignment
48
+ left: (identifier) @variable.name
49
+ right: (_) @variable.value) @variable.assignment
50
+
51
+ (assignment
52
+ left: (pattern_list) @variable.pattern
53
+ right: (_) @variable.value) @variable.multiple
54
+
55
+ (augmented_assignment
56
+ left: (identifier) @variable.name
57
+ right: (_) @variable.value) @variable.augmented
58
+ """
59
+
60
+ # Decorators
61
+ DECORATORS = """
62
+ (decorator
63
+ (identifier) @decorator.name) @decorator.simple
64
+
65
+ (decorator
66
+ (call
67
+ function: (identifier) @decorator.name
68
+ arguments: (argument_list) @decorator.args)) @decorator.call
69
+
70
+ (decorator
71
+ (attribute
72
+ object: (identifier) @decorator.object
73
+ attribute: (identifier) @decorator.name)) @decorator.attribute
74
+ """
75
+
76
+ # Method definitions
77
+ METHODS = """
78
+ (function_definition
79
+ name: (identifier) @method.name
80
+ parameters: (parameters
81
+ (identifier) @method.self
82
+ . (_)*) @method.params
83
+ body: (block) @method.body) @method.definition
84
+ """
85
+
86
+ # Exception handling
87
+ EXCEPTIONS = """
88
+ (try_statement
89
+ body: (block) @try.body
90
+ (except_clause
91
+ type: (_)? @except.type
92
+ name: (identifier)? @except.name
93
+ body: (block) @except.body)*
94
+ (else_clause
95
+ body: (block) @else.body)?
96
+ (finally_clause
97
+ body: (block) @finally.body)?) @try.statement
98
+
99
+ (raise_statement
100
+ (call
101
+ function: (identifier) @exception.name
102
+ arguments: (argument_list)? @exception.args)) @raise.statement
103
+ """
104
+
105
+ # Comprehensions
106
+ COMPREHENSIONS = """
107
+ (list_comprehension
108
+ body: (_) @comprehension.body
109
+ (for_in_clause
110
+ left: (_) @comprehension.var
111
+ right: (_) @comprehension.iter)) @list.comprehension
112
+
113
+ (dictionary_comprehension
114
+ body: (pair
115
+ key: (_) @comprehension.key
116
+ value: (_) @comprehension.value)
117
+ (for_in_clause
118
+ left: (_) @comprehension.var
119
+ right: (_) @comprehension.iter)) @dict.comprehension
120
+
121
+ (set_comprehension
122
+ body: (_) @comprehension.body
123
+ (for_in_clause
124
+ left: (_) @comprehension.var
125
+ right: (_) @comprehension.iter)) @set.comprehension
126
+ """
127
+
128
+ # Comments and docstrings
129
+ COMMENTS = """
130
+ (comment) @comment
131
+
132
+ (expression_statement
133
+ (string) @docstring)
134
+ """
135
+
136
+ # Type hints and annotations
137
+ TYPE_HINTS = """
138
+ (function_definition
139
+ parameters: (parameters
140
+ (typed_parameter
141
+ type: (_) @type.param)) @type.function_param)
142
+
143
+ (function_definition
144
+ return_type: (_) @type.return) @type.function_return
145
+
146
+ (assignment
147
+ type: (_) @type.variable) @type.variable_annotation
148
+ """
149
+
150
+ # Async/await patterns
151
+ ASYNC_PATTERNS = """
152
+ (function_definition) @async.function
153
+
154
+ (await
155
+ (call) @async.await_call) @async.await
156
+
157
+ (async_for_statement) @async.for
158
+
159
+ (async_with_statement) @async.with
160
+ """
161
+
162
+ # F-strings and string formatting
163
+ STRING_FORMATTING = """
164
+ (formatted_string
165
+ (interpolation) @string.interpolation) @string.fstring
166
+
167
+ (call
168
+ function: (attribute
169
+ object: (_)
170
+ attribute: (identifier) @string.format_method))
171
+ """
172
+
173
+ # Context managers
174
+ CONTEXT_MANAGERS = """
175
+ (with_statement
176
+ (with_clause
177
+ (with_item
178
+ value: (_) @context.manager)) @context.clause) @context.with
179
+
180
+ (async_with_statement
181
+ (with_clause
182
+ (with_item
183
+ value: (_) @context.manager)) @context.clause) @context.async_with
184
+ """
185
+
186
+ # Lambda expressions
187
+ LAMBDAS = """
188
+ (lambda
189
+ parameters: (lambda_parameters)? @lambda.params
190
+ body: (_) @lambda.body) @lambda.expression
191
+ """
192
+
193
+ # Modern Python patterns
194
+ MODERN_PATTERNS = """
195
+ (match_statement
196
+ subject: (_) @match.subject
197
+ body: (case_clause)+ @match.cases) @pattern.match
198
+
199
+ (case_clause
200
+ pattern: (_) @case.pattern
201
+ guard: (_)? @case.guard
202
+ consequence: (block) @case.body) @pattern.case
203
+
204
+ (walrus_operator
205
+ left: (_) @walrus.target
206
+ right: (_) @walrus.value) @assignment.walrus
207
+ """
208
+
209
+ # All queries combined
210
+ ALL_QUERIES = {
211
+ "functions": {
212
+ "query": FUNCTIONS,
213
+ "description": "Search all function definitions (including async)",
214
+ },
215
+ "classes": {"query": CLASSES, "description": "Search all class definitions"},
216
+ "imports": {"query": IMPORTS, "description": "Search all import statements"},
217
+ "variables": {"query": VARIABLES, "description": "Search all variable assignments"},
218
+ "decorators": {"query": DECORATORS, "description": "Search all decorators"},
219
+ "methods": {
220
+ "query": METHODS,
221
+ "description": "Search all method definitions within classes",
222
+ },
223
+ "exceptions": {
224
+ "query": EXCEPTIONS,
225
+ "description": "Search exception handling and raise statements",
226
+ },
227
+ "comprehensions": {
228
+ "query": COMPREHENSIONS,
229
+ "description": "Search list, dictionary, and set comprehensions",
230
+ },
231
+ "comments": {"query": COMMENTS, "description": "Search comments and docstrings"},
232
+ "type_hints": {
233
+ "query": TYPE_HINTS,
234
+ "description": "Search type hints and annotations",
235
+ },
236
+ "async_patterns": {
237
+ "query": ASYNC_PATTERNS,
238
+ "description": "Search async/await patterns",
239
+ },
240
+ "string_formatting": {
241
+ "query": STRING_FORMATTING,
242
+ "description": "Search f-strings and string formatting",
243
+ },
244
+ "context_managers": {
245
+ "query": CONTEXT_MANAGERS,
246
+ "description": "Search context managers (with statements)",
247
+ },
248
+ "lambdas": {"query": LAMBDAS, "description": "Search lambda expressions"},
249
+ "modern_patterns": {
250
+ "query": MODERN_PATTERNS,
251
+ "description": "Search modern Python patterns (match/case, walrus operator)",
252
+ },
253
+ # Convenience aliases
254
+ "function_names": {
255
+ "query": FUNCTIONS,
256
+ "description": "Function alias - search all function definitions",
257
+ },
258
+ "class_names": {
259
+ "query": CLASSES,
260
+ "description": "Class alias - search all class definitions",
261
+ },
262
+ "all_declarations": {
263
+ "query": FUNCTIONS + "\n\n" + CLASSES + "\n\n" + VARIABLES,
264
+ "description": "Search all function, class, and variable declarations",
265
+ },
266
+ }
267
+
268
+
269
+ def get_query(name: str) -> str:
270
+ """Get a specific query by name."""
271
+ if name in ALL_QUERIES:
272
+ return ALL_QUERIES[name]["query"]
273
+ raise ValueError(
274
+ f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
275
+ )
276
+
277
+
278
+ def get_all_queries() -> dict:
279
+ """Get all available queries."""
280
+ return ALL_QUERIES
281
+
282
+
283
+ def list_queries() -> list:
284
+ """List all available query names."""
285
+ return list(ALL_QUERIES.keys())