Class: RubyLsp::Store

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



19
20
21
22
23
# File 'lib/ruby_lsp/store.rb', line 19

def initialize
  @state = T.let({}, T::Hash[String, Document])
  @encoding = T.let(Constant::PositionEncodingKind::UTF8, String)
  @formatter = T.let("auto", String)
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



13
14
15
# File 'lib/ruby_lsp/store.rb', line 13

def encoding
  @encoding
end

#formatterObject

Returns the value of attribute formatter.



16
17
18
# File 'lib/ruby_lsp/store.rb', line 16

def formatter
  @formatter
end

Instance Method Details

#cache_fetch(uri, request_name, &block) ⇒ Object



68
69
70
# File 'lib/ruby_lsp/store.rb', line 68

def cache_fetch(uri, request_name, &block)
  get(uri).cache_fetch(request_name, &block)
end

#clearObject



46
47
48
# File 'lib/ruby_lsp/store.rb', line 46

def clear
  @state.clear
end

#delete(uri) ⇒ Object



56
57
58
# File 'lib/ruby_lsp/store.rb', line 56

def delete(uri)
  @state.delete(uri)
end

#empty?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ruby_lsp/store.rb', line 51

def empty?
  @state.empty?
end

#get(uri) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ruby_lsp/store.rb', line 26

def get(uri)
  document = @state[uri]
  return document unless document.nil?

  set(uri: uri, source: File.binread(CGI.unescape(URI.parse(uri).path)), version: 0)
  T.must(@state[uri])
end

#push_edits(uri:, edits:, version:) ⇒ Object



41
42
43
# File 'lib/ruby_lsp/store.rb', line 41

def push_edits(uri:, edits:, version:)
  T.must(@state[uri]).push_edits(edits, version: version)
end

#set(uri:, source:, version:) ⇒ Object



35
36
37
38
# File 'lib/ruby_lsp/store.rb', line 35

def set(uri:, source:, version:)
  document = Document.new(source: source, version: version, uri: uri, encoding: @encoding)
  @state[uri] = document
end