Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/typeprof/cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(argv)
output = nil
rbs_collection_path = nil
initialize_config_file = false
exclude_patterns = []

opt.separator ""
opt.separator "Options:"
Expand All @@ -25,6 +26,7 @@ def initialize(argv)
opt.on("--version", "Display typeprof version") { cli_options[:display_version] = true }
opt.on("--collection PATH", "File path of collection configuration") { |v| rbs_collection_path = v }
opt.on("--no-collection", "Ignore collection configuration") { rbs_collection_path = :no }
opt.on("--exclude PATTERN", "Exclude files matching glob PATTERN (can be specified multiple times)") { |v| exclude_patterns << v }
opt.on("--lsp", "LSP server mode") do |v|
core_options[:display_indicator] = false
cli_options[:lsp] = true
Expand Down Expand Up @@ -65,6 +67,7 @@ def initialize(argv)
output_errors: false,
output_parameter_names: false,
output_source_locations: false,
exclude_patterns: exclude_patterns,
}.merge(core_options)

@lsp_options = {
Expand Down Expand Up @@ -189,7 +192,8 @@ def generate_config_file
{
"typeprof_version": "experimental",
"rbs_dir": "sig/",
"analysis_unit_dirs": #{exist_dirs.inspect}
"analysis_unit_dirs": #{exist_dirs.inspect},
// "exclude": ["**/templates/**/*.rb"],
// "diagnostic_severity": "warning"
}
JSONC
Expand Down
13 changes: 11 additions & 2 deletions lib/typeprof/core/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def reset!

def add_workspace(rb_folder, rbs_folder)
Dir.glob(File.expand_path(rb_folder + "/**/*.{rb,rbs}")) do |path|
update_file(path, nil)
update_file(path, nil) unless exclude_files.include?(path)
end
Dir.glob(File.expand_path(rbs_folder + "/**/*.{rb,rbs}")) do |path|
update_file(path, nil)
update_file(path, nil) unless exclude_files.include?(path)
end
end

Expand Down Expand Up @@ -512,6 +512,7 @@ def batch(files, output)
i += 1
end

next if exclude_files.include?(File.expand_path(file))
res = update_file(file, File.read(file))

if res
Expand Down Expand Up @@ -542,6 +543,14 @@ def batch(files, output)
output.puts dump_declarations(file)
end
end

private

def exclude_files
@exclude_files ||= (@options[:exclude_patterns] || []).each_with_object(::Set.new) { |pattern, set|
Dir.glob(File.expand_path(pattern)) { |path| set << path }
}
end
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/typeprof/lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def add_workspaces(folders)
puts "unknown severity: #{ severity }"
end
end
@core_options[:exclude_patterns] = conf[:exclude] if conf[:exclude]
conf[:analysis_unit_dirs].each do |dir|
dir = File.expand_path(dir, path)
core = @cores[dir] = TypeProf::Core::Service.new(@core_options)
Expand Down
11 changes: 11 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ def check: -> :ok
end)
end

def test_e2e_exclude
assert_equal(<<~END, test_run("exclude_test", ["--exclude", "**/templates/**", "."]))
# TypeProf #{ TypeProf::VERSION }

# ./lib/main.rb
class Object
def foo: (String) -> String
end
END
end

def test_lsp_options_with_lsp_mode
assert_nothing_raised { TypeProf::CLI::CLI.new(["--lsp", "--stdio"]) }
end
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/exclude_test/lib/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def foo(n)
n
end

foo("str")
6 changes: 6 additions & 0 deletions test/fixtures/exclude_test/templates/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<h1><%= title %></h1>
<p><%= content %></p>
</body>
</html>