Module: YARD::RegistryResolverPatch

Defined in:
lib/yard/aggredator/plugin.rb

Instance Method Summary collapse

Instance Method Details

#lookup_by_path(path, opts = {}) ⇒ Object

Отвратительный copy-paste из RegistryResolver при переходе из Yard v0.9.39 -> v0.9.40 бы исправлен баг 2017 года github.com/lsegal/yard/issues/1116 из-за этого сломалась работа поиска статических родительских методов с привязаннми макросами… исправление: КОМЕНТИРУЕМ СТРОКУ



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/yard/aggredator/plugin.rb', line 335

def lookup_by_path(path, opts = {})
  path = path.to_s
  namespace = opts[:namespace]
  inheritance = opts[:inheritance] || false
  proxy_fallback = opts[:proxy_fallback] || false
  type = opts[:type]

  if namespace.is_a?(CodeObjects::Proxy)
    return proxy_fallback ? CodeObjects::Proxy.new(namespace, path, type) : nil
  end

  if namespace == :root || !namespace
    namespace = @registry.root
  else
    namespace = namespace.parent until namespace.is_a?(CodeObjects::NamespaceObject)
  end
  orignamespace = namespace

  if path =~ starts_with_default_separator_match
    path = $'
    namespace = @registry.root
    orignamespace = @registry.root
  end

  resolved = nil
  lexical_lookup = 0
  while namespace && !resolved
    resolved = lookup_path_direct(namespace, path, type)
    # Prevent a bare name from resolving back to the namespace we started
    # from when searching through a parent namespace. For example,
    # `include Enumerable` inside `A::Enumerable` would walk up to namespace
    # `A` and match `A::Enumerable`, creating a false self-referential mixin.
    # Only skip when we have already moved to a parent (namespace != orignamespace).
    # See https://github.com/lsegal/yard/issues/1116

    # ВОТ ЭТУ СТРОКУ НАДО ЗАКОМЕНТИРОВАТЬ ЧТОБ РАБОТАЛ Aggredator::Api::V3::Message.schema_id
    # resolved = nil if resolved.equal?(orignamespace) && !namespace.equal?(orignamespace)
    resolved ||= lookup_path_inherited(namespace, path, type) if inheritance
    break if resolved
    namespace = namespace.parent
    lexical_lookup += 1
  end

  # method objects cannot be resolved through lexical lookup by more than 1 ns
  if lexical_lookup > 1 && resolved.is_a?(CodeObjects::MethodObject)
    resolved = nil
  end

  if proxy_fallback
    resolved ||= CodeObjects::Proxy.new(orignamespace, path, type)
  end

  resolved
end