Line data Source code
1 : -- lua/yoda/filetype/detection.lua
2 : -- Filetype detection patterns and configuration
3 :
4 10 : local M = {}
5 :
6 : -- ============================================================================
7 : -- Detection Patterns
8 : -- ============================================================================
9 :
10 10 : M.PATTERNS = {
11 10 : jenkinsfile = {
12 : "Jenkinsfile",
13 : "*.Jenkinsfile",
14 : "jenkinsfile",
15 : "*.jenkinsfile",
16 : "*.jenkins",
17 : "*jenkins*",
18 10 : },
19 10 : }
20 :
21 : -- ============================================================================
22 : -- Filetype Handlers
23 : -- ============================================================================
24 :
25 : --- Configure Jenkinsfile for Groovy syntax with Jenkins keywords
26 10 : function M.configure_jenkinsfile()
27 5 : vim.bo.filetype = "groovy"
28 : -- Set syntax explicitly: in headless/test environments the FileType event
29 : -- may not fire, so we can't rely on it to load the groovy syntax file.
30 5 : vim.bo.syntax = "groovy"
31 :
32 : -- Add Jenkins-specific keywords for better syntax highlighting
33 10 : vim.cmd([[
34 : syntax keyword groovyKeyword pipeline agent stages stage steps script sh bat powershell
35 : syntax keyword groovyKeyword when environment parameters triggers tools options
36 : syntax keyword groovyKeyword post always success failure unstable changed cleanup
37 : syntax keyword groovyKeyword parallel matrix node checkout scm git svn
38 : syntax keyword groovyKeyword build publishHTML archiveArtifacts publishTestResults
39 : syntax keyword groovyKeyword junit testReport emailext slackSend
40 : syntax match groovyFunction /\w\+\s*(/
41 5 : ]])
42 15 : end
43 :
44 : -- ============================================================================
45 : -- Setup Functions
46 : -- ============================================================================
47 :
48 : --- Setup Jenkinsfile detection autocmd
49 : --- @param autocmd function vim.api.nvim_create_autocmd function
50 : --- @param augroup function vim.api.nvim_create_augroup function
51 10 : function M.setup_jenkinsfile_detection(autocmd, augroup)
52 8 : autocmd({ "BufRead", "BufNewFile" }, {
53 8 : group = augroup("YodaJenkinsfile", { clear = true }),
54 : desc = "Detect Jenkinsfile and configure for Jenkins Pipeline syntax",
55 4 : pattern = M.PATTERNS.jenkinsfile,
56 4 : callback = M.configure_jenkinsfile,
57 : })
58 14 : end
59 :
60 : --- Setup all filetype detection autocmds
61 : --- @param autocmd function vim.api.nvim_create_autocmd function
62 : --- @param augroup function vim.api.nvim_create_augroup function
63 10 : function M.setup_all(autocmd, augroup)
64 2 : M.setup_jenkinsfile_detection(autocmd, augroup)
65 12 : end
66 :
67 10 : return M
|