Class: RubyLsp::Store

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

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



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

def initialize
  @state = T.let({}, T::Hash[String, Document])
end

Instance Method Details

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



60
61
62
# File 'lib/ruby_lsp/store.rb', line 60

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

#clearObject



38
39
40
# File 'lib/ruby_lsp/store.rb', line 38

def clear
  @state.clear
end

#delete(uri) ⇒ Object



48
49
50
# File 'lib/ruby_lsp/store.rb', line 48

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

#empty?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ruby_lsp/store.rb', line 43

def empty?
  @state.empty?
end

#get(uri) ⇒ Object



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

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

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

#push_edits(uri, edits) ⇒ Object



33
34
35
# File 'lib/ruby_lsp/store.rb', line 33

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

#set(uri, content) ⇒ Object



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

def set(uri, content)
  document = Document.new(content)
  @state[uri] = document
end