summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/syntax_suggest/clean_document.rb7
-rw-r--r--lib/syntax_suggest/code_line.rb6
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/syntax_suggest/clean_document.rb b/lib/syntax_suggest/clean_document.rb
index b572189259..08a465dfb0 100644
--- a/lib/syntax_suggest/clean_document.rb
+++ b/lib/syntax_suggest/clean_document.rb
@@ -110,7 +110,7 @@ module SyntaxSuggest
@document.join
end
- # Remove comments and whitespace only lines
+ # Remove comments
#
# replace with empty newlines
#
@@ -156,8 +156,9 @@ module SyntaxSuggest
#
def clean_sweep(source:)
source.lines.map do |line|
- if line.match?(/^\s*(#[^{].*)?$/) # https://rubular.com/r/LLE10D8HKMkJvs
- $/
+ if line.match?(/^\s*#([^{].*)?$/) # https://rubular.com/r/LLE10D8HKMkJvs
+ whitespace = /^(?<whitespace>\s*)#([^{].*)?$/.match(line).named_captures["whitespace"] || ""
+ whitespace + $/
else
line
end
diff --git a/lib/syntax_suggest/code_line.rb b/lib/syntax_suggest/code_line.rb
index dc738ab128..d771a2c0dd 100644
--- a/lib/syntax_suggest/code_line.rb
+++ b/lib/syntax_suggest/code_line.rb
@@ -48,11 +48,9 @@ module SyntaxSuggest
strip_line = line.dup
strip_line.lstrip!
- if strip_line.empty?
- @empty = true
- @indent = 0
+ if (@empty = strip_line.empty?)
+ @indent = line.length - 1 # Newline removed from strip_line is not "whitespace"
else
- @empty = false
@indent = line.length - strip_line.length
end