Code Monkey home page Code Monkey logo

Comments (4)

vinistock avatar vinistock commented on May 30, 2024 1

There's no built-in way by checking the method definition straight. We'd need to keep track of which section we're currently inside. Something like this in pseudo code

class InlayHint < BaseRequest
  def initialize(...)
    @current_visibility = :public # Maybe use a Sorbet enum?
  end

  def visit_call(node) # not sure if it's call, command, fcall...
    if this_thing_is_private_public_or_protected
      @current_visibility = the_new_visibility
    end
  end

  def visit_def(node)
    add_hint_using_current_visibility
  end
end

Two thoughts:

  • I think we shouldn't add anything for public methods, since that's the default
  • If it's possible, I think this inlay hint would look better on top of the method name (not on the left or right)

from ruby-lsp.

RyanBrushett avatar RyanBrushett commented on May 30, 2024 1

Ooo neat, thanks for the pointers!

I think we shouldn't add anything for public methods, since that's the default

Completely agree. That would be really messy.

If it's possible, I think this inlay hint would look better on top of the method name (not on the left or right)

Should be entirely possible. This hint in particular really runs the risk of looking messy, I agree that above is a good place to start. If I get a chance to hack on it, I'll be sure to propose a few options with screenshots for easy evaluation.

from ruby-lsp.

st0012 avatar st0012 commented on May 30, 2024

@vinistock I want to give this a try. I'll start by listing common cases that can use the hint.

But without type information, there aren't too many features we can implement with high accuracy.

  • Implicit self

  • Implicit type information, like

    • rescue => e (Exception)
    • raise "error" (RuntimeError)
  • Method visibility

    private
    
    # 100 lines
    
    (private) def foo
    end
  • Expanded namespace

    • Not sure how practical it is without code evaluation
    module Foo
      module Rails; end
    
      (Foo::)Rails

For new developers

These may be too intrusive and distracting for experienced developers. But they could help new devs understand Ruby.

  • Expand syntactical sugar like &= or |=

    a |= b # (a = a | b)
  • Operator precedence

    1 + 2 * 5 # (1 + (2 * 5))
  • Explain % literals

    %q(foobarbaz) # String "foobarbaz"

Things that'll be helpful if possible

  • Possible super source

    class A
      def foo; end
    end
    
    class B < A
      def foo
        super # hint A
      end
    end

from ruby-lsp.

RyanBrushett avatar RyanBrushett commented on May 30, 2024

I dug into adding a hint for indicating method visibility but I kept hitting a wall in figuring out whether or not a def node was private/protected/public.

Would that require enhancing syntax_tree a bit or is there some elegant way to determine a node's visibility that I've missed? Maybe I'm looking at it from the wrong perspective.

from ruby-lsp.

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.