Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steepfile: Allow to change the extension of the source files #1454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/steep/project/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def check(*args)
sources.concat(args)
end

def ext(ext)
@ext = ext
end
Comment on lines +77 to +79
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any better name for this? I have some other ideas: file_ext, source_ext and extensions (plural).

Copy link
Contributor

@ParadoxV5 ParadoxV5 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ext and extensions sound like “plugins”.
Here’s another: check_ext

Honestly, it should be called “templating”.
ERB templating syntax is not Ruby syntax, and just changing the extension won’t teach Steep how to recognize them, not to mention this design currently blocks a target from continuing checking *.rb.
If Steep can automatically switch to ERB mode for *.erbs, it can simply change the default file extension to .{rb,erb}.

P.S. If it’s just for pretending say .ruby files to be synonymous with .rb, is check 'app/views/**/*.{rb,ruby}' sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Steep can automatically switch to ERB mode for *.erbs, it can simply change the default file extension to .{rb,erb}.

Some template languages, such as HAML, can be converted to Ruby in real-world apps. Therefore it might be better to provide to enhance Steep via plug-ins. From that perspective, it would be better to specify the file extensions via Steepfile.

P.S. If it’s just for pretending say .ruby files to be synonymous with .rb, is check 'app/views/**/*.{rb,ruby}' sufficient?

Unfortunately, it does not work perfectly.

Please see the diff of lib/steep/server/master.rb. It has a hard-coded .rb string to set up didChangeWatchedFiles event.


def ignore(*args)
ignored_sources.concat(args)
end
Expand Down Expand Up @@ -103,7 +107,7 @@ def ignored_signatures
end

def source_pattern
Pattern.new(patterns: sources, ignores: ignored_sources, ext: ".rb")
Pattern.new(patterns: sources, ignores: ignored_sources, ext: @ext || ".rb")
end

def signature_pattern
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def process_message_from_client(message)
end
target.source_pattern.prefixes.each do |pat|
path = project.base_dir + pat
patterns << (path + "**/*.rb").to_s unless path.file?
patterns << (path + "**/*#{target.source_pattern.ext}").to_s unless path.file?
end
target.signature_pattern.patterns.each do |pat|
path = project.base_dir + pat
Expand Down Expand Up @@ -800,7 +800,7 @@ def start_type_check(request: nil, last_request:, progress: nil, include_unchang
Steep.logger.info "Starting new progress..."

@current_type_check_request = request

if progress
# If `request:` keyword arg is not given
request.work_done_progress.begin("Type checking", request_id: fresh_request_id)
Expand Down
5 changes: 5 additions & 0 deletions sample/Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ end
# signature "sig/length.rbs"
# unreferenced!
# end

# target :templates do
# check "lib/templates" # Directory name
# ext ".erb"
# end
4 changes: 4 additions & 0 deletions sig/steep/project/dsl.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ module Steep

attr_reader ignored_signatures: Array[String]

@ext: String?

def check: (*String args) -> void

def ext: (String ext) -> void

def ignore: (*String args) -> void

def signature: (*String args) -> void
Expand Down
24 changes: 24 additions & 0 deletions test/steepfile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,28 @@ def test_string
end
end
end

def test_ext
in_tmpdir do
project = Project.new(steepfile_path: current_dir + "Steepfile")

Project::DSL.parse(project, <<EOF)
target :views do
check "app/views"
ext ".erb"
signature "sig"
end
EOF

assert_equal 1, project.targets.size

project.targets.find {|target| target.name == :views }.tap do |target|
assert_instance_of Project::Target, target

assert_equal ["app/views"], target.source_pattern.patterns
assert_equal ".erb", target.source_pattern.ext
assert_equal ["sig"], target.signature_pattern.patterns
end
end
end
end
Loading