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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: recognize or blocks in call args #19690

Merged
merged 3 commits into from Oct 29, 2023

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Oct 28, 2023

This PR should fix un-uniform behavior where or-blocks are not recognized in call arguments.

Current:

import os

const (
	// v fmt doesn't alling since it isn't singleline / has an or block.
	exe = os.find_abs_path_of_executable('my_exe') or {
		eprintln('skipping test, since `my_exe` is missing')
		exit(0)
	}
	// same expr as above but wrapped in a function as an argument.
	// v fmt aligns despite the or block.
	exe_quoted            = os.quoted_path(os.find_abs_path_of_executable('my_exe') or {
		eprintln('skipping test, since `my_exe` is missing')
		exit(0)
	})
	single_line_test_path = os.join_path(os.vtmp_dir(), 'my_test_path')
)

Changed:

import os

const (
	exe = os.find_abs_path_of_executable('my_exe') or {
		eprintln('skipping test, since `my_exe` is missing')
		exit(0)
	}
	// Now detects or block in call arg.
	exe_quoted = os.quoted_path(os.find_abs_path_of_executable('my_exe') or {
		eprintln('skipping test, since `my_exe` is missing')
		exit(0)
	})
	single_line_test_path = os.join_path(os.vtmp_dir(), 'my_test_path')
)

馃 Generated by Copilot at 08b020b

Improve the formatting of call expressions with or blocks and add a test file to verify it. Fix issue #11197 by modifying expr_is_single_line in vlib/v/fmt/fmt.v.

馃 Generated by Copilot at 08b020b

  • Fix formatting of call expressions with or blocks (link)
  • Add test cases for formatting of call expressions with or blocks as constants (link)

@ttytm ttytm marked this pull request as draft October 28, 2023 23:10
@ttytm ttytm marked this pull request as ready for review October 29, 2023 00:11
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Excellent.

@spytheman spytheman merged commit 5c2eafc into vlang:master Oct 29, 2023
41 checks passed
sibkod pushed a commit to sibkod/v that referenced this pull request Oct 30, 2023
@ttytm ttytm deleted the fmt/fix-call-arg-or-block branch November 1, 2023 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants