Giter Club home page Giter Club logo

Comments (3)

castwide avatar castwide commented on May 25, 2024 1

Detecting dynamic methods is tricky. I might be able to make it work in limited cases, but there will always be exceptions. The only 100% reliable solution is to execute the code, which Solargraph intentionally avoids doing.

One alternative is to use YARD directives. Example using the @!method directive:

module MyModule
  # @!method another_method(an_argument)
  #   This method add new functionality
  #   @param an_argument [SomeType] a specific argument
  #   @return [SomeType]

  def self.included(klass)
    klass.class_eval do
      def another_method(an_argument)
        #Some business code
      end
    end
  end
end

class MyClass
  include MyModule
end

kl = MyClass.new
kl. # => another_method appears in suggestions

Note: suggestions from YARD directives will only be available if the file is included in the generated .yardoc directory. By default, YARD only reads the workspace's lib and app directories. That setting can be changed with a .yardopts file. A future version of the Solargraph gem might be able to parse directives locally.

I'm open to other suggestions for improving detection of dynamic methods. It's a hard problem.

from vscode-solargraph.

didacusAbella avatar didacusAbella commented on May 25, 2024 1

Very Nice!! I'll try it as soon as possible

from vscode-solargraph.

castwide avatar castwide commented on May 25, 2024

As of gem version 0.15.0, there are two additions that can help with this feature:

  • Improved macro support. Any @!method and @!attribute macros in your workspace get mapped into completion suggestions. A local yardoc is not required.

  • The experimental Runtime plugin. Solargraph can run a subprocess that queries your project's classes and modules for "magic" methods. More information is available in the Solargraph README.

from vscode-solargraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.