Module: Ibex::LSP::DocumentStoreValidation
- Included in:
- DocumentStore
- Defined in:
- lib/ibex/lsp/document_store_validation.rb,
sig/ibex/lsp/document_store_validation.rbs
Overview
Validates versions, source bounds, and prospective multi-file workspace edits.
Instance Method Summary collapse
-
#disk_path_for_close(path, uri) ⇒ String?
Resolve disk independently from overlay aliases before removing an open buffer.
- #parse_candidate(path, source) ⇒ void
- #valid_replacements?(replacements) ⇒ Boolean
- #validate_source(source) ⇒ void
- #validate_version(version) ⇒ void
Instance Method Details
#disk_path_for_close(path, uri) ⇒ String?
Resolve disk independently from overlay aliases before removing an open buffer.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ibex/lsp/document_store_validation.rb', line 48 def disk_path_for_close(path, uri) # @type self: DocumentStore canonical = loader.disk_path(path) return canonical if workspace.root_for(canonical) raise ProtocolError.new("document disk target is outside workspace roots: #{uri}", code: -32_602) rescue Errno::ENOENT, Errno::ENOTDIR nil rescue SystemCallError => e raise ProtocolError.new("cannot resolve document disk target #{uri.inspect}: #{e.}", code: -32_602) end |
#parse_candidate(path, source) ⇒ void
This method returns an undefined value.
42 43 44 |
# File 'lib/ibex/lsp/document_store_validation.rb', line 42 def parse_candidate(path, source) Frontend::Parser.new(source, file: path, mode: :extended).parse_source_document end |
#valid_replacements?(replacements) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ibex/lsp/document_store_validation.rb', line 8 def valid_replacements?(replacements) # @type self: DocumentStore candidate = Frontend::SourceLoader.new @snapshots.each_value do |entry| candidate.(entry.fetch(:path), entry.fetch(:source)) if entry.fetch(:open) end replacements.each do |path, source| candidate.(path, source) parse_candidate(path, source) end roots = replacements.keys.flat_map { |path| affected_roots(path) }.uniq roots.each { |root| Frontend::Resolver.new(root, mode: :extended, loader: candidate).resolve } true rescue Ibex::Error, SystemCallError false end |
#validate_source(source) ⇒ void
This method returns an undefined value.
34 35 36 37 38 39 |
# File 'lib/ibex/lsp/document_store_validation.rb', line 34 def validate_source(source) raise ProtocolError.new("document text must be a string", code: -32_602) unless source.is_a?(String) return if source.bytesize <= Limits::MAX_DOCUMENT_BYTES raise ProtocolError.new("document exceeds #{Limits::MAX_DOCUMENT_BYTES} bytes", code: -32_602) end |
#validate_version(version) ⇒ void
This method returns an undefined value.
28 29 30 31 |
# File 'lib/ibex/lsp/document_store_validation.rb', line 28 def validate_version(version) raise ProtocolError.new("document version must be a non-negative integer", code: -32_602) unless version.is_a?(Integer) && !version.negative? end |