reveal-cli 0.2.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.
- plugins/c-header.yaml +89 -0
- plugins/gdscript.yaml +96 -0
- plugins/python.yaml +94 -0
- plugins/yaml.yaml +87 -0
- reveal/__init__.py +20 -0
- reveal/_archive_old_v0.1/analyzers/__init__.py +39 -0
- reveal/_archive_old_v0.1/analyzers/base.py +143 -0
- reveal/_archive_old_v0.1/analyzers/bash_analyzer.py +202 -0
- reveal/_archive_old_v0.1/analyzers/csharp_analyzer.py +167 -0
- reveal/_archive_old_v0.1/analyzers/gdscript_analyzer.py +201 -0
- reveal/_archive_old_v0.1/analyzers/go_analyzer.py +230 -0
- reveal/_archive_old_v0.1/analyzers/javascript_analyzer.py +272 -0
- reveal/_archive_old_v0.1/analyzers/json_analyzer.py +143 -0
- reveal/_archive_old_v0.1/analyzers/markdown_analyzer.py +116 -0
- reveal/_archive_old_v0.1/analyzers/php_analyzer.py +166 -0
- reveal/_archive_old_v0.1/analyzers/python_analyzer.py +118 -0
- reveal/_archive_old_v0.1/analyzers/rust_analyzer.py +202 -0
- reveal/_archive_old_v0.1/analyzers/sql_analyzer.py +534 -0
- reveal/_archive_old_v0.1/analyzers/text_analyzer.py +35 -0
- reveal/_archive_old_v0.1/analyzers/toml_analyzer.py +137 -0
- reveal/_archive_old_v0.1/analyzers/treesitter_base.py +276 -0
- reveal/_archive_old_v0.1/analyzers/yaml_analyzer.py +127 -0
- reveal/_archive_old_v0.1/breadcrumbs.py +147 -0
- reveal/_archive_old_v0.1/cli.py +445 -0
- reveal/_archive_old_v0.1/core.py +136 -0
- reveal/_archive_old_v0.1/detectors.py +29 -0
- reveal/_archive_old_v0.1/formatters.py +272 -0
- reveal/_archive_old_v0.1/grep_filter.py +85 -0
- reveal/_archive_old_v0.1/plugin_loader.py +178 -0
- reveal/_archive_old_v0.1/registry.py +286 -0
- reveal/analyzers/__init__.py +23 -0
- reveal/analyzers/go.py +13 -0
- reveal/analyzers/jupyter_analyzer.py +226 -0
- reveal/analyzers/markdown.py +79 -0
- reveal/analyzers/python.py +15 -0
- reveal/analyzers/rust.py +13 -0
- reveal/analyzers/yaml_json.py +110 -0
- reveal/base.py +193 -0
- reveal/main.py +216 -0
- reveal/tests/__init__.py +1 -0
- reveal/tests/test_json_yaml_line_numbers.py +238 -0
- reveal/tests/test_line_numbers.py +151 -0
- reveal/tests/test_toml_analyzer.py +220 -0
- reveal/tree_view.py +105 -0
- reveal/treesitter.py +282 -0
- reveal_cli-0.2.0.dist-info/METADATA +319 -0
- reveal_cli-0.2.0.dist-info/RECORD +51 -0
- reveal_cli-0.2.0.dist-info/WHEEL +5 -0
- reveal_cli-0.2.0.dist-info/entry_points.txt +2 -0
- reveal_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
- reveal_cli-0.2.0.dist-info/top_level.txt +2 -0
plugins/c-header.yaml
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# C/C++ Header File Plugin
|
|
2
|
+
# Provides 4-level progressive disclosure for .h and .hpp files
|
|
3
|
+
|
|
4
|
+
extension: [.h, .hpp, .hh]
|
|
5
|
+
name: C/C++ Header
|
|
6
|
+
description: C and C++ header files
|
|
7
|
+
icon: 🔧
|
|
8
|
+
|
|
9
|
+
levels:
|
|
10
|
+
0:
|
|
11
|
+
name: metadata
|
|
12
|
+
description: File statistics and basic info
|
|
13
|
+
breadcrumb: "File metadata"
|
|
14
|
+
analyzer: null
|
|
15
|
+
outputs:
|
|
16
|
+
- file_size
|
|
17
|
+
- line_count
|
|
18
|
+
- encoding
|
|
19
|
+
- header_guards
|
|
20
|
+
- include_count
|
|
21
|
+
next_levels: [1, 2, 3]
|
|
22
|
+
|
|
23
|
+
1:
|
|
24
|
+
name: structure
|
|
25
|
+
description: Declarations, includes, and definitions
|
|
26
|
+
breadcrumb: "Includes, defines, declarations"
|
|
27
|
+
analyzer: c_header_structure
|
|
28
|
+
outputs:
|
|
29
|
+
- includes
|
|
30
|
+
- defines
|
|
31
|
+
- typedefs
|
|
32
|
+
- struct_declarations
|
|
33
|
+
- function_declarations
|
|
34
|
+
- class_declarations # C++
|
|
35
|
+
- namespaces # C++
|
|
36
|
+
- template_declarations # C++
|
|
37
|
+
next_levels: [0, 2, 3]
|
|
38
|
+
tips:
|
|
39
|
+
- "Use --grep to find specific declarations"
|
|
40
|
+
- "Level 2 shows function signatures"
|
|
41
|
+
|
|
42
|
+
2:
|
|
43
|
+
name: preview
|
|
44
|
+
description: Declarations with signatures
|
|
45
|
+
breadcrumb: "Function signatures, struct definitions"
|
|
46
|
+
analyzer: c_header_preview
|
|
47
|
+
outputs:
|
|
48
|
+
- function_signatures
|
|
49
|
+
- struct_definitions
|
|
50
|
+
- class_definitions
|
|
51
|
+
- template_definitions
|
|
52
|
+
- documentation_comments
|
|
53
|
+
next_levels: [0, 1, 3]
|
|
54
|
+
tips:
|
|
55
|
+
- "See implementation details with --level 3"
|
|
56
|
+
|
|
57
|
+
3:
|
|
58
|
+
name: full
|
|
59
|
+
description: Complete header content
|
|
60
|
+
breadcrumb: "Complete header file (paged)"
|
|
61
|
+
analyzer: null
|
|
62
|
+
outputs:
|
|
63
|
+
- full_content
|
|
64
|
+
next_levels: [0, 1, 2]
|
|
65
|
+
paging: true
|
|
66
|
+
page_size: 120
|
|
67
|
+
|
|
68
|
+
features:
|
|
69
|
+
grep: true
|
|
70
|
+
context: true
|
|
71
|
+
paging: true
|
|
72
|
+
line_numbers: true
|
|
73
|
+
syntax_highlighting: true
|
|
74
|
+
|
|
75
|
+
analyzer_config:
|
|
76
|
+
parse_comments: true
|
|
77
|
+
extract_doxygen: true
|
|
78
|
+
include_private: true
|
|
79
|
+
detect_extern_c: true
|
|
80
|
+
|
|
81
|
+
examples:
|
|
82
|
+
- command: "reveal mylib.h"
|
|
83
|
+
description: "Show header metadata"
|
|
84
|
+
- command: "reveal mylib.h -l 1"
|
|
85
|
+
description: "Show includes and declarations"
|
|
86
|
+
- command: "reveal mylib.h -l 2 --grep 'process'"
|
|
87
|
+
description: "Preview process function signatures"
|
|
88
|
+
- command: "reveal mylib.h -l 3"
|
|
89
|
+
description: "Show complete header content"
|
plugins/gdscript.yaml
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# GDScript File Plugin
|
|
2
|
+
# Provides 4-level progressive disclosure for Godot Engine .gd files
|
|
3
|
+
|
|
4
|
+
extension: .gd
|
|
5
|
+
name: GDScript
|
|
6
|
+
description: Godot Engine GDScript files with structure analysis
|
|
7
|
+
icon: 🎮
|
|
8
|
+
|
|
9
|
+
# Hierarchical levels - each level reveals more detail
|
|
10
|
+
levels:
|
|
11
|
+
0:
|
|
12
|
+
name: metadata
|
|
13
|
+
description: File statistics and basic information
|
|
14
|
+
breadcrumb: "File metadata (size, encoding, line count)"
|
|
15
|
+
analyzer: null # Built-in metadata analyzer
|
|
16
|
+
outputs:
|
|
17
|
+
- file_size
|
|
18
|
+
- line_count
|
|
19
|
+
- encoding
|
|
20
|
+
- last_modified
|
|
21
|
+
- file_type
|
|
22
|
+
next_levels: [1, 2, 3]
|
|
23
|
+
|
|
24
|
+
1:
|
|
25
|
+
name: structure
|
|
26
|
+
description: Code structure without implementations
|
|
27
|
+
breadcrumb: "Class, signals, exports, functions (structure only)"
|
|
28
|
+
analyzer: gdscript_structure
|
|
29
|
+
outputs:
|
|
30
|
+
- extends
|
|
31
|
+
- class_name
|
|
32
|
+
- signals
|
|
33
|
+
- exports
|
|
34
|
+
- constants
|
|
35
|
+
- variables
|
|
36
|
+
- functions
|
|
37
|
+
next_levels: [0, 2, 3]
|
|
38
|
+
tips:
|
|
39
|
+
- "Use --grep 'function_name' to filter specific functions"
|
|
40
|
+
- "Add --context 2 to see surrounding context"
|
|
41
|
+
|
|
42
|
+
2:
|
|
43
|
+
name: preview
|
|
44
|
+
description: Key elements without full code
|
|
45
|
+
breadcrumb: "Extends, signals, exports, function signatures"
|
|
46
|
+
analyzer: gdscript_preview
|
|
47
|
+
outputs:
|
|
48
|
+
- class_declaration
|
|
49
|
+
- signals
|
|
50
|
+
- exports
|
|
51
|
+
- function_signatures
|
|
52
|
+
- constants
|
|
53
|
+
next_levels: [0, 1, 3]
|
|
54
|
+
tips:
|
|
55
|
+
- "See full implementation with --level 3"
|
|
56
|
+
- "Filter by element name with --grep"
|
|
57
|
+
|
|
58
|
+
3:
|
|
59
|
+
name: full
|
|
60
|
+
description: Complete source code with paging
|
|
61
|
+
breadcrumb: "Complete file contents (paged)"
|
|
62
|
+
analyzer: null # Built-in full content reader
|
|
63
|
+
outputs:
|
|
64
|
+
- full_source
|
|
65
|
+
next_levels: [0, 1, 2]
|
|
66
|
+
paging: true
|
|
67
|
+
page_size: 120
|
|
68
|
+
tips:
|
|
69
|
+
- "Use --grep to filter lines"
|
|
70
|
+
- "Add --context N for surrounding lines"
|
|
71
|
+
|
|
72
|
+
# Features available at all levels
|
|
73
|
+
features:
|
|
74
|
+
grep: true
|
|
75
|
+
context: true
|
|
76
|
+
paging: true
|
|
77
|
+
line_numbers: true
|
|
78
|
+
syntax_highlighting: false
|
|
79
|
+
|
|
80
|
+
# Analyzer configuration
|
|
81
|
+
analyzer_config:
|
|
82
|
+
include_lifecycle_funcs: true
|
|
83
|
+
include_private_vars: true
|
|
84
|
+
parse_comments: true
|
|
85
|
+
extract_signals: true
|
|
86
|
+
|
|
87
|
+
# Examples shown in help text
|
|
88
|
+
examples:
|
|
89
|
+
- command: "reveal player.gd"
|
|
90
|
+
description: "Show file metadata (level 0)"
|
|
91
|
+
- command: "reveal player.gd -l 1"
|
|
92
|
+
description: "Show code structure (signals, exports, functions)"
|
|
93
|
+
- command: "reveal player.gd -l 2 --grep '_ready'"
|
|
94
|
+
description: "Preview _ready function and nearby code"
|
|
95
|
+
- command: "reveal player.gd -l 3 --grep 'func take_damage' -C 5"
|
|
96
|
+
description: "Show take_damage function with 5 lines context"
|
plugins/python.yaml
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Python Source File Plugin
|
|
2
|
+
# Provides 4-level progressive disclosure for .py files
|
|
3
|
+
|
|
4
|
+
extension: .py
|
|
5
|
+
name: Python Source
|
|
6
|
+
description: Python source files with AST-based analysis
|
|
7
|
+
icon: 🐍
|
|
8
|
+
|
|
9
|
+
# Hierarchical levels - each level reveals more detail
|
|
10
|
+
levels:
|
|
11
|
+
0:
|
|
12
|
+
name: metadata
|
|
13
|
+
description: File statistics and basic information
|
|
14
|
+
breadcrumb: "File metadata (size, encoding, line count)"
|
|
15
|
+
analyzer: null # Built-in metadata analyzer
|
|
16
|
+
outputs:
|
|
17
|
+
- file_size
|
|
18
|
+
- line_count
|
|
19
|
+
- encoding
|
|
20
|
+
- last_modified
|
|
21
|
+
- file_type
|
|
22
|
+
next_levels: [1, 2, 3]
|
|
23
|
+
|
|
24
|
+
1:
|
|
25
|
+
name: structure
|
|
26
|
+
description: Code structure without implementations
|
|
27
|
+
breadcrumb: "Imports, classes, functions (structure only)"
|
|
28
|
+
analyzer: python_structure
|
|
29
|
+
outputs:
|
|
30
|
+
- imports
|
|
31
|
+
- classes
|
|
32
|
+
- functions
|
|
33
|
+
- global_variables
|
|
34
|
+
- decorators
|
|
35
|
+
next_levels: [0, 2, 3]
|
|
36
|
+
tips:
|
|
37
|
+
- "Use --grep 'ClassName' to filter specific classes"
|
|
38
|
+
- "Add --context 2 to see surrounding context"
|
|
39
|
+
|
|
40
|
+
2:
|
|
41
|
+
name: preview
|
|
42
|
+
description: Signatures and docstrings without full code
|
|
43
|
+
breadcrumb: "Function signatures, docstrings, type hints"
|
|
44
|
+
analyzer: python_preview
|
|
45
|
+
outputs:
|
|
46
|
+
- function_signatures
|
|
47
|
+
- class_signatures
|
|
48
|
+
- docstrings
|
|
49
|
+
- type_hints
|
|
50
|
+
- decorators_with_args
|
|
51
|
+
next_levels: [0, 1, 3]
|
|
52
|
+
tips:
|
|
53
|
+
- "See full implementation with --level 3"
|
|
54
|
+
- "Filter by function name with --grep"
|
|
55
|
+
|
|
56
|
+
3:
|
|
57
|
+
name: full
|
|
58
|
+
description: Complete source code with paging
|
|
59
|
+
breadcrumb: "Complete file contents (paged)"
|
|
60
|
+
analyzer: null # Built-in full content reader
|
|
61
|
+
outputs:
|
|
62
|
+
- full_source
|
|
63
|
+
next_levels: [0, 1, 2]
|
|
64
|
+
paging: true
|
|
65
|
+
page_size: 120
|
|
66
|
+
tips:
|
|
67
|
+
- "Use --grep to filter lines"
|
|
68
|
+
- "Add --context N for surrounding lines"
|
|
69
|
+
|
|
70
|
+
# Features available at all levels
|
|
71
|
+
features:
|
|
72
|
+
grep: true
|
|
73
|
+
context: true
|
|
74
|
+
paging: true
|
|
75
|
+
line_numbers: true
|
|
76
|
+
syntax_highlighting: true # Future
|
|
77
|
+
|
|
78
|
+
# Analyzer configuration
|
|
79
|
+
analyzer_config:
|
|
80
|
+
include_private: false
|
|
81
|
+
include_magic: false
|
|
82
|
+
parse_docstrings: true
|
|
83
|
+
extract_type_hints: true
|
|
84
|
+
|
|
85
|
+
# Examples shown in help text
|
|
86
|
+
examples:
|
|
87
|
+
- command: "reveal app.py"
|
|
88
|
+
description: "Show file metadata (level 0)"
|
|
89
|
+
- command: "reveal app.py -l 1"
|
|
90
|
+
description: "Show code structure (imports, classes, functions)"
|
|
91
|
+
- command: "reveal app.py -l 2 --grep 'UserManager'"
|
|
92
|
+
description: "Preview UserManager class signatures"
|
|
93
|
+
- command: "reveal app.py -l 3 --grep 'def process' -C 5"
|
|
94
|
+
description: "Show process functions with 5 lines context"
|
plugins/yaml.yaml
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# YAML File Plugin
|
|
2
|
+
# Provides 4-level progressive disclosure for .yaml and .yml files
|
|
3
|
+
|
|
4
|
+
extension: [.yaml, .yml]
|
|
5
|
+
name: YAML
|
|
6
|
+
description: YAML configuration and data files
|
|
7
|
+
icon: 📝
|
|
8
|
+
|
|
9
|
+
levels:
|
|
10
|
+
0:
|
|
11
|
+
name: metadata
|
|
12
|
+
description: File statistics and YAML characteristics
|
|
13
|
+
breadcrumb: "File metadata and YAML info"
|
|
14
|
+
analyzer: null
|
|
15
|
+
outputs:
|
|
16
|
+
- file_size
|
|
17
|
+
- line_count
|
|
18
|
+
- encoding
|
|
19
|
+
- yaml_version
|
|
20
|
+
- has_anchors
|
|
21
|
+
- has_aliases
|
|
22
|
+
- document_count
|
|
23
|
+
next_levels: [1, 2, 3]
|
|
24
|
+
|
|
25
|
+
1:
|
|
26
|
+
name: structure
|
|
27
|
+
description: Top-level keys and nested structure
|
|
28
|
+
breadcrumb: "Top-level keys and nesting depth"
|
|
29
|
+
analyzer: yaml_structure
|
|
30
|
+
outputs:
|
|
31
|
+
- top_level_keys
|
|
32
|
+
- nesting_depth
|
|
33
|
+
- key_paths
|
|
34
|
+
- data_types
|
|
35
|
+
- anchors
|
|
36
|
+
- aliases
|
|
37
|
+
next_levels: [0, 2, 3]
|
|
38
|
+
tips:
|
|
39
|
+
- "Use --grep 'database' to find database config"
|
|
40
|
+
- "See full values with --level 2"
|
|
41
|
+
|
|
42
|
+
2:
|
|
43
|
+
name: preview
|
|
44
|
+
description: Keys with value summaries
|
|
45
|
+
breadcrumb: "Keys with abbreviated values"
|
|
46
|
+
analyzer: yaml_preview
|
|
47
|
+
outputs:
|
|
48
|
+
- keys_with_values
|
|
49
|
+
- value_summaries
|
|
50
|
+
- list_lengths
|
|
51
|
+
- object_keys
|
|
52
|
+
next_levels: [0, 1, 3]
|
|
53
|
+
tips:
|
|
54
|
+
- "Long values are truncated - use level 3 for full content"
|
|
55
|
+
|
|
56
|
+
3:
|
|
57
|
+
name: full
|
|
58
|
+
description: Complete YAML content
|
|
59
|
+
breadcrumb: "Complete YAML content (paged)"
|
|
60
|
+
analyzer: null
|
|
61
|
+
outputs:
|
|
62
|
+
- full_content
|
|
63
|
+
next_levels: [0, 1, 2]
|
|
64
|
+
paging: true
|
|
65
|
+
page_size: 120
|
|
66
|
+
|
|
67
|
+
features:
|
|
68
|
+
grep: true
|
|
69
|
+
context: true
|
|
70
|
+
paging: true
|
|
71
|
+
line_numbers: true
|
|
72
|
+
syntax_highlighting: true
|
|
73
|
+
|
|
74
|
+
analyzer_config:
|
|
75
|
+
max_value_preview_length: 80
|
|
76
|
+
show_types: true
|
|
77
|
+
expand_anchors: false
|
|
78
|
+
|
|
79
|
+
examples:
|
|
80
|
+
- command: "reveal config.yaml"
|
|
81
|
+
description: "Show YAML metadata"
|
|
82
|
+
- command: "reveal config.yaml -l 1"
|
|
83
|
+
description: "Show top-level structure"
|
|
84
|
+
- command: "reveal config.yaml -l 2 --grep 'database'"
|
|
85
|
+
description: "Preview database configuration"
|
|
86
|
+
- command: "reveal config.yaml -l 3"
|
|
87
|
+
description: "Show complete YAML content"
|
reveal/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Reveal - Explore code semantically.
|
|
2
|
+
|
|
3
|
+
A clean, simple tool for progressive code exploration.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "0.2.0"
|
|
7
|
+
|
|
8
|
+
# Import base classes for external use
|
|
9
|
+
from .base import FileAnalyzer, register, get_analyzer
|
|
10
|
+
from .treesitter import TreeSitterAnalyzer
|
|
11
|
+
|
|
12
|
+
# Import all built-in analyzers to register them
|
|
13
|
+
from .analyzers import *
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
'FileAnalyzer',
|
|
17
|
+
'TreeSitterAnalyzer',
|
|
18
|
+
'register',
|
|
19
|
+
'get_analyzer',
|
|
20
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Analyzers for different file types."""
|
|
2
|
+
|
|
3
|
+
from .base import BaseAnalyzer
|
|
4
|
+
from .yaml_analyzer import YAMLAnalyzer
|
|
5
|
+
from .json_analyzer import JSONAnalyzer
|
|
6
|
+
from .toml_analyzer import TOMLAnalyzer
|
|
7
|
+
from .markdown_analyzer import MarkdownAnalyzer
|
|
8
|
+
from .python_analyzer import PythonAnalyzer
|
|
9
|
+
from .sql_analyzer import SQLAnalyzer
|
|
10
|
+
from .text_analyzer import TextAnalyzer
|
|
11
|
+
from .gdscript_analyzer import GDScriptAnalyzer
|
|
12
|
+
|
|
13
|
+
# Tree-sitter based analyzers (optional dependency)
|
|
14
|
+
try:
|
|
15
|
+
from .treesitter_base import TreeSitterAnalyzer
|
|
16
|
+
from .rust_analyzer import RustAnalyzer
|
|
17
|
+
from .csharp_analyzer import CSharpAnalyzer
|
|
18
|
+
from .go_analyzer import GoAnalyzer
|
|
19
|
+
from .javascript_analyzer import JavaScriptAnalyzer
|
|
20
|
+
from .php_analyzer import PHPAnalyzer
|
|
21
|
+
from .bash_analyzer import BashAnalyzer
|
|
22
|
+
TREESITTER_ANALYZERS = [
|
|
23
|
+
'TreeSitterAnalyzer', 'RustAnalyzer', 'CSharpAnalyzer', 'GoAnalyzer',
|
|
24
|
+
'JavaScriptAnalyzer', 'PHPAnalyzer', 'BashAnalyzer'
|
|
25
|
+
]
|
|
26
|
+
except ImportError:
|
|
27
|
+
TREESITTER_ANALYZERS = []
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
'BaseAnalyzer',
|
|
31
|
+
'YAMLAnalyzer',
|
|
32
|
+
'JSONAnalyzer',
|
|
33
|
+
'TOMLAnalyzer',
|
|
34
|
+
'MarkdownAnalyzer',
|
|
35
|
+
'PythonAnalyzer',
|
|
36
|
+
'SQLAnalyzer',
|
|
37
|
+
'TextAnalyzer',
|
|
38
|
+
'GDScriptAnalyzer',
|
|
39
|
+
] + TREESITTER_ANALYZERS
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Base analyzer interface."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Dict, Any, List, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BaseAnalyzer(ABC):
|
|
8
|
+
"""Base class for file type analyzers."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, lines: List[str], file_path: Optional[str] = None,
|
|
11
|
+
focus_start: Optional[int] = None, focus_end: Optional[int] = None,
|
|
12
|
+
**kwargs):
|
|
13
|
+
"""
|
|
14
|
+
Initialize analyzer with file lines.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
lines: List of file lines
|
|
18
|
+
file_path: Path to source file (for composable output)
|
|
19
|
+
focus_start: Optional start line for focused analysis
|
|
20
|
+
focus_end: Optional end line for focused analysis
|
|
21
|
+
**kwargs: Additional arguments for plugin-specific features
|
|
22
|
+
"""
|
|
23
|
+
self.lines = lines
|
|
24
|
+
self.file_path = file_path
|
|
25
|
+
self.focus_start = focus_start
|
|
26
|
+
self.focus_end = focus_end
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def analyze_structure(self) -> Dict[str, Any]:
|
|
30
|
+
"""
|
|
31
|
+
Analyze file structure for Level 1.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Dictionary with structural information
|
|
35
|
+
"""
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def generate_preview(self) -> List[tuple[int, str]]:
|
|
40
|
+
"""
|
|
41
|
+
Generate preview for Level 2.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
List of (line_number, content) tuples
|
|
45
|
+
"""
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
def format_structure(self, structure: Dict[str, Any]) -> Optional[List[str]]:
|
|
49
|
+
"""
|
|
50
|
+
Format structure output for Level 1 display (optional override).
|
|
51
|
+
|
|
52
|
+
Plugins can override this to provide custom formatting without
|
|
53
|
+
modifying core reveal code. If not overridden, reveal uses
|
|
54
|
+
generic formatting based on the structure dictionary.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
structure: The dict returned from analyze_structure()
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
List of formatted output lines, or None to use default formatting
|
|
61
|
+
"""
|
|
62
|
+
return None # Default: use generic formatter
|
|
63
|
+
|
|
64
|
+
# Line number helpers for tool composability
|
|
65
|
+
|
|
66
|
+
def format_location(self, line_num: Optional[int]) -> str:
|
|
67
|
+
"""
|
|
68
|
+
Format a line reference in a composable way.
|
|
69
|
+
|
|
70
|
+
Returns filename:line for tool integration (vim, grep, git, etc.)
|
|
71
|
+
or L0000 format if no file_path available.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
line_num: Line number to format (1-indexed)
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
Formatted location string (e.g., "schema.sql:32" or "L0032")
|
|
78
|
+
"""
|
|
79
|
+
if line_num is None:
|
|
80
|
+
return ""
|
|
81
|
+
if self.file_path:
|
|
82
|
+
return f"{self.file_path}:{line_num}"
|
|
83
|
+
return f"L{line_num:04d}"
|
|
84
|
+
|
|
85
|
+
def with_location(self, text: str, line_num: Optional[int], width: int = 30) -> str:
|
|
86
|
+
"""
|
|
87
|
+
Prepend location reference to text for aligned output.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
text: Text to annotate
|
|
91
|
+
line_num: Line number (1-indexed)
|
|
92
|
+
width: Column width for location (default: 30)
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Formatted string with location prefix
|
|
96
|
+
"""
|
|
97
|
+
loc = self.format_location(line_num)
|
|
98
|
+
if loc:
|
|
99
|
+
return f"{loc:<{width}} {text}"
|
|
100
|
+
return text
|
|
101
|
+
|
|
102
|
+
def find_definition(self, identifier: str, start_line: int = 1,
|
|
103
|
+
case_sensitive: bool = True) -> Optional[int]:
|
|
104
|
+
"""
|
|
105
|
+
Find the line number where an identifier is defined.
|
|
106
|
+
|
|
107
|
+
Searches from start_line through the file for the identifier.
|
|
108
|
+
Useful for automatically annotating structure with line numbers.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
identifier: Text to search for (e.g., table name, function name)
|
|
112
|
+
start_line: Line to start searching from (1-indexed)
|
|
113
|
+
case_sensitive: Whether to match case (default: True)
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Line number (1-indexed) where identifier found, or None
|
|
117
|
+
"""
|
|
118
|
+
search_text = identifier if case_sensitive else identifier.lower()
|
|
119
|
+
for i, line in enumerate(self.lines[start_line - 1:], start_line):
|
|
120
|
+
compare_line = line if case_sensitive else line.lower()
|
|
121
|
+
if search_text in compare_line:
|
|
122
|
+
return i
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
def in_focus_range(self, line_num: int) -> bool:
|
|
126
|
+
"""
|
|
127
|
+
Check if a line number is within the focus range.
|
|
128
|
+
|
|
129
|
+
Useful when user requests specific line range (e.g., reveal file.sql:10-50)
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
line_num: Line number to check (1-indexed)
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
True if in focus range or no focus set, False otherwise
|
|
136
|
+
"""
|
|
137
|
+
if self.focus_start is None and self.focus_end is None:
|
|
138
|
+
return True
|
|
139
|
+
if self.focus_start and line_num < self.focus_start:
|
|
140
|
+
return False
|
|
141
|
+
if self.focus_end and line_num > self.focus_end:
|
|
142
|
+
return False
|
|
143
|
+
return True
|