Skip to content

Commit

Permalink
Add tests, fix tests, resolve sorbet errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoroth committed Apr 12, 2024
1 parent fca974d commit 60adc9e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
5 changes: 5 additions & 0 deletions lib/ruby_lsp/document.rb
Expand Up @@ -180,6 +180,11 @@ def sorbet_sigil_is_true_or_higher
end
end

sig { returns(T::Boolean) }
def typechecker_enabled?
DependencyDetector.instance.typechecker_for_uri?(uri) && sorbet_sigil_is_true_or_higher
end

class Scanner
extend T::Sig

Expand Down
6 changes: 4 additions & 2 deletions lib/ruby_lsp/requests/support/dependency_detector.rb
Expand Up @@ -3,10 +3,12 @@

require "singleton"

require "ruby_lsp/requests/support/common"

module RubyLsp
class DependencyDetector
include Singleton
include Support::Common
include Requests::Support::Common
extend T::Sig

sig { returns(String) }
Expand Down Expand Up @@ -69,7 +71,7 @@ def detect_typechecker

sig { params(uri: URI::Generic).returns(T::Boolean) }
def typechecker_for_uri?(uri)
detect_typechecker && !erb?(uri)
typechecker && !erb?(uri)
end

sig { returns(T::Array[String]) }
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/store.rb
Expand Up @@ -4,7 +4,7 @@
module RubyLsp
class Store
extend T::Sig
include Support::Common
include Requests::Support::Common

sig { returns(T::Boolean) }
attr_accessor :supports_progress
Expand Down
39 changes: 39 additions & 0 deletions test/requests/support/common_test.rb
@@ -0,0 +1,39 @@
# typed: true
# frozen_string_literal: true

require "test_helper"

module RubyLsp
class CommonTest < Minitest::Test
def test_erb_for_erb_file
uri = URI::Generic.from_path(path: "/path/to/file.erb")
assert(common.erb?(uri))
end

def test_erb_for_html_erb_file
uri = URI::Generic.from_path(path: "/path/to/file.html.erb")
assert(common.erb?(uri))
end

def test_erb_for_rhtml_file
uri = URI::Generic.from_path(path: "/path/to/file.rhtml")
assert(common.erb?(uri))
end

def test_erb_for_rhtm_file
uri = URI::Generic.from_path(path: "/path/to/file.rhtm")
assert(common.erb?(uri))
end

def test_erb_for_rb_file
uri = URI::Generic.from_path(path: "/path/to/file.rb")
refute(common.erb?(uri))
end

private

def common
Class.new.include(Requests::Support::Common).new
end
end
end
26 changes: 13 additions & 13 deletions test/requests/workspace_symbol_test.rb
Expand Up @@ -18,15 +18,15 @@ module Bar; end
CONSTANT = 1
RUBY

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo", uri).perform.first
assert_equal("Foo", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::CLASS, T.must(result).kind)

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Bar").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Bar", uri).perform.first
assert_equal("Bar", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::NAMESPACE, T.must(result).kind)

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "CONST").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "CONST", uri).perform.first
assert_equal("CONSTANT", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::CONSTANT, T.must(result).kind)
end
Expand All @@ -39,15 +39,15 @@ module Bar; end
CONSTANT = 1
RUBY

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Floo").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Floo", uri).perform.first
assert_equal("Foo", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::CLASS, T.must(result).kind)

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Bear").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Bear", uri).perform.first
assert_equal("Bar", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::NAMESPACE, T.must(result).kind)

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "CONF").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "CONF", uri).perform.first
assert_equal("CONSTANT", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::CONSTANT, T.must(result).kind)
end
Expand All @@ -67,7 +67,7 @@ class Foo; end
class Foo; end
RUBY

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo").perform
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo", uri).perform
assert_equal(1, result.length)
assert_equal(URI::Generic.from_path(path: path).to_s, T.must(result.first).location.uri)
end
Expand All @@ -79,7 +79,7 @@ class Bar; end
end
RUBY

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo::Bar").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo::Bar", uri).perform.first
assert_equal("Foo::Bar", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::CLASS, T.must(result).kind)
assert_equal("Foo", T.must(result).container_name)
Expand All @@ -88,7 +88,7 @@ class Bar; end
def test_finds_default_gem_symbols
@index.index_single(RubyIndexer::IndexablePath.new(nil, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb"))

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Pathname").perform
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Pathname", uri).perform
refute_empty(result)
end

Expand All @@ -100,7 +100,7 @@ class Foo
end
RUBY

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo::CONSTANT").perform
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "Foo::CONSTANT", uri).perform
assert_equal(1, result.length)
assert_equal("Foo", T.must(result.first).name)
end
Expand All @@ -115,15 +115,15 @@ def bar; end
end
RUBY

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "bar").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "bar", uri).perform.first
assert_equal("bar", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::METHOD, T.must(result).kind)

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "initialize").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "initialize", uri).perform.first
assert_equal("initialize", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::CONSTRUCTOR, T.must(result).kind)

result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "baz").perform.first
result = RubyLsp::Requests::WorkspaceSymbol.new(@global_state, "baz", uri).perform.first
assert_equal("baz", T.must(result).name)
assert_equal(RubyLsp::Constant::SymbolKind::PROPERTY, T.must(result).kind)
end
Expand Down

0 comments on commit 60adc9e

Please sign in to comment.