Class: Yoda::Server::Workspace

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yoda/server/workspace.rb

Overview

Defined Under Namespace

Classes: UriEncoder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, root_uri:) ⇒ Workspace

Returns a new instance of Workspace.

Parameters:

  • name (String)
  • root_uri (String)


29
30
31
32
# File 'lib/yoda/server/workspace.rb', line 29

def initialize(name:, root_uri:)
  @name = name
  @root_uri = root_uri
end

Instance Attribute Details

#nameString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/yoda/server/workspace.rb', line 12

def name
  @name
end

#root_uriString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/yoda/server/workspace.rb', line 15

def root_uri
  @root_uri
end

Class Method Details

.from_workspace_folder(folder) ⇒ Workspace

Parameters:

  • folder (LanguageServer::Protocol::Interface::WorkspaceFolder)

Returns:



23
24
25
# File 'lib/yoda/server/workspace.rb', line 23

def self.from_workspace_folder(folder)
  new(name: folder.name, root_uri: folder.uri)
end

Instance Method Details

#projectStore::Project?

Returns:



40
41
42
# File 'lib/yoda/server/workspace.rb', line 40

def project
  @project ||= Store::Project.for_path(root_path)
end

#read_at(uri) ⇒ String?

Parameters:

  • uri (String)

Returns:

  • (String, nil)


51
52
53
54
# File 'lib/yoda/server/workspace.rb', line 51

def read_at(uri)
  path = UriDecoder.path_of_uri(uri)
  path && file_tree.read_at(path)
end

#read_source(uri) ⇒ Object

Parameters:

  • uri (String)


57
58
59
60
61
# File 'lib/yoda/server/workspace.rb', line 57

def read_source(uri)
  path = UriDecoder.path_of_uri(uri)
  return if !path || !program_file?(path)
  file_tree.clear_editing_at(path)
end

#remove_source(uri:) ⇒ Object

Parameters:

  • uri (String)


72
73
74
75
# File 'lib/yoda/server/workspace.rb', line 72

def remove_source(uri:)
  path = UriDecoder.path_of_uri(uri)
  file_tree.mark_deleted(path)
end

#root_pathString

Returns:

  • (String)


45
46
47
# File 'lib/yoda/server/workspace.rb', line 45

def root_path
  UriDecoder.path_of_uri(root_uri)
end

#setupArray<Exception>

Returns errors on setup.

Returns:

  • (Array<Exception>)

    errors on setup



35
36
37
# File 'lib/yoda/server/workspace.rb', line 35

def setup
  project.setup
end

#store_source(uri:, source:) ⇒ Object

Parameters:

  • uri (String)
  • source (String)


65
66
67
68
69
# File 'lib/yoda/server/workspace.rb', line 65

def store_source(uri:, source:)
  path = UriDecoder.path_of_uri(uri)
  return if !path || !program_file?(path)
  file_tree.set_editing_at(path, source)
end

#suburi?(uri) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/yoda/server/workspace.rb', line 77

def suburi?(uri)
  path = UriDecoder.path_of_uri(uri)
  path && subpath?(path)
end