[vim/vim] runtime(filetype): add Caddyfile filetype (PR #16525)

45 views
Skip to first unread message

Vladimir Levin

unread,
Jan 26, 2025, 7:17:44 AM1/26/25
to vim/vim, Subscribed

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!

Checklist

  • to add a new filetype test (keep it similar to the other filetype tests).
  • all configuration switches should be documented (check filetype.txt and/or syntax.txt for filetype and syntax plugins)
  • add yourself as Maintainer to the top of file (again, keep the header similar to other runtime files)
  • add yourself to the MAINTAINERS file.

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/16525

Commit Summary

  • f83dca8 runtime(filetype): add Caddyfile filetype

File Changes

(7 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16525@github.com>

Christian Clason

unread,
Jan 26, 2025, 8:00:23 AM1/26/25
to vim/vim, Subscribed

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.Message ID: <vim/vim/pull/16525/c2614408899@github.com>

Christian Clason

unread,
Jan 26, 2025, 8:01:03 AM1/26/25
to vim/vim, Subscribed

@clason commented on this pull request.


In .github/MAINTAINERS:

> @@ -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.Message ID: <vim/vim/pull/16525/review/2574273150@github.com>

dkearns

unread,
Jan 26, 2025, 8:05:30 AM1/26/25
to vim/vim, Subscribed

@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


In .github/MAINTAINERS:

> @@ -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?


In runtime/filetype.vim:

> @@ -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.Message ID: <vim/vim/pull/16525/review/2574272860@github.com>

Vladimir Levin

unread,
Jan 26, 2025, 8:12:31 AM1/26/25
to vim/vim, Subscribed

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 caddy to caddyfile in my TreeSitter PR :)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16525/c2614413431@github.com>

Vladimir Levin

unread,
Jan 26, 2025, 8:19:58 AM1/26/25
to vim/vim, Subscribed

@opa-oz commented on this pull request.


In .github/MAINTAINERS:

> @@ -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.Message ID: <vim/vim/pull/16525/review/2574277239@github.com>

Christian Clason

unread,
Jan 26, 2025, 8:21:56 AM1/26/25
to vim/vim, Subscribed

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.Message ID: <vim/vim/pull/16525/c2614417085@github.com>

Vladimir Levin

unread,
Jan 26, 2025, 8:47:52 AM1/26/25
to vim/vim, Push

@opa-oz pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16525/before/f83dca8c882edd4f53917d710a3f89552b0d0ee8/after/506944b03887b1308d411ae188988e489d4157ae@github.com>

Vladimir Levin

unread,
Jan 26, 2025, 8:49:38 AM1/26/25
to vim/vim, Subscribed

@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.Message ID: <vim/vim/pull/16525/c2614432220@github.com>

dkearns

unread,
Jan 26, 2025, 10:12:56 AM1/26/25
to vim/vim, Subscribed

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.Message ID: <vim/vim/pull/16525/c2614463429@github.com>

Christian Brabandt

unread,
Jan 26, 2025, 10:55:05 AM1/26/25
to vim/vim, Subscribed

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.Message ID: <vim/vim/pull/16525/c2614482266@github.com>

vim-dev ML

unread,
Jan 26, 2025, 12:53:55 PM1/26/25
to vim/vim, vim-dev ML, Your activity

On Sun, 2025-01-26 at 07:54 -0800, Christian Brabandt wrote:
> Do we also need a filetype plugin (e.g. for setting the commentstring)?

Like the one shipped with the existing out-of-tree plugin?

That also has indent support, and what appears to be more complete
syntax support. This change just creates conflicts for anyone who uses
that plugin.

Is there any reason *at all* to prefer this version?

-Rob


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16525/c2614526284@github.com>

Vladimir Levin

unread,
Jan 26, 2025, 9:05:54 PM1/26/25
to vim/vim, vim-dev ML, Comment

@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.

  1. If you’re okay with this approach, I can implement it.
  2. Alternatively, I can dive into mastering Vimscript and provide a syntax that could compete with the vim-caddyfile plugin (I’ve already spent a weekend working on tree-sitter parsing/highlighting, so I feel positive about this).
  3. As a third option, I could reach out to the author of the vim-caddyfile plugin to ask if they’d be willing to merge this PR (or create a separate one). I’m not sure what the policy is for onboarding plugins into "vim-core."

The choice is yours 🙇


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/16525/c2614725605@github.com>

Christian Brabandt

unread,
Jan 27, 2025, 3:38:38 AM1/27/25
to vim/vim, vim-dev ML, Comment

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.Message ID: <vim/vim/pull/16525/c2615132306@github.com>

Christian Brabandt

unread,
Jun 13, 2026, 4:12:54 PM (10 hours ago) Jun 13
to vim/vim, vim-dev ML, Comment
chrisbra left a comment (vim/vim#16525)

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.Message ID: <vim/vim/pull/16525/c4699660131@github.com>

Reply all
Reply to author
Forward
0 new messages