Sha256: 8223b919426f2a1a2247b95a0a2eeeac80dd296875718cfaafe150f2ef085e27

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 KB

Contents

# typed: strict
# frozen_string_literal: true

# NOTE: This module is intended to be used by addons for writing their own tests, so keep that in mind if changing.

module RubyLsp
  module TestHelper
    extend T::Sig

    sig do
      type_parameters(:T)
        .params(
          source: T.nilable(String),
          uri: URI::Generic,
          stub_no_typechecker: T::Boolean,
          load_addons: T::Boolean,
          block: T.proc.params(server: RubyLsp::Server, uri: URI::Generic).returns(T.type_parameter(:T)),
        ).returns(T.type_parameter(:T))
    end
    def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typechecker: false, load_addons: true,
      &block)
      server = RubyLsp::Server.new(test_mode: true)
      server.global_state.stubs(:typechecker).returns(false) if stub_no_typechecker

      if source
        server.process_message({
          method: "textDocument/didOpen",
          params: {
            textDocument: {
              uri: uri,
              text: source,
              version: 1,
            },
          },
        })
      end

      server.global_state.index.index_single(
        RubyIndexer::IndexablePath.new(nil, T.must(uri.to_standardized_path)),
        source,
      )
      server.load_addons if load_addons
      block.call(server, uri)
    ensure
      if load_addons
        RubyLsp::Addon.addons.each(&:deactivate)
        RubyLsp::Addon.addons.clear
      end
      T.must(server).run_shutdown
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby-lsp-0.17.0 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.6 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.5 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.4 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.3 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.2 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.1 lib/ruby_lsp/test_helper.rb
ruby-lsp-0.16.0 lib/ruby_lsp/test_helper.rb