diff --git a/lib/ruby_lsp/document.rb b/lib/ruby_lsp/document.rb index b8b18de6a..77807b187 100644 --- a/lib/ruby_lsp/document.rb +++ b/lib/ruby_lsp/document.rb @@ -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 diff --git a/lib/ruby_lsp/requests/support/dependency_detector.rb b/lib/ruby_lsp/requests/support/dependency_detector.rb index 3d7f3b632..d2bf7eb4c 100644 --- a/lib/ruby_lsp/requests/support/dependency_detector.rb +++ b/lib/ruby_lsp/requests/support/dependency_detector.rb @@ -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) } @@ -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]) } diff --git a/lib/ruby_lsp/store.rb b/lib/ruby_lsp/store.rb index 08dbef84e..d66353896 100644 --- a/lib/ruby_lsp/store.rb +++ b/lib/ruby_lsp/store.rb @@ -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 diff --git a/test/requests/support/common_test.rb b/test/requests/support/common_test.rb new file mode 100644 index 000000000..ea5842f80 --- /dev/null +++ b/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 diff --git a/test/requests/workspace_symbol_test.rb b/test/requests/workspace_symbol_test.rb index 7553f8334..914a935d6 100644 --- a/test/requests/workspace_symbol_test.rb +++ b/test/requests/workspace_symbol_test.rb @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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