katakata_irb 0.1.10 → 0.1.12
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.
- checksums.yaml +4 -4
- data/lib/katakata_irb/completor.rb +68 -38
- data/lib/katakata_irb/nesting_parser.rb +3 -0
- data/lib/katakata_irb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de309515e451688552ff4758e266ba13966dfef8e62601d0496e3dfc1df256c1
|
4
|
+
data.tar.gz: 9923f034c376e28156f7d4a8552f893a2d70546372f7feea0f0f04e5072d782a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 956de3a2a11d2ab1d877dbc832010fe501c18d1708dc9371e3d7dec9b0a158c66a6a05456660336e72b321662cae4ef764f2f0e065c4f7eab2f542262f59fe43
|
7
|
+
data.tar.gz: 2cc3a0e8829e6567fa34dd9a3218db03a8b51f5733392680b759810395aaab62ed2ca18c2fbc52f67c2608d6c0e6107c22e4546dcfc0c3aa8f055450ee8287f0
|
@@ -12,6 +12,7 @@ module KatakataIrb::Completor
|
|
12
12
|
def self.setup
|
13
13
|
KatakataIrb::Types.preload_in_thread
|
14
14
|
completion_proc = ->(target, preposing = nil, postposing = nil) do
|
15
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
15
16
|
code = "#{preposing}#{target}"
|
16
17
|
irb_context = IRB.conf[:MAIN_CONTEXT]
|
17
18
|
binding = irb_context.workspace.binding
|
@@ -19,10 +20,17 @@ module KatakataIrb::Completor
|
|
19
20
|
KatakataIrb::Completor.prev_analyze_result = result
|
20
21
|
candidates = case result
|
21
22
|
in [:require | :require_relative => method, name]
|
22
|
-
if
|
23
|
-
IRB::
|
23
|
+
if IRB.const_defined? :RegexpCompletor # IRB::VERSION >= 1.8.2
|
24
|
+
path_completor = IRB::RegexpCompletor.new
|
25
|
+
elsif IRB.const_defined? :InputCompletor # IRB::VERSION <= 1.8.1
|
26
|
+
path_completor = IRB::InputCompletor
|
27
|
+
end
|
28
|
+
if !path_completor
|
29
|
+
[]
|
30
|
+
elsif method == :require
|
31
|
+
path_completor.retrieve_files_to_require_from_load_path
|
24
32
|
else
|
25
|
-
|
33
|
+
path_completor.retrieve_files_to_require_relative_from_current_dir
|
26
34
|
end
|
27
35
|
in [:call_or_const, type, name, self_call]
|
28
36
|
((self_call ? type.all_methods: type.methods).map(&:to_s) - HIDDEN_METHODS) | type.constants
|
@@ -51,53 +59,75 @@ module KatakataIrb::Completor
|
|
51
59
|
candidates.map(&:to_s).select { !_1.match?(all_symbols_pattern) && _1.start_with?(name) }.uniq.sort.map do
|
52
60
|
target + _1[name.size..]
|
53
61
|
end
|
54
|
-
end
|
55
|
-
IRB::InputCompletor::CompletionProc.define_singleton_method :call do |*args|
|
56
|
-
completion_proc.call(*args)
|
57
62
|
rescue => e
|
58
63
|
KatakataIrb.last_completion_error = e
|
59
64
|
KatakataIrb.log_puts
|
60
65
|
KatakataIrb.log_puts "#{e.inspect} stored to KatakataIrb.last_completion_error"
|
61
66
|
KatakataIrb.log_puts
|
67
|
+
ensure
|
68
|
+
$VERBOSE = verbose
|
62
69
|
end
|
63
70
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
type
|
70
|
-
|
71
|
-
|
72
|
-
elsif type in KatakataIrb::Types::InstanceType
|
73
|
-
"#{KatakataIrb::Types.class_name_of(type.klass)}##{name}"
|
74
|
-
end
|
71
|
+
doc_namespace_proc = ->(input) do
|
72
|
+
name = input[/[a-zA-Z_0-9]+[!?=]?\z/]
|
73
|
+
method_doc = -> type do
|
74
|
+
type = type.types.find { _1.all_methods.include? name.to_sym }
|
75
|
+
if type in KatakataIrb::Types::SingletonType
|
76
|
+
"#{KatakataIrb::Types.class_name_of(type.module_or_class)}.#{name}"
|
77
|
+
elsif type in KatakataIrb::Types::InstanceType
|
78
|
+
"#{KatakataIrb::Types.class_name_of(type.klass)}##{name}"
|
75
79
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
end
|
81
|
+
call_or_const_doc = -> type do
|
82
|
+
if name =~ /\A[A-Z]/
|
83
|
+
type = type.types.grep(KatakataIrb::Types::SingletonType).find { _1.module_or_class.const_defined?(name) }
|
84
|
+
type.module_or_class == Object ? name : "#{KatakataIrb::Types.class_name_of(type.module_or_class)}::#{name}" if type
|
85
|
+
else
|
86
|
+
method_doc.call(type)
|
83
87
|
end
|
88
|
+
end
|
84
89
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
case KatakataIrb::Completor.prev_analyze_result
|
91
|
+
in [:call_or_const, type, _name, _self_call]
|
92
|
+
call_or_const_doc.call type
|
93
|
+
in [:const, type, _name]
|
94
|
+
# when prev_analyze_result is const, current analyze result might be call
|
95
|
+
call_or_const_doc.call type
|
96
|
+
in [:gvar, _name]
|
97
|
+
name
|
98
|
+
in [:call, type, _name, _self_call]
|
99
|
+
method_doc.call type
|
100
|
+
in [:lvar_or_method, _name, scope]
|
101
|
+
method_doc.call scope.self_type unless scope.local_variables.include?(name)
|
102
|
+
else
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if IRB.const_defined? :RegexpCompletor # IRB::VERSION >= 1.8.2
|
107
|
+
IRB::RegexpCompletor.class_eval do
|
108
|
+
define_method :completion_candidates do |preposing, target, postposing, bind:|
|
109
|
+
completion_proc.call(target, preposing, postposing)
|
110
|
+
end
|
111
|
+
define_method :doc_namespace do |_preposing, matched, _postposing, bind:|
|
112
|
+
doc_namespace_proc.call matched
|
98
113
|
end
|
99
114
|
end
|
100
|
-
|
115
|
+
elsif IRB.const_defined? :InputCompletor # IRB::VERSION <= 1.8.1
|
116
|
+
IRB::InputCompletor::CompletionProc.define_singleton_method :call do |*args|
|
117
|
+
completion_proc.call(*args)
|
118
|
+
end
|
119
|
+
IRB::InputCompletor.singleton_class.prepend(
|
120
|
+
Module.new do
|
121
|
+
define_method :retrieve_completion_data do |input, doc_namespace: false, **kwargs|
|
122
|
+
return super(input, doc_namespace: false, **kwargs) unless doc_namespace
|
123
|
+
doc_namespace_proc.call input
|
124
|
+
end
|
125
|
+
end
|
126
|
+
)
|
127
|
+
else
|
128
|
+
puts 'Cannot activate katakata_irb'
|
129
|
+
end
|
130
|
+
|
101
131
|
setup_type_dialog
|
102
132
|
end
|
103
133
|
|
@@ -9,8 +9,11 @@ module KatakataIrb::NestingParser
|
|
9
9
|
]
|
10
10
|
|
11
11
|
def self.tokenize(code)
|
12
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
12
13
|
tokens = Ripper::Lexer.new(code).scan.reject { ERROR_TOKENS.include? _1.event }
|
13
14
|
KatakataIrb::NestingParser.interpolate_ripper_ignored_tokens code, tokens
|
15
|
+
ensure
|
16
|
+
$VERBOSE = verbose
|
14
17
|
end
|
15
18
|
|
16
19
|
def self.interpolate_ripper_ignored_tokens(code, tokens)
|
data/lib/katakata_irb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katakata_irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tompng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|