mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: insert newline after last HashStmt (#8482)
This commit is contained in:
parent
53a5aad855
commit
d660f2cc6f
@ -1752,7 +1752,7 @@ Global variables are not allowed, so this can be really useful.
|
||||
When naming constants, `snake_case` must be used. In order to distinguish consts
|
||||
from local variables, the full path to consts must be specified. For example,
|
||||
to access the PI const, full `math.pi` name must be used both outside the `math`
|
||||
module, and inside it. That restriction is relaxed only for the `main` module
|
||||
module, and inside it. That restriction is relaxed only for the `main` module
|
||||
(the one containing your `fn main()`, where you can use the shorter name of the
|
||||
constants too, i.e. just `println(numbers)`, not `println(main.numbers)` .
|
||||
|
||||
@ -3413,7 +3413,7 @@ single block. `customflag` should be a snake_case identifier, it can not
|
||||
contain arbitrary characters (only lower case latin letters + numbers + `_`).
|
||||
NB: a combinatorial `_d_customflag_linux.c.v` postfix will not work.
|
||||
If you do need a custom flag file, that has platform dependent code, use the
|
||||
postfix `_d_customflag.v`, and then use plaftorm dependent compile time
|
||||
postfix `_d_customflag.v`, and then use plaftorm dependent compile time
|
||||
conditional blocks inside it, i.e. `$if linux {}` etc.
|
||||
|
||||
## Compile time pseudo variables
|
||||
|
@ -4,6 +4,7 @@ module big
|
||||
#flag -I @VROOT/thirdparty/bignum
|
||||
#flag @VROOT/thirdparty/bignum/bn.o
|
||||
#include "bn.h"
|
||||
|
||||
struct C.bn {
|
||||
mut:
|
||||
array [32]u32
|
||||
|
@ -2,6 +2,7 @@ module os
|
||||
|
||||
#include <sys/stat.h> // #include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
struct C.dirent {
|
||||
d_name [256]char
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
module os
|
||||
|
||||
#include "@VROOT/vlib/os/os_darwin.m"
|
||||
|
||||
pub const (
|
||||
sys_write = 4
|
||||
sys_open = 5
|
||||
|
@ -6,6 +6,7 @@ import strings
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
pub const (
|
||||
path_separator = '/'
|
||||
path_delimiter = ':'
|
||||
|
@ -3,6 +3,7 @@ module os
|
||||
import strings
|
||||
|
||||
#include <process.h>
|
||||
|
||||
pub const (
|
||||
path_separator = '\\'
|
||||
path_delimiter = ';'
|
||||
|
@ -4,6 +4,7 @@
|
||||
module time
|
||||
|
||||
#include <time.h>
|
||||
|
||||
const (
|
||||
days_string = 'MonTueWedThuFriSatSun'
|
||||
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||
|
@ -1,6 +1,7 @@
|
||||
module time
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
const (
|
||||
// start_time is needed on Darwin and Windows because of potential overflows
|
||||
start_time = C.mach_absolute_time()
|
||||
|
@ -4,6 +4,7 @@
|
||||
module time
|
||||
|
||||
#include <time.h>
|
||||
|
||||
struct C.tm {
|
||||
tm_sec int
|
||||
tm_min int
|
||||
|
@ -5,6 +5,7 @@ module time
|
||||
|
||||
#include <time.h>
|
||||
// #include <sysinfoapi.h>
|
||||
|
||||
struct C.tm {
|
||||
tm_year int
|
||||
tm_mon int
|
||||
|
@ -7,6 +7,7 @@ import v.cflag
|
||||
#flag windows -l shell32
|
||||
#flag windows -l dbghelp
|
||||
#flag windows -l advapi32
|
||||
|
||||
struct MsvcResult {
|
||||
full_cl_exe_path string
|
||||
exe_path string
|
||||
|
@ -295,6 +295,9 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
|
||||
|
||||
fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
|
||||
prev_line_nr := prev_stmt.position().last_line
|
||||
if prev_stmt is ast.HashStmt && stmt !is ast.HashStmt && stmt !is ast.ExprStmt {
|
||||
return true
|
||||
}
|
||||
// The stmt either has or shouldn't have a newline before
|
||||
if stmt.position().line_nr - prev_line_nr <= 1 || f.out.last_n(2) == '\n\n' {
|
||||
return false
|
||||
|
3
vlib/v/fmt/tests/hashstmt_expected.vv
Normal file
3
vlib/v/fmt/tests/hashstmt_expected.vv
Normal file
@ -0,0 +1,3 @@
|
||||
#include "header.h"
|
||||
|
||||
struct Foo {}
|
2
vlib/v/fmt/tests/hashstmt_input.vv
Normal file
2
vlib/v/fmt/tests/hashstmt_input.vv
Normal file
@ -0,0 +1,2 @@
|
||||
#include "header.h"
|
||||
struct Foo {}
|
12
vlib/v/fmt/tests/hashstmt_keep.vv
Normal file
12
vlib/v/fmt/tests/hashstmt_keep.vv
Normal file
@ -0,0 +1,12 @@
|
||||
// comment above HashStmt
|
||||
#flag -I @VROOT/c
|
||||
#flag @VROOT/c/implementation.o
|
||||
|
||||
#include "@VROOT/c/implementation.h"
|
||||
|
||||
// comment between with newlines around
|
||||
|
||||
#include "header.h"
|
||||
// comment between without newlines
|
||||
#include "sqlite3.h"
|
||||
// comment directly after the HsahStmt
|
@ -1,8 +0,0 @@
|
||||
// comment above HashStmts
|
||||
#flag linux -lsdl2
|
||||
#include "stdio.h"
|
||||
|
||||
// comment between with newlines around
|
||||
|
||||
#include "header.h"
|
||||
#include "sqlite3.h"
|
@ -1,3 +0,0 @@
|
||||
#flag -I @VROOT/c
|
||||
#flag @VROOT/c/implementation.o
|
||||
#include "@VROOT/c/implementation.h"
|
Loading…
Reference in New Issue
Block a user