Class: TypeProf::LSP::Text
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/typeprof/lsp/text.rb |
Class Method Summary
- .new(path, text, version) ⇒ Text constructor
- .split(str)
Instance Attribute Summary
Instance Method Summary
Constructor Details
.new(path, text, version) ⇒ Text
Class Method Details
.split(str)
[ GitHub ]Instance Attribute Details
#lines (readonly)
[ GitHub ]#path (readonly)
[ GitHub ]#version (readonly)
[ GitHub ]Instance Method Details
#apply_changes(changes, version)
[ GitHub ]# File 'lib/typeprof/lsp/text.rb', line 21
def apply_changes(changes, version) changes.each do |change| change => { range: { start: { line: start_row, character: start_col }, end: { line: end_row , character: end_col } }, text: new_text, } new_text = Text.split(new_text) prefix = @lines[start_row][0...start_col] suffix = @lines[end_row][end_col...] if new_text.size == 1 new_text[0] = prefix + new_text[0] + suffix else new_text[0] = prefix + new_text[0] new_text[-1] = new_text[-1] + suffix end @lines[start_row .. end_row] = new_text end validate @version = version end
#modify_for_completion(changes, pos)
[ GitHub ]# File 'lib/typeprof/lsp/text.rb', line 54
def modify_for_completion(changes, pos) pos => { line: row, character: col } if col >= 2 && @lines[row][col - 1] == "." && (col == 1 || @lines[row][col - 2] != ".") @lines[row][col - 1] = " " yield string, ".", { line: row, character: col - 2} @lines[row][col - 1] = "." elsif col >= 3 && @lines[row][col - 2, 2] == "::" @lines[row][col - 2, 2] = " " yield string, "::", { line: row, character: col - 3 } @lines[row][col - 2, 2] = "::" else yield string, nil, { line: row, character: col } end end
#string
[ GitHub ]# File 'lib/typeprof/lsp/text.rb', line 17
def string @lines.join end
#validate
[ GitHub ]# File 'lib/typeprof/lsp/text.rb', line 49
def validate raise unless @lines[0..-2].all? {|s| s.count("\n") == 1 && s.end_with?("\n") } raise unless @lines[-1].count("\n") == 0 end