castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.89k stars 158 forks source link

Implement yard directive visibility handling #567

Closed ghost closed 2 years ago

ghost commented 2 years ago

Implement handling of the yard @!visibility directive.

Should address #566.

Signed-off-by: liberatys nick.anthony.flueckiger@hey.com

castwide commented 2 years ago

This is a great start, but there are still a couple of use cases that don't match YARD's specification.

  1. A @!visibility directive that is attached to a method should not modify other methods. Example spec:

    it "processes private visibility directives attached to methods" do
      map = Solargraph::SourceMap.load_string(%(
        class Example
          # @!visibility private
          def method1; end
    
          def method2; end
        end
      ))
      method1 = map.first_pin('Example#method1')
      expect(method1.visibility).to be(:private)
      method2 = map.first_pin('Example#method2')
      expect(method2.visibility).to be(:public)
    end
  2. A @!visibility directive that is not attached to a method should modify other methods and can be overridden. Example spec:

    it "processes class-wide private visibility directives" do
      map = Solargraph::SourceMap.load_string(%(
        class Example
          # @!visibility private
    
          def method1; end
    
          def method2; end
    
          # @!visibility public
          def method3; end
        end
      ))
      method1 = map.first_pin('Example#method1')
      expect(method1.visibility).to be(:private)
      method2 = map.first_pin('Example#method2')
      expect(method2.visibility).to be(:private)
      method3 = map.first_pin('Example#method3')
      expect(method3.visibility).to be(:public)
    end
castwide commented 2 years ago

I'll go ahead and merge this and make the changes to pass the two additional specs. It'll be released in 0.47.0.