Class: Rfmt::LSP::Workspace
- Inherits:
-
Object
- Object
- Rfmt::LSP::Workspace
- Defined in:
- lib/rfmt/lsp/workspace.rb
Instance Method Summary collapse
- #configure(params) ⇒ Object
-
#initialize ⇒ Workspace
constructor
A new instance of Workspace.
- #root_for(uri) ⇒ Object
- #with_root_for(uri, &block) ⇒ Object
Constructor Details
#initialize ⇒ Workspace
Returns a new instance of Workspace.
10 11 12 |
# File 'lib/rfmt/lsp/workspace.rb', line 10 def initialize @roots = [] end |
Instance Method Details
#configure(params) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/rfmt/lsp/workspace.rb', line 14 def configure(params) @roots = workspace_folder_roots(params) root_uri = params['rootUri'] @roots << URI.file_uri_to_path(root_uri) if root_uri @roots = @roots.compact.map { |root| File.(root) }.uniq end |
#root_for(uri) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rfmt/lsp/workspace.rb', line 21 def root_for(uri) path = URI.file_uri_to_path(uri) return existing_root(@roots.first) unless path matching_root = @roots .select { |root| path_inside?(path, root) } .max_by(&:length) return existing_root(matching_root) if matching_root existing_root(File.dirname(path)) end |