Module: Steep::Server::Utils

Included in:
BaseWorker, CodeWorker
Defined in:
lib/steep/server/utils.rb

Constant Summary collapse

LSP =
LanguageServer::Protocol

Instance Method Summary collapse

Instance Method Details

#source_path(uri) ⇒ Object



6
7
8
# File 'lib/steep/server/utils.rb', line 6

def source_path(uri)
  project.relative_path(Pathname(uri.path))
end

#update_source(request) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/steep/server/utils.rb', line 10

def update_source(request)
  path = source_path(URI.parse(request[:params][:textDocument][:uri]))
  text = request[:params][:contentChanges][0][:text]
  version = request[:params][:textDocument][:version]

  Steep.logger.debug "Updateing source: path=#{path}, version=#{version}, size=#{text.bytesize}"

  project.targets.each do |target|
    case
    when target.source_file?(path)
      target.update_source path, text
    when target.possible_source_file?(path)
      target.add_source path, text
    when target.signature_file?(path)
      target.update_signature path, text
    when target.possible_signature_file?(path)
      target.add_signature path, text
    end
  end

  if block_given?
    yield path, version
  end
end