# frozen_string_literal: true
module YARD
  module Handlers
    module C
      class Base < Handlers::Base

        # Temporary workaround until a proper fix can be applied to YARD master.
        alias_method :namespace_for_variable_original, :namespace_for_variable
        def namespace_for_variable(var)
          patch_namespace_for_variable(var) ||
              namespace_for_variable_original(var)
        end

        private

        def patch_namespace_for_variable(var)
          name = PATCH_ERROR_NAME[var]
          # $stderr.puts "Mapped #{var} to #{name}" if name
          name.nil? ? nil : P(name)
        end

        # Generated by update_error_map.rb (Copy+past results)
        PATCH_ERROR_NAME = {
          'rb_eException' => 'Exception',
          'rb_eSystemExit' => 'SystemExit',
          'rb_eFatal' => 'fatal',
          'rb_eSignal' => 'SignalException',
          'rb_eInterrupt' => 'Interrupt',
          'rb_eStandardError' => 'StandardError',
          'rb_eTypeError' => 'TypeError',
          'rb_eArgError' => 'ArgumentError',
          'rb_eIndexError' => 'IndexError',
          'rb_eKeyError' => 'KeyError',
          'rb_eRangeError' => 'RangeError',
          'rb_eScriptError' => 'ScriptError',
          'rb_eSyntaxError' => 'SyntaxError',
          'rb_eLoadError' => 'LoadError',
          'rb_eNotImpError' => 'NotImplementedError',
          'rb_eNameError' => 'NameError',
          'rb_eNoMethodError' => 'NoMethodError',
          'rb_eRuntimeError' => 'RuntimeError',
          'rb_eFrozenError' => 'FrozenError',
          'rb_eSecurityError' => 'SecurityError',
          'rb_eNoMemError' => 'NoMemoryError',
          'rb_eEncodingError' => 'EncodingError',
          'rb_eSystemCallError' => 'SystemCallError',
        }

      end
    end
  end
end
