Caddy is relatively old, but there is not filetype for it.
I wanted to do highlighting as well, but didn't want to "adopt" vim-caddyfile, so with help of syntax/nginx.vim and Google, I come up with this:
Screenshot.2025-01-26.at.21.15.37.png (view on web)
Time to dive deep into vim script, heh 😏
Happy to be reviewed! Thank you!
https://github.com/vim/vim/pull/16525
(7 files)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Don't you want to set the filetype to caddy (to match your tree-sitter parser)?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@clason commented on this pull request.
> @@ -434,6 +434,7 @@ runtime/syntax/bzr.vim @hdima runtime/syntax/cabal.vim @coot runtime/syntax/cabalconfig.vim @coot runtime/syntax/cabalproject.vim @coot +runtime/syntax/caddy.vim @opa-oz
Here it's caddy, not caddyfile.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@dkearns requested changes on this pull request.
Thanks.
You need to generate and commit a dump file for the syntax test. There are instructions in `runtime/syntax/testdir/README.txt
> @@ -434,6 +434,7 @@ runtime/syntax/bzr.vim @hdima runtime/syntax/cabal.vim @coot runtime/syntax/cabalconfig.vim @coot runtime/syntax/cabalproject.vim @coot +runtime/syntax/caddy.vim @opa-oz
The runtime files should match the filetype name. So this should be caddyfile.vim.
I'm assuming there's a reason to be specific and call this caddyfile rather than just caddy, like there being other Caddy related files not covered by this filetype?
> @@ -329,6 +329,10 @@ au BufNewFile,BufRead *.lpc,*.ulpc setf lpc " C3 au BufNewFile,BufRead *.c3,*.c3i,*.c3t setf c3 +" Caddyfile; +" Also see Caddyfile.* below. +au BufNewFile,BufRead Caddyfile,caddyfile,*.[cC]addyfile setf caddyfile⬇️ Suggested change
-au BufNewFile,BufRead Caddyfile,caddyfile,*.[cC]addyfile setf caddyfile +au BufNewFile,BufRead [cC]addyfile,*.[cC]addyfile setf caddyfile
In runtime/syntax/caddyfile.vim:
> @@ -0,0 +1,52 @@ +" Vim syntax file +" Language: caddy configure file⬇️ Suggested change
-" Language: caddy configure file +" Language: Caddy configuration file
In runtime/syntax/caddyfile.vim:
> @@ -0,0 +1,52 @@ +" Vim syntax file +" Language: caddy configure file +" Maintainer: Vladimir Levin <opao...@gmail.com> +" Last Change: 2025 Jan 26 + +" Quit when a (custom) syntax file was already loaded +if exists("b:current_syntax") + finish +endif + +syn keyword caddyTodo contained TODO FIXME XXX
As well as renaming the file to caddyfile.vim the syntax group prefixes should also match. E.g. caddyfileTodo
In runtime/syntax/caddyfile.vim:
> +
+syn region caddyPlaceholder start=+{+ end=+}+ oneline
+
+" These regular expressions where taken from `syntax/nginx.vim`
+syn match caddyInteger '\W\zs\(\d[0-9.]*\|[0-9.]*\d\)\w\?\ze\W'
+syn match caddyIPaddr '\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{6}\(\x\{1,4}:\x\{1,4}\|\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[::\(\(\x\{1,4}:\)\{,6}\x\{1,4}\|\(\x\{1,4}:\)\{,5}\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{1}:\(\(\x\{1,4}:\)\{,5}\x\{1,4}\|\(\x\{1,4}:\)\{,4}\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{2}:\(\(\x\{1,4}:\)\{,4}\x\{1,4}\|\(\x\{1,4}:\)\{,3}\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{3}:\(\(\x\{1,4}:\)\{,3}\x\{1,4}\|\(\x\{1,4}:\)\{,2}\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{4}:\(\(\x\{1,4}:\)\{,2}\x\{1,4}\|\(\x\{1,4}:\)\{,1}\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{5}:\(\(\x\{1,4}:\)\{,1}\x\{1,4}\|\([0-2]\?\d\{1,2}\.\)\{3}[0-2]\?\d\{1,2}\)\]'
+syn match caddyIPaddr '\[\(\x\{1,4}:\)\{6}:\x\{1,4}\]'
+" Highlight wildcard listening signs also as IPaddr
+syn match ngxIPaddr '\s\zs\[::]'
⬇️ Suggested change
-syn match ngxIPaddr '\s\zs\[::]' +syn match caddyfileIPaddr '\s\zs\[::]'
And the next line.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Don't you want to set the filetype to caddy (to match your tree-sitter parser)?
@clason actually, after I looked at Dockerfile in this repo - I'll rename
caddytocaddyfilein my TreeSitter PR :)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@opa-oz commented on this pull request.
> @@ -434,6 +434,7 @@ runtime/syntax/bzr.vim @hdima runtime/syntax/cabal.vim @coot runtime/syntax/cabalconfig.vim @coot runtime/syntax/cabalproject.vim @coot +runtime/syntax/caddy.vim @opa-oz
I'm assuming there's a reason to be specific and call this caddyfile rather than just caddy, like there being other Caddy related files not covered by this filetype?
I wanted be aligned with Dockerfile, since it's very alike - single file to rule them all. Technically it's written that you can import other files, but I couldn't find information - what extensions.
If I search via Github, I see people having:
config/
multiple_upstream.Caddyfile
reverse_proxy.Caddyfile
And I also saw:
proxy/
Caddyfile.prod
Caddyfile.dev
Don't mind renaming, if you think it's better :)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I'll rename caddy to caddyfile in my TreeSitter PR :)
You can't do that; the name is fixed in the grammar. But let's keep that discussion there; here I just wanted to draw attention to the mismatch and make sure it's intentional.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@opa-oz pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@dkearns sorry for being uneducated:
Screenshot.2025-01-26.at.22.48.05.png (view on web)
Second dump file (common_patterns_01.dump) is just a half of initial file. Is it to be expected?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Second dump file (common_patterns_01.dump) is just a half of initial file. Is it to be expected?
Yes, there's overlap.
Sorry, I didn't notice on the first pass but the test file needs to start with the filetype name. So it should be named caddyfile_common_patterns.caddyfile or just caddyfile.caddyfile while there's only one.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Do we also need a filetype plugin (e.g. for setting the commentstring)?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
@chrisbra @mailing-list-enjoyers
Good questions!
To be completely honest, I'm mostly interested in filetype association, since right now the Caddyfile is just a generic conf file. I jumped in here to address only this issue, but without associating any syntax with the new filetype, I thought it would be rather unfriendly.
I considered this syntax option:
" Vim syntax file " Language: Caddy configure file " Maintainer: Vladimir Levin <opao...@gmail.com>
" Last Change: 2025 Jan 26
" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax") finish endif " The actual syntax is in conf.vim runtime! syntax/conf.vim let b:current_syntax = "caddyfile"
This should be consistent with previous versions (Caddyfile will still use the conf syntax), but the filetype will change to caddyfile, which makes it easier to integrate with tree-sitter, LSP, and formatters.
The choice is yours 🙇
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.![]()
I think using a separate syntax file is fine. I wouldn't runtime the nginx.vim file, unless you are sure both filetypes will use the same highlighting rules.
I'd also think about a very generic filetype, like this:
" Vim ftplugin file " Language: Caddyfile " Maintainer: Your Name " Last Change: Date " Only do this when not done yet for this buffer if exists("b:did_ftplugin") finish endif let b:did_ftplugin = 1 setlocal commentstring=#\ %s let b:undo_ftplugin = "setlocal commentstring<"
Thanks
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
this has stalled, so closing
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you commented.![]()