Skip to content

Global methods in _top_level.rb not recognized by Solargraph #88

@jvcarli

Description

@jvcarli

Hi, I found an issue with global methods defined in _top_level.rb.

While defining a global method as:

def file_loaded(filename)
end

works in actual Ruby execution (top-level methods become global),
it causes issues with static analysis tools like Solargraph. Solargraph can't see those methods, so things like documentation on hover and go to definition are broken for those methods.

Suggested fix

Fortunately this is a really simple fix.

Wrap all global methods in a module Kernel block to explicitly tell static analyzers these methods should be available everywhere:

module Kernel
  def file_loaded(filename)
  end
  
  def file_loaded?(filename)
  end
  
  def inputbox(*args)
  end
  
  # ... other global methods
end

Kernel is where Ruby's own global methods live, so this fixes the issue. Constants need to remain outside of Kernel module.

I've tested it locally and it fixes the problem.

SEE: https://docs.ruby-lang.org/en/3.2/Kernel.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions