Skip to content

Commit 27d3232

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/syntax_suggest] Remove workaround for ripper not lexing the entire source
Maybe ripper fixed it since then. But prism also doesn't have this problem. ruby/syntax_suggest@8bc383b2a4
1 parent 63a90d2 commit 27d3232

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

lib/syntax_suggest/clean_document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module SyntaxSuggest
8686
class CleanDocument
8787
def initialize(source:)
8888
lines = clean_sweep(source: source)
89-
@document = CodeLine.from_source(lines.join, lines: lines)
89+
@document = CodeLine.from_source(lines.join)
9090
end
9191

9292
# Call all of the document "cleaners"

lib/syntax_suggest/code_line.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ class CodeLine
2626

2727
# Returns an array of CodeLine objects
2828
# from the source string
29-
def self.from_source(source, lines: nil)
30-
lines ||= source.lines
31-
lex_array_for_line = LexAll.new(source: source, source_lines: lines).each_with_object(Hash.new { |h, k| h[k] = [] }) { |lex, hash| hash[lex.line] << lex }
32-
lines.map.with_index do |line, index|
29+
def self.from_source(source)
30+
lex_array_for_line = LexAll.new(source: source).each_with_object(Hash.new { |h, k| h[k] = [] }) { |lex, hash| hash[lex.line] << lex }
31+
source.lines.map.with_index do |line, index|
3332
CodeLine.new(
3433
line: line,
3534
index: index,

lib/syntax_suggest/lex_all.rb

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# frozen_string_literal: true
22

33
module SyntaxSuggest
4-
# Ripper.lex is not guaranteed to lex the entire source document
5-
#
6-
# This class guarantees the whole document is lex-ed by iteratively
7-
# lexing the document where ripper stopped.
8-
#
9-
# Prism likely doesn't have the same problem. Once ripper support is removed
10-
# we can likely reduce the complexity here if not remove the whole concept.
4+
# Lexes the whole source and wraps the tokens in `LexValue`.
115
#
126
# Example usage:
137
#
@@ -18,22 +12,8 @@ module SyntaxSuggest
1812
class LexAll
1913
include Enumerable
2014

21-
def initialize(source:, source_lines: nil)
15+
def initialize(source:)
2216
@lex = self.class.lex(source, 1)
23-
lineno = @lex.last[0][0] + 1
24-
source_lines ||= source.lines
25-
last_lineno = source_lines.length
26-
27-
until lineno >= last_lineno
28-
lines = source_lines[lineno..]
29-
30-
@lex.concat(
31-
self.class.lex(lines.join, lineno + 1)
32-
)
33-
34-
lineno = @lex.last[0].first + 1
35-
end
36-
3717
last_lex = nil
3818
@lex.map! { |elem|
3919
last_lex = LexValue.new(elem[0].first, elem[1], elem[2], elem[3], last_lex)

0 commit comments

Comments
 (0)