Skip to content

Commit 5e8d47c

Browse files
committed
Prevent migration code lens from failing in unsaved files
1 parent 28a6f65 commit 5e8d47c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/ruby_lsp/ruby_lsp_rails/code_lens.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ def on_class_node_enter(node)
152152
end
153153

154154
if superclass_name&.start_with?("ActiveRecord::Migration")
155-
command = "#{migrate_command} VERSION=#{migration_version}"
156-
add_migrate_code_lens(node, name: class_name, command: command)
155+
version = migration_version
156+
command = "#{migrate_command} VERSION=#{version}"
157+
add_migrate_code_lens(node, name: class_name, command: command) if version
157158
end
158159
end
159160

@@ -241,7 +242,9 @@ def migrate_command
241242

242243
sig { returns(T.nilable(String)) }
243244
def migration_version
244-
File.basename(T.must(@path)).split("_").first
245+
return unless @path
246+
247+
File.basename(@path).split("_").first
245248
end
246249

247250
sig { params(node: Prism::Node, name: String, command: String).void }

0 commit comments

Comments
 (0)