-- lx format
local format = require("core.format")

format.register({
	name = "Git Ignore",
	shortname = "gitignore",
	author = "liqube",
	comment = "#",

	filenames = {
		".gitignore",
		".dockerignore",
		".ignore",
		".npmignore",
		".eslintignore",
		".prettierignore",
		".rgignore",
		".fdignore",
		"gitignore_global.txt",
	},

	patterns = {
		-- Escaped leading marker tokens (\# and \!)
		{ pattern = "%s*\\[#!].-\n", type = "string", line_start = true },
		{ pattern = "%s*#.-\n", type = "comment", line_start = true },

		-- Negation pattern prefix
		{ pattern = "%s*!%f[%S]", type = "operator", line_start = true },

		-- Root-relative patterns
		{ pattern = "%s*/", type = "operator", line_start = true },

		-- Glob pieces
		{ pattern = "%*%*", type = "keyword2" },
		{ pattern = "%[[^%]\n]+%]", type = "keyword2" },
		{ pattern = "[%*%?]", type = "keyword2" },

		-- Path separators
		{ pattern = "\\", type = "operator" },
		{ pattern = "/", type = "operator" },
		{ pattern = "[^%s!#%*%?%[%]\\/\n]+", type = "symbol" },
	},

	outline_patterns = {
		{ pattern = "#", line_start = true, block_start_only = true },
	},
})
