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



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

def initialize
  @state = T.let({}, T::Hash[String, Document])
  @encoding = T.let(Constant::PositionEncodingKind::UTF8, String)
  @formatter = T.let("auto", String)
  @supports_progress = T.let(true, T::Boolean)
  @experimental_features = T.let(false, T::Boolean)
  @workspace_uri = T.let(URI::Generic.from_path(path: Dir.pwd), URI::Generic)
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#experimental_featuresObject

Returns the value of attribute experimental_features.



18
19
20
# File 'lib/ruby_lsp/store.rb', line 18

def experimental_features
  @experimental_features
end

#formatterObject

Returns the value of attribute formatter.



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

def formatter
  @formatter
end

#supports_progressObject

Returns the value of attribute supports_progress.



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

def supports_progress
  @supports_progress
end

#workspace_uriObject

Returns the value of attribute workspace_uri.



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

def workspace_uri
  @workspace_uri
end

Instance Method Details

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



77
78
79
# File 'lib/ruby_lsp/store.rb', line 77

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

#clearObject



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

def clear
  @state.clear
end

#delete(uri) ⇒ Object



65
66
67
# File 'lib/ruby_lsp/store.rb', line 65

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

#empty?Boolean



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

def empty?
  @state.empty?
end

#get(uri) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/ruby_lsp/store.rb', line 34

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

  path = T.must(uri.to_standardized_path)
  set(uri: uri, source: File.binread(path), version: 0)
  T.must(@state[uri.to_s])
end

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



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

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

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



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

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