Sha256: 35bdcfb04335b7aa423eb9fd5768b51b5889c8b6e61e27b4604cb41c94b8250f

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

# frozen_string_literal: true

require "cgi"
require "uri"
require "ruby_lsp/document"

module RubyLsp
  class Store
    def initialize
      @state = {}
    end

    def get(uri)
      document = @state[uri]
      return document unless document.nil?

      set(uri, File.binread(CGI.unescape(URI.parse(uri).path)))
      @state[uri]
    end

    def set(uri, content)
      @state[uri] = Document.new(content)
    rescue SyntaxTree::Parser::ParseError
      # Do not update the store if there are syntax errors
    end

    def push_edits(uri, edits)
      @state[uri].push_edits(edits)
    end

    def clear
      @state.clear
    end

    def delete(uri)
      @state.delete(uri)
    end

    def cache_fetch(uri, request_name, &block)
      get(uri).cache_fetch(request_name, &block)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-lsp-0.0.3 lib/ruby_lsp/store.rb