katakata_irb 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 297457c829dac09ddee68c1cc5365acfcc2583e0282fb1070ebae8fa138523ba
4
- data.tar.gz: a45663afa386d4093814a3ea2a49c98cb03e90004e2a42c0dc723f4686500a51
3
+ metadata.gz: 810109ee76180f61c9b3672a8def67d0a32d53ca23b2436c65575457b586bf68
4
+ data.tar.gz: e17ff5c4e226d785031f2b433b35a8763a49e6a254420fcacf96507975dfa70b
5
5
  SHA512:
6
- metadata.gz: e66cd04bba34272f585adb1a6dde686a49d064604a48b1c0d14093474857b30537f6b05dd965eaf7ae822b174e373122479c05a643cc951fe4ecea3009a625c6
7
- data.tar.gz: 4cb475b48b8e73db73340a1a11c97b087f99d2d6159e235d93a8845e4a718e9b18deb4e693d86059ba98bdbecbf41f24c13cb70d969fdd6d18f9cb171c76478b
6
+ metadata.gz: 47f0ea76bdf5a5599d219524346acca935b67d1ea73ed60d55887534bce442fffc8c483590b53cd84754c754b829551d837c38687282c497f2924c3ec616f0ff
7
+ data.tar.gz: f3aec83bbee8f2e889fdcf31eecc85627972511bf1673894d7f45f8a6834e6b52212ec4beb1814e0e8ddd705cf39eb9370ba78ff395d288caadcaa07008ebed8
@@ -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 method == :require
23
- IRB::InputCompletor.retrieve_files_to_require_from_load_path
23
+ if IRB.const_defined? :InputCompletor # IRB::VERSION <= 1.8.1
24
+ path_completor = IRB::InputCompletor
25
+ elsif IRB.const_defined? :RegexpCompletor # IRB::VERSION >= 1.8.2
26
+ path_completor = IRB::RegexpCompletor.new
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
- IRB::InputCompletor.retrieve_files_to_require_relative_from_current_dir
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
- IRB::InputCompletor.singleton_class.prepend Module.new{
65
- def retrieve_completion_data(input, doc_namespace: false, **)
66
- return super unless doc_namespace
67
- name = input[/[a-zA-Z_0-9]+[!?=]?\z/]
68
- method_doc = -> type do
69
- type = type.types.find { _1.all_methods.include? name.to_sym }
70
- if type in KatakataIrb::Types::SingletonType
71
- "#{KatakataIrb::Types.class_name_of(type.module_or_class)}.#{name}"
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
- call_or_const_doc = -> type do
77
- if name =~ /\A[A-Z]/
78
- type = type.types.grep(KatakataIrb::Types::SingletonType).find { _1.module_or_class.const_defined?(name) }
79
- type.module_or_class == Object ? name : "#{KatakataIrb::Types.class_name_of(type.module_or_class)}::#{name}" if type
80
- else
81
- method_doc.call(type)
82
- end
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
- case KatakataIrb::Completor.prev_analyze_result
86
- in [:call_or_const, type, _name, _self_call]
87
- call_or_const_doc.call type
88
- in [:const, type, _name]
89
- # when prev_analyze_result is const, current analyze result might be call
90
- call_or_const_doc.call type
91
- in [:gvar, _name]
92
- name
93
- in [:call, type, _name, _self_call]
94
- method_doc.call type
95
- in [:lvar_or_method, _name, scope]
96
- method_doc.call scope.self_type unless scope.local_variables.include?(name)
97
- else
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? :InputCompletor # IRB::VERSION <= 1.8.1
107
+ IRB::InputCompletor::CompletionProc.define_singleton_method :call do |*args|
108
+ completion_proc.call(*args)
109
+ end
110
+ IRB::InputCompletor.singleton_class.prepend(
111
+ Module.new do
112
+ define_method :retrieve_completion_data do |input, doc_namespace: false, **kwargs|
113
+ return super(input, doc_namespace: false, **kwargs) unless doc_namespace
114
+ doc_namespace_proc.call input
115
+ end
116
+ end
117
+ )
118
+ elsif IRB.const_defined? :RegexpCompletor # IRB::VERSION >= 1.8.2
119
+ IRB::RegexpCompletor.class_eval do
120
+ define_method :completion_candidates do |preposing, target, postposing, bind:|
121
+ completion_proc.call(target, preposing, postposing)
122
+ end
123
+ define_method :doc_namespace do |_preposing, matched, _postposing, bind:|
124
+ doc_namespace_proc.call matched
98
125
  end
99
126
  end
100
- }
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KatakataIrb
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.11"
5
5
  end
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.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-30 00:00:00.000000000 Z
11
+ date: 2023-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb