Class: RubyLsp::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lsp/store.rb

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



9
10
11
# File 'lib/ruby_lsp/store.rb', line 9

def initialize
  @state = {}
end

Instance Method Details

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



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

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

#clearObject



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

def clear
  @state.clear
end

#delete(uri) ⇒ Object



31
32
33
# File 'lib/ruby_lsp/store.rb', line 31

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

#get(uri) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ruby_lsp/store.rb', line 13

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

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

#set(uri, content) ⇒ Object



21
22
23
24
25
# File 'lib/ruby_lsp/store.rb', line 21

def set(uri, content)
  @state[uri] = Document.new(content)
rescue SyntaxTree::Parser::ParseError
  # Do not update the store if there are syntax errors
end