Sha256: 60e94f7bcb69d454e486f5bf89967be4f732f52cdfd91921147d157532031945

Contents?: true

Size: 1004 Bytes

Versions: 4

Compression:

Stored size: 1004 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  class RBSDocument < Document
    extend T::Sig
    extend T::Generic

    ParseResultType = type_member { { fixed: T::Array[RBS::AST::Declarations::Base] } }

    sig { params(source: String, version: Integer, uri: URI::Generic, encoding: Encoding).void }
    def initialize(source:, version:, uri:, encoding: Encoding::UTF_8)
      @syntax_error = T.let(false, T::Boolean)
      super
    end

    sig { override.returns(ParseResultType) }
    def parse
      return @parse_result unless @needs_parsing

      @needs_parsing = false

      _, _, declarations = RBS::Parser.parse_signature(@source)
      @syntax_error = false
      @parse_result = declarations
    rescue RBS::ParsingError
      @syntax_error = true
      @parse_result
    end

    sig { override.returns(T::Boolean) }
    def syntax_error?
      @syntax_error
    end

    sig { override.returns(LanguageId) }
    def language_id
      LanguageId::RBS
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-lsp-0.17.17 lib/ruby_lsp/rbs_document.rb
ruby-lsp-0.17.16 lib/ruby_lsp/rbs_document.rb
ruby-lsp-0.17.15 lib/ruby_lsp/rbs_document.rb
ruby-lsp-0.17.14 lib/ruby_lsp/rbs_document.rb