-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tab completion appending quote #782
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -578,8 +578,9 @@ def context | |
@context | ||
end | ||
|
||
def retrieve_completion_block(set_completion_quote_character = false) | ||
@line_editor.retrieve_completion_block(set_completion_quote_character) | ||
def retrieve_completion_block(_unused = false) | ||
preposing, target, postposing, _quote = @line_editor.retrieve_completion_block | ||
[preposing, target, postposing] | ||
end | ||
|
||
def call_completion_proc_with_checking_args(pre, target, post) | ||
|
@@ -826,8 +827,7 @@ def editing_mode | |
end.uniq | ||
end | ||
|
||
private def perform_completion(list) | ||
preposing, target, postposing = retrieve_completion_block | ||
private def perform_completion(preposing, target, postposing, quote, list) | ||
candidates = filter_normalize_candidates(target, list) | ||
|
||
case @completion_state | ||
|
@@ -851,7 +851,7 @@ def editing_mode | |
append_character = '' | ||
if candidates.include?(completed) | ||
if candidates.one? | ||
append_character = completion_append_character.to_s | ||
append_character = quote || completion_append_character.to_s | ||
@completion_state = CompletionState::PERFECT_MATCH | ||
elsif @config.show_all_if_ambiguous | ||
menu(candidates) | ||
|
@@ -895,8 +895,8 @@ def dialog_proc_scope_completion_journey_data | |
end | ||
|
||
private def retrieve_completion_journey_state | ||
preposing, target, postposing = retrieve_completion_block | ||
list = call_completion_proc | ||
preposing, target, postposing, quote = retrieve_completion_block | ||
list = call_completion_proc(preposing, target, postposing, quote) | ||
return unless list.is_a?(Array) | ||
|
||
candidates = list.select{ |item| item.start_with?(target) } | ||
|
@@ -1146,9 +1146,8 @@ def scroll_into_view | |
end | ||
end | ||
|
||
def call_completion_proc | ||
result = retrieve_completion_block(true) | ||
pre, target, post = result | ||
def call_completion_proc(pre, target, post, quote) | ||
Reline.core.instance_variable_set(:@completion_quote_character, quote) | ||
result = call_completion_proc_with_checking_args(pre, target, post) | ||
Reline.core.instance_variable_set(:@completion_quote_character, nil) | ||
result | ||
|
@@ -1224,11 +1223,12 @@ def set_current_lines(lines, byte_pointer = nil, line_index = 0) | |
process_auto_indent | ||
end | ||
|
||
def retrieve_completion_block(set_completion_quote_character = false) | ||
def retrieve_completion_block | ||
quote_characters = Reline.completer_quote_characters | ||
before = current_line.byteslice(0, @byte_pointer).grapheme_clusters | ||
quote = nil | ||
unless quote_characters.empty? | ||
# Calcualte closing quote when cursor is at the end of the line | ||
if current_line.bytesize == @byte_pointer && !quote_characters.empty? | ||
escaped = false | ||
before.each do |c| | ||
if escaped | ||
|
@@ -1243,26 +1243,20 @@ def retrieve_completion_block(set_completion_quote_character = false) | |
end | ||
end | ||
end | ||
|
||
word_break_characters = quote_characters + Reline.completer_word_break_characters | ||
break_index = before.rindex { |c| word_break_characters.include?(c) || quote_characters.include?(c) } || -1 | ||
preposing = before.take(break_index + 1).join | ||
target = before.drop(break_index + 1).join | ||
postposing = current_line.byteslice(@byte_pointer, current_line.bytesize - @byte_pointer) | ||
if target | ||
if set_completion_quote_character and quote | ||
Reline.core.instance_variable_set(:@completion_quote_character, quote) | ||
insert_text(quote) # FIXME: should not be here | ||
target += quote | ||
end | ||
end | ||
lines = whole_lines | ||
if @line_index > 0 | ||
preposing = lines[0..(@line_index - 1)].join("\n") + "\n" + preposing | ||
end | ||
if (lines.size - 1) > @line_index | ||
postposing = postposing + "\n" + lines[(@line_index + 1)..-1].join("\n") | ||
end | ||
[preposing.encode(encoding), target.encode(encoding), postposing.encode(encoding)] | ||
[preposing.encode(encoding), target.encode(encoding), postposing.encode(encoding), quote&.encode(encoding)] | ||
end | ||
|
||
def confirm_multiline_termination | ||
|
@@ -1393,10 +1387,11 @@ def finish | |
@completion_occurs = move_completed_list(:down) | ||
else | ||
@completion_journey_state = nil | ||
result = call_completion_proc | ||
pre, target, post, quote = retrieve_completion_block | ||
result = call_completion_proc(pre, target, post, quote) | ||
if result.is_a?(Array) | ||
@completion_occurs = true | ||
perform_completion(result) | ||
perform_completion(pre, target, post, quote, result) | ||
end | ||
end | ||
end | ||
|
@@ -1860,9 +1855,9 @@ def finish | |
if current_line.empty? or @byte_pointer < current_line.bytesize | ||
em_delete(key) | ||
elsif [email protected] # show completed list | ||
result = call_completion_proc | ||
pre, target, post, quote = retrieve_completion_block | ||
result = call_completion_proc(pre, target, post, quote) | ||
if result.is_a?(Array) | ||
_preposing, target = retrieve_completion_block | ||
candidates = filter_normalize_candidates(target, result) | ||
menu(candidates) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we ever use its argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the parameter because this is exposed to DialogProcScope like this.
But code searching in github, it looks like this method is not used yet. I think we can remove the parameter.
I didn't confirm yet, but this method itself might be useful to use from IRB to reduce this hack
https://github.com/ruby/irb/blob/84366b8cdd7ac4c200a03405a07ed074aff5ae23/lib/irb/input-method.rb#L302-L305
Hack that stores
@completion_params
in completion_proc and read it from dialog_proc