1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: support ctags with -print_v_files and .ctags.d/v.ctags

This commit is contained in:
Delyan Angelov 2020-04-30 19:15:30 +03:00
parent 250dea7bd1
commit a6dfc6d46b
7 changed files with 71 additions and 2 deletions

44
.ctags.d/v.ctags Normal file
View File

@ -0,0 +1,44 @@
## TODO: support more precise struct/const/enum fields
--langdef=V
--map-V=+.v
--map-V=+.vv
--map-V=+.vsh
--kinddef-V=m,imodule,imported modules
--kinddef-V=M,module,modules
--kinddef-V=C,cfunction,cfunctions
--kinddef-V=f,function,functions
--kinddef-V=h,method,functions
--kinddef-V=c,const,constants
--kinddef-V=v,variable,variables
--kinddef-V=s,struct,structs
--kinddef-V=e,enum,enums
--kinddef-V=i,interface,interfaces
--kinddef-V=S,sfield,struct field
--kinddef-V=E,efield,enum field
--_roledef-V=m.imported,imported module
--_roledef-V=M.declared,module declaration
--regex-V=/^module[[:blank:]]+([0-9a-zA-Z]+)[[:blank:]]*$/\1/M/{_role=declared}{scope=push}
--regex-V=/^import[[:blank:]]+(([0-9a-zA-Z]+)?|.*\.([a-zA-Z_][0-9a-zA-Z]+))[[:blank:]]*$/\2\3/m/{_role=imported}{scope=ref}
--regex-V=/^[[:blank:]]*fn[[:blank:]]+C\.([a-zA-Z_][0-9a-zA-Z_]*)\(/C.\1/C/
--regex-V=/^(pub)?[[:blank:]]*fn[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)\(/\2/f/
--regex-V=/^(pub)?[[:blank:]]*fn[[:blank:]]+\(.*\)[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]*)\(/\2/h/
--regex-V=/^(pub)?[[:blank:]]*struct[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)[[:blank:]]*\{/\2/s/{scope=push}
--regex-V=/^(pub)?[[:blank:]]*enum[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)[[:blank:]]*\{/\2/e/{scope=push}
--regex-V=/^(pub)?[[:blank:]]*interface[[:blank:]]+([a-zA-Z_][0-9a-zA-Z_]*)[[:blank:]]*\{/\2/i/{scope=push}
--regex-V=/^[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]*(,)?[[:blank:]]*(\/\/.*)?$/\1/E/{scope=ref}
--regex-V=/^[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]+\??\&?(\[[0-9]*\])?([a-zA-Z_][0-9a-zA-Z_.]+)[[:blank:]]*(\/\/.*)?$/\1/S/{scope=ref}
--regex-V=/^[[:blank:]]*\}[[:blank:]]*$//{scope=pop}{placeholder}
## Variables:
--regex-V=/^[[:blank:]]*(mut[[:blank:]]*)([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]*:=/\2/v/{scope=ref}
## Consts:
--regex-V=/^(pub)?[[:blank:]]*const[[:blank:]]+\([[:blank:]]*/const/c/{scope=push}
##NB: the next variable regexp should work only inside const ( ), but currently works for ordinary assignments too:
--regex-V=/^[[:blank:]]*([a-zA-Z_][0-9a-zA-Z_]+)[[:blank:]]*=/\1/v/{scope=ref}
--regex-V=/^[[:blank:]]*\)[[:blank:]]*$//{scope=pop}{placeholder}
--extras=+q
--extras=+r
--fields=+r

View File

@ -89,6 +89,18 @@ The build flags are shared by the build and run commands:
-v, -vv, -vvv
Enable varying verbosity in the V compiler while compiling
-print_v_files
Just print the list of all parsed .v files, then stop processing further.
This is useful for running external processing tools:
./v -print_v_files cmd/v | etags -L -
... will generate a TAGS file, that emacs can then use to jump
to the definition of functions used by v itself. For vim:
./v -print_v_files cmd/v | ctags -L -
... will generate a simillar tags file, that vi compatible editors can use.
NB: an useful, although not entirely accurate regexp based Universal Ctags options file
for V is located in `.ctags.d/v.ctags` . If you use https://ctags.io/ , it will be used
up automatically, or you can specify it explicitly with --options=.ctags.d/v.ctags .
For C-specific build flags, use `v help build-c`.
See also:

View File

@ -174,6 +174,9 @@ fn parse_args(args []string) (&pref.Preferences, string) {
'-x64' {
res.backend = .x64
}
'-print_v_files' {
res.print_v_files = true
}
'-os' {
target_os := cmdline.option(current_args, '-os', '')
i++

View File

@ -82,6 +82,13 @@ pub fn (mut b Builder) parse_imports() {
}
}
b.resolve_deps()
//
if b.pref.print_v_files {
for p in b.parsed_files {
println(p.path)
}
exit(0)
}
}
pub fn (mut b Builder) resolve_deps() {

View File

@ -33,10 +33,11 @@ pub fn (mut b Builder) gen_c(v_files []string) string {
pub fn (mut b Builder) build_c(v_files []string, out_file string) {
b.out_name_c = out_file
b.info('build_c($out_file)')
output := b.gen_c(v_files)
mut f := os.create(out_file) or {
panic(err)
}
f.writeln(b.gen_c(v_files))
f.writeln(output)
f.close()
// os.write_file(out_file, b.gen_c(v_files))
}

View File

@ -29,10 +29,11 @@ pub fn (mut b Builder) gen_js(v_files []string) string {
pub fn (mut b Builder) build_js(v_files []string, out_file string) {
b.out_name_js = out_file
b.info('build_js($out_file)')
output := b.gen_js(v_files)
mut f := os.create(out_file) or {
panic(err)
}
f.writeln(b.gen_js(v_files))
f.writeln(output)
f.close()
}

View File

@ -80,6 +80,7 @@ pub mut:
mod string
run_args []string // `v run x.v 1 2 3` => `1 2 3`
printfn_list []string // a list of generated function names, whose source should be shown, for debugging
print_v_files bool // when true, just print the list of all parsed .v files then stop.
}
pub fn backend_from_string(s string) ?Backend {