Class: RubyLsp::Document
- Inherits:
-
Object
show all
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Defined in:
- lib/ruby_lsp/document.rb
Defined Under Namespace
Classes: LanguageId, Scanner
Constant Summary
collapse
- ParseResultType =
type_member
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source:, version:, uri:, encoding: Encoding::UTF_8) ⇒ Document
Returns a new instance of Document.
38
39
40
41
42
43
44
45
46
|
# File 'lib/ruby_lsp/document.rb', line 38
def initialize(source:, version:, uri:, encoding: Encoding::UTF_8)
@cache = T.let({}, T::Hash[String, T.untyped])
@encoding = T.let(encoding, Encoding)
@source = T.let(source, String)
@version = T.let(version, Integer)
@uri = T.let(uri, URI::Generic)
@needs_parsing = T.let(true, T::Boolean)
@parse_result = T.let(parse, ParseResultType)
end
|
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
35
36
37
|
# File 'lib/ruby_lsp/document.rb', line 35
def encoding
@encoding
end
|
#parse_result ⇒ Object
Returns the value of attribute parse_result.
23
24
25
|
# File 'lib/ruby_lsp/document.rb', line 23
def parse_result
@parse_result
end
|
#source ⇒ Object
Returns the value of attribute source.
26
27
28
|
# File 'lib/ruby_lsp/document.rb', line 26
def source
@source
end
|
#uri ⇒ Object
Returns the value of attribute uri.
32
33
34
|
# File 'lib/ruby_lsp/document.rb', line 32
def uri
@uri
end
|
#version ⇒ Object
Returns the value of attribute version.
29
30
31
|
# File 'lib/ruby_lsp/document.rb', line 29
def version
@version
end
|
Instance Method Details
#==(other) ⇒ Object
49
50
51
|
# File 'lib/ruby_lsp/document.rb', line 49
def ==(other)
self.class == other.class && uri == other.uri && @source == other.source
end
|
#cache_fetch(request_name, &block) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/ruby_lsp/document.rb', line 64
def cache_fetch(request_name, &block)
cached = @cache[request_name]
return cached if cached
result = block.call(self)
@cache[request_name] = result
result
end
|
#cache_get(request_name) ⇒ Object
79
80
81
|
# File 'lib/ruby_lsp/document.rb', line 79
def cache_get(request_name)
@cache[request_name]
end
|
#cache_set(request_name, value) ⇒ Object
74
75
76
|
# File 'lib/ruby_lsp/document.rb', line 74
def cache_set(request_name, value)
@cache[request_name] = value
end
|
#create_scanner ⇒ Object
107
108
109
|
# File 'lib/ruby_lsp/document.rb', line 107
def create_scanner
Scanner.new(@source, @encoding)
end
|
#language_id ⇒ Object
54
|
# File 'lib/ruby_lsp/document.rb', line 54
def language_id; end
|
#parse ⇒ Object
101
|
# File 'lib/ruby_lsp/document.rb', line 101
def parse; end
|
#push_edits(edits, version:) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/ruby_lsp/document.rb', line 84
def push_edits(edits, version:)
edits.each do |edit|
range = edit[:range]
scanner = create_scanner
start_position = scanner.find_char_position(range[:start])
end_position = scanner.find_char_position(range[:end])
@source[start_position...end_position] = edit[:text]
end
@version = version
@needs_parsing = true
@cache.clear
end
|
#syntax_error? ⇒ Boolean
104
|
# File 'lib/ruby_lsp/document.rb', line 104
def syntax_error?; end
|