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.



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

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)


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

def close uri
  open_source_hash.delete uri
end

#find(uri) ⇒ Solargraph::Source

Find the source with the given URI.

Parameters:

  • uri (String)

Returns:

Raises:



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

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)


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

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