Sha256: d08ccfbeefed56e7d2e6915a38ee0c1e6cec73e9ab3850b1788db804fc0dda0d

Contents?: true

Size: 1.01 KB

Versions: 18

Compression:

Stored size: 1.01 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  class Scope
    extend T::Sig

    sig { returns(T.nilable(Scope)) }
    attr_reader :parent

    sig { params(parent: T.nilable(Scope)).void }
    def initialize(parent = nil)
      @parent = parent

      # A hash of name => type
      @locals = T.let({}, T::Hash[Symbol, Local])
    end

    # Add a new local to this scope. The types should only be `:parameter` or `:variable`
    sig { params(name: T.any(String, Symbol), type: Symbol).void }
    def add(name, type)
      @locals[name.to_sym] = Local.new(type)
    end

    sig { params(name: T.any(String, Symbol)).returns(T.nilable(Local)) }
    def lookup(name)
      sym = name.to_sym
      entry = @locals[sym]
      return entry if entry
      return unless @parent

      @parent.lookup(sym)
    end

    class Local
      extend T::Sig

      sig { returns(Symbol) }
      attr_reader :type

      sig { params(type: Symbol).void }
      def initialize(type)
        @type = type
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ruby-lsp-0.23.6 lib/ruby_lsp/scope.rb
ruby-lsp-0.23.5 lib/ruby_lsp/scope.rb
ruby-lsp-0.23.4 lib/ruby_lsp/scope.rb
ruby-lsp-0.23.3 lib/ruby_lsp/scope.rb
ruby-lsp-0.23.2 lib/ruby_lsp/scope.rb
ruby-lsp-0.23.1 lib/ruby_lsp/scope.rb
ruby-lsp-0.23.0 lib/ruby_lsp/scope.rb
ruby-lsp-0.22.1 lib/ruby_lsp/scope.rb
ruby-lsp-0.22.0 lib/ruby_lsp/scope.rb
ruby-lsp-0.21.3 lib/ruby_lsp/scope.rb
ruby-lsp-0.21.2 lib/ruby_lsp/scope.rb
ruby-lsp-0.21.1 lib/ruby_lsp/scope.rb
ruby-lsp-0.21.0 lib/ruby_lsp/scope.rb
ruby-lsp-0.20.1 lib/ruby_lsp/scope.rb
ruby-lsp-0.20.0 lib/ruby_lsp/scope.rb
ruby-lsp-0.19.1 lib/ruby_lsp/scope.rb
ruby-lsp-0.19.0 lib/ruby_lsp/scope.rb
ruby-lsp-0.18.4 lib/ruby_lsp/scope.rb