Class: Solargraph::LanguageServer::Host::Sources

Inherits:
Object
  • Object
show all
Includes:
Observable, UriHelpers
Defined in:
lib/solargraph/language_server/host/sources.rb

Overview

A Host class for managing sources.

Instance Method Summary collapse

Methods included from UriHelpers

decode, encode, file_to_uri, uri_to_file

Instance Method Details

#add_uri(uri) ⇒ void

This method returns an undefined value.

Parameters:

  • uri (String)


16
17
18
# File 'lib/solargraph/language_server/host/sources.rb', line 16

def add_uri uri
  queue.push(uri)
end

#clearvoid

This method returns an undefined value.



80
81
82
# File 'lib/solargraph/language_server/host/sources.rb', line 80

def clear
  open_source_hash.clear
end

#close(uri) ⇒ void

This method returns an undefined value.

Close the source with the given URI.

Parameters:

  • uri (String)


68
69
70
# File 'lib/solargraph/language_server/host/sources.rb', line 68

def close uri
  open_source_hash.delete uri
end

#find(uri) ⇒ Solargraph::Source

Find the source with the given URI.

@sg-ignore flow ensitive typing should understand raise

Parameters:

  • uri (String)

Returns:

Raises:



60
61
62
# File 'lib/solargraph/language_server/host/sources.rb', line 60

def find uri
  open_source_hash[uri] || raise(Solargraph::FileNotFoundError, "Host could not find #{uri}")
end

#include?(uri) ⇒ Boolean

True if a source with given URI is currently open.

Parameters:

  • uri (String)

Returns:

  • (Boolean)


75
76
77
# File 'lib/solargraph/language_server/host/sources.rb', line 75

def include? uri
  open_source_hash.key? uri
end

#open(uri, text, version) ⇒ Source

Open a source.

Parameters:

  • uri (String)
  • text (String)
  • version (Integer)

Returns:



26
27
28
29
30
# File 'lib/solargraph/language_server/host/sources.rb', line 26

def open uri, text, version
  filename = uri_to_file(uri)
  source = Solargraph::Source.new(text, filename, version)
  open_source_hash[uri] = source
end

#open_from_disk(uri) ⇒ void

This method returns an undefined value.

Parameters:

  • uri (String)


34
35
36
37
# File 'lib/solargraph/language_server/host/sources.rb', line 34

def open_from_disk uri
  source = Solargraph::Source.load(UriHelpers.uri_to_file(uri))
  open_source_hash[uri] = source
end

#update(uri, updater) ⇒ void

This method returns an undefined value.

Update an existing source.

Parameters:

Raises:



46
47
48
49
50
51
# File 'lib/solargraph/language_server/host/sources.rb', line 46

def update uri, updater
  src = find(uri)
  open_source_hash[uri] = src.synchronize(updater)
  changed
  notify_observers uri
end