katakata_irb 0.1.10 → 0.1.12

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: de309515e451688552ff4758e266ba13966dfef8e62601d0496e3dfc1df256c1
4
+ data.tar.gz: 9923f034c376e28156f7d4a8552f893a2d70546372f7feea0f0f04e5072d782a
5
5
  SHA512:
6
- metadata.gz: e66cd04bba34272f585adb1a6dde686a49d064604a48b1c0d14093474857b30537f6b05dd965eaf7ae822b174e373122479c05a643cc951fe4ecea3009a625c6
7
- data.tar.gz: 4cb475b48b8e73db73340a1a11c97b087f99d2d6159e235d93a8845e4a718e9b18deb4e693d86059ba98bdbecbf41f24c13cb70d969fdd6d18f9cb171c76478b
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 method == :require
23
- IRB::InputCompletor.retrieve_files_to_require_from_load_path
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
- 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? :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)
@@ -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.12"
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.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-08-30 00:00:00.000000000 Z
11
+ date: 2023-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb