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

vfmt erasing lines of code following // vfmt off #21518

Closed
islonely opened this issue May 17, 2024 · 2 comments
Closed

vfmt erasing lines of code following // vfmt off #21518

islonely opened this issue May 17, 2024 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@islonely
Copy link
Contributor

islonely commented May 17, 2024

Describe the bug

vfmt is erasing lines of code inside // vfmt off blocks

Reproduction Steps

module core

import term.ui as tui
import rand

// Color contains an RGB value as `u8`.
type Color = tui.Color

// Color.hsl produces an RGB color from hue, saturation, and lightness values.
fn Color.hsl(h f32, s f32, l f32) Color {
	if s == 0 {
		ll := u8(l)
		return Color{ll, ll, ll}
	}

	qq := if l < 0.5 {
		l * (1 + s)
	} else {
		l + s - (l * s)
	}
	pp := (2 * l) - qq
	return Color{
		r: u8(hue(pp, qq, h + 1.0 / 3.0) * 255)
		g: u8(hue(pp, qq, h) * 255)
		b: u8(hue(pp, qq, h - 1.0 / 3.0) * 255)
	}
}

// Color.random generates a random `Color`.
[inline]
fn Color.random() Color {
	return Color{rand.u8(), rand.u8(), rand.u8()}
}

// Color.pastel generates a random pastel `Color`.
[inline]
fn Color.pastel() Color {
	// vfmt off
	return Color.hsl(
		rand.f32(),
		rand.f32_in_range(0.25, 0.95) or { panic('fn Color.pastel(): this should never happen.') },
		0.75 // rand.f32_in_range(0.75, 0.9) or { panic('fn Color.pasetl(): this should never happen.') }
	)
	// vfmt on
}

// hue is used to help convert HSL to RGB in `fn Color.hsl`.
fn hue(p f32, q f32, _t f32) f32 {
	// vfmt off
	mut t := _t
	if t < 0 { t += 1 }
	if t > 1 { t -= 1 }
	if t < 1.0 / 6.0 { return p + (q - p) * 6 * t }
	if t < 1.0 / 2.0 { return q }
	if t < 2.0 / 3.0 { return p + (q - p) * (2.0 / 3.0 - t) * 6	}
	return p
	// vfmt on
}

Expected Behavior

Expected the only change to be [inline] to @[inline]. It has already been formatted on a previous version of V, so everything else should be proper.

Current Behavior

The line following // vfmt off is erased.

module core

import term.ui as tui
import rand

// Color contains an RGB value as `u8`.
type Color = tui.Color

// Color.hsl produces an RGB color from hue, saturation, and lightness values.
fn Color.hsl(h f32, s f32, l f32) Color {
	if s == 0 {
		ll := u8(l)
		return Color{ll, ll, ll}
	}

	qq := if l < 0.5 {
		l * (1 + s)
	} else {
		l + s - (l * s)
	}
	pp := (2 * l) - qq
	return Color{
		r: u8(hue(pp, qq, h + 1.0 / 3.0) * 255)
		g: u8(hue(pp, qq, h) * 255)
		b: u8(hue(pp, qq, h - 1.0 / 3.0) * 255)
	}
}

// Color.random generates a random `Color`.
@[inline]
fn Color.random() Color {
	return Color{rand.u8(), rand.u8(), rand.u8()}
}

// Color.pastel generates a random pastel `Color`.
@[inline]
fn Color.pastel() Color {
	// vfmt off
		rand.f32(),
		rand.f32_in_range(0.25, 0.95) or { panic('fn Color.pastel(): this should never happen.') },
		0.75 // rand.f32_in_range(0.75, 0.9) or { panic('fn Color.pasetl(): this should never happen.') }
	)
	// vfmt on
	// vfmt on
}

// hue is used to help convert HSL to RGB in `fn Color.hsl`.
fn hue(p f32, q f32, _t f32) f32 {
	// vfmt off
	if t < 0 { t += 1 }
	if t > 1 { t -= 1 }
	if t < 1.0 / 6.0 { return p + (q - p) * 6 * t }
	if t < 1.0 / 2.0 { return q }
	if t < 2.0 / 3.0 { return p + (q - p) * (2.0 / 3.0 - t) * 6	}
	return p
	// vfmt on
	// vfmt on
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.5 25777bd.eeaf8d9

Environment details (OS name and version, etc.)

V full version: V 0.4.5 25777bd.eeaf8d9
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 16 cpus, 64bit, little endian, 

getwd: C:\Users\imado\Documents\shattlebip
vexe: C:\Users\imado\v\v.exe
vexe mtime: 2024-05-17 02:45:52

vroot: OK, value: C:\Users\imado\v
VMODULES: OK, value: C:\Users\imado\.vmodules
VTMP: OK, value: C:\Users\imado\AppData\Local\Temp\v_0

Git version: git version 2.33.1.windows.1
Git vroot status: weekly.2023.41-1491-geeaf8d94
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc status: thirdparty-windows-amd64 e90c2620

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@islonely islonely added the Bug This tag is applied to issues which reports bugs. label May 17, 2024
@ttytm
Copy link
Member

ttytm commented May 18, 2024

Testing on Linux and Windows, I cannot reproduce the described issue.

Only the @ is added infront of the attributes.

@islonely
Copy link
Contributor Author

It is no longer performing how I described as well. I have v fmt set to run when I save a file in VSCode, so I guess it may have been something wrong with the extension I am using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

2 participants