Sha256: d7f4fb3e14d985c195f0cd2738680d395bfc1d9ac0b99f52039c68dd4e3d0d15

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  class Store
    extend T::Sig

    sig { returns(String) }
    attr_accessor :encoding

    sig { returns(String) }
    attr_accessor :formatter

    sig { returns(T::Boolean) }
    attr_accessor :supports_progress

    sig { returns(T::Boolean) }
    attr_accessor :experimental_features

    sig { void }
    def initialize
      @state = T.let({}, T::Hash[String, Document])
      @encoding = T.let(Constant::PositionEncodingKind::UTF8, String)
      @formatter = T.let("auto", String)
      @supports_progress = T.let(true, T::Boolean)
      @experimental_features = T.let(false, T::Boolean)
    end

    sig { params(uri: URI::Generic).returns(Document) }
    def get(uri)
      document = @state[uri.to_s]
      return document unless document.nil?

      path = T.must(uri.to_standardized_path)
      set(uri: uri, source: File.binread(path), version: 0)
      T.must(@state[uri.to_s])
    end

    sig { params(uri: URI::Generic, source: String, version: Integer).void }
    def set(uri:, source:, version:)
      document = RubyDocument.new(source: source, version: version, uri: uri, encoding: @encoding)
      @state[uri.to_s] = document
    end

    sig { params(uri: URI::Generic, edits: T::Array[Document::EditShape], version: Integer).void }
    def push_edits(uri:, edits:, version:)
      T.must(@state[uri.to_s]).push_edits(edits, version: version)
    end

    sig { void }
    def clear
      @state.clear
    end

    sig { returns(T::Boolean) }
    def empty?
      @state.empty?
    end

    sig { params(uri: URI::Generic).void }
    def delete(uri)
      @state.delete(uri.to_s)
    end

    sig do
      type_parameters(:T)
        .params(
          uri: URI::Generic,
          request_name: String,
          block: T.proc.params(document: Document).returns(T.type_parameter(:T)),
        ).returns(T.type_parameter(:T))
    end
    def cache_fetch(uri, request_name, &block)
      get(uri).cache_fetch(request_name, &block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-lsp-0.12.5 lib/ruby_lsp/store.rb
ruby-lsp-0.12.4 lib/ruby_lsp/store.rb