├── docs └── example.gif ├── after └── plugin │ └── cmp_jenkins.lua ├── README.md └── lua └── cmp_jenkins └── init.lua /docs/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshzcold/cmp-jenkinsfile/HEAD/docs/example.gif -------------------------------------------------------------------------------- /after/plugin/cmp_jenkins.lua: -------------------------------------------------------------------------------- 1 | require('cmp').register_source('jenkinsfile', require('cmp_jenkins').new()) 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cmp-jenkinsfile 2 | 3 | simple completion utilizing the `IntelliJ IDEA GDSL` file that gets generated for installed jenkins plugins. 4 | 5 | *example gdsl* 6 | 7 | ``` 8 | method(name: 'parallel', type: 'Object', params: ['closures':'java.util.Map'], doc: 'Execute in parallel') 9 | method(name: 'parallel', type: 'Object', namedParams: [parameter(name: 'closures', type: 'java.util.Map'), parameter(name: 'failFast', type: 'boolean'), ], doc: 'Execute in parallel') 10 | ``` 11 | 12 | ## demo 13 | 14 | ![example gif](./docs/example.gif) 15 | 16 | ## options 17 | 18 | **jenkins_url**: full jenkins url to download the gdsl from. 19 | 20 | example: `http://jenkins.lab/` 21 | 22 | `/pipeline-syntax/gdsl` will automatically be append to the end of the url. 23 | 24 | **gdsl_file**: full path to either download to or statically read from. 25 | 26 | If `jenkins_url` is supplied then this file will be written to. If `jenkins_url` is blank then only read from the supplied path 27 | 28 | defaults to: `$HOME/.cache/nvim/cmp-jenkinsfile.gdsl` 29 | 30 | **http**: optional http configuration 31 | - **basic_auth_user**: username for basic authentication 32 | - **basic_auth_password**: password for basic authentication 33 | - **ca_cert**: path to CA certificate file 34 | - **proxy**: proxy URL 35 | 36 | **Recommended Config:** 37 | 38 | ```lua 39 | cmp.setup({ 40 | cmp.setup.filetype("Jenkinsfile", { 41 | sources = { 42 | { 43 | name = "jenkinsfile", 44 | option = { 45 | jenkins_url = "https://jenkins.co", 46 | }, 47 | }, 48 | }, 49 | }), 50 | ``` 51 | 52 | **Full Config:** 53 | 54 | ```lua 55 | cmp.setup({ 56 | cmp.setup.filetype("Jenkinsfile", { 57 | sources = { 58 | { 59 | name = "jenkinsfile", 60 | option = { 61 | jenkins_url = "https://jenkins.co", 62 | gdsl_file = "~/.cache/nvim/cmp-jenkinsfile.gdsl", 63 | http = { 64 | basic_auth_user = "admin", 65 | basic_auth_password = "adminadmin", 66 | ca_cert = "/etc/ssl/certs/cacert", 67 | proxy = "http://internal-proxy:8000", 68 | }, 69 | }, 70 | }, 71 | }, 72 | }), 73 | ``` 74 | -------------------------------------------------------------------------------- /lua/cmp_jenkins/init.lua: -------------------------------------------------------------------------------- 1 | local source = {} 2 | 3 | local defaults = { 4 | gdsl_file = os.getenv("HOME").."/.cache/nvim/cmp-jenkinsfile.gdsl", 5 | jenkins_url = "", 6 | http = { 7 | basic_auth_user = "", 8 | basic_auth_password = "", 9 | ca_cert = "", 10 | proxy = "", 11 | }, 12 | } 13 | 14 | local function file_exists(name) 15 | local f=io.open(name,"r") 16 | if f~=nil then io.close(f) return true else return false end 17 | end 18 | 19 | local function file_is_empty(name) 20 | local file = io.open(name,"r") 21 | if not file then return true end 22 | local content = file:read "*a" 23 | local res = string.match(content,"(method)") 24 | return res == nil 25 | end 26 | 27 | local function build_curl(jenkins_url, opts) 28 | local cmd = "curl --silent -X GET "..jenkins_url.."/pipeline-syntax/gdsl" 29 | if opts.proxy ~= "" then 30 | cmd = cmd.." --proxy "..opts.proxy 31 | end 32 | if opts.ca_cert ~= "" then 33 | cmd = cmd.." --cacert "..opts.ca_cert 34 | end 35 | if opts.basic_auth_user ~= "" then 36 | cmd = cmd.." --basic --user "..opts.basic_auth_user..":"..opts.basic_auth_password 37 | end 38 | return cmd 39 | end 40 | 41 | function source.new() 42 | return setmetatable({}, { __index = source }) 43 | end 44 | 45 | function source:complete(params, callback) 46 | params.option = vim.tbl_deep_extend('keep', params.option, defaults) 47 | vim.validate('gdsl_file', params.option.gdsl_file, 'string', false, '`opts.gdsl_file` must be `string`') 48 | vim.validate('jenkins_url', params.option.jenkins_url, 'string', false, '`opts.jenkins_url` must be `string`') 49 | vim.validate('http', params.option.http, 'table', false, '`opts.http` must be `table`') 50 | vim.validate('http.basic_auth_user', params.option.http.basic_auth_user, 'string', false, '`opts.http.basic_auth_user` must be `string`') 51 | vim.validate('http.basic_auth_password', params.option.http.basic_auth_password, 'string', false, '`opts.http.basic_auth_password` must be `string`') 52 | vim.validate('http.ca_cert', params.option.http.ca_cert, 'string', false, '`opts.http.ca_cert` must be `string`') 53 | vim.validate('http.proxy', params.option.http.proxy, 'string', false, '`opts.http.proxy` must be `string`') 54 | 55 | if params.option.jenkins_url ~= "" then 56 | if not file_exists(params.option.gdsl_file) or file_is_empty(params.option.gdsl_file) then 57 | local curl_cmd = build_curl(params.option.jenkins_url, params.option.http) 58 | local handle = io.popen(curl_cmd.." > "..params.option.gdsl_file) 59 | if handle ~= nil then 60 | local result = handle:read("*a") 61 | print(result) 62 | handle:close() 63 | end 64 | end 65 | end 66 | 67 | local _vals = {} 68 | local items = {} 69 | local file = io.open(params.option.gdsl_file) 70 | if file ~= nil then 71 | 72 | local lines = file:lines() 73 | for line in lines do 74 | local _name, _type, _params, _doc = line:match("name: '(.*)', type: '(.*)', namedParams: (%[.*%]), doc: '(.*)'") 75 | if _params == nil then 76 | _name, _type, _params, _doc = line:match("name: '(.*)', type: '(.*)', params: (%[.*%]), doc: '(.*)'") 77 | end 78 | 79 | if _name ~= nil and _type ~= nil and _params ~= nil and _doc ~= nil then 80 | -- print("name: "..name.." type: "..type.." params: "..params.." doc: "..doc) 81 | if _vals[_name] then 82 | _vals[_name].detail = _vals[_name].detail.."\n---------------\n".._params 83 | else 84 | _vals[_name] = { 85 | label = _name, 86 | detail = _doc.."\n\n".._params 87 | } 88 | end 89 | end 90 | end 91 | 92 | for _, v in pairs(_vals) do 93 | table.insert(items, { 94 | label = v.label, 95 | detail = v.detail, 96 | dup = 0 97 | }) 98 | end 99 | 100 | io.close(file) 101 | callback({ 102 | items = items, 103 | isIncomplete = false 104 | }) 105 | end 106 | end 107 | 108 | return source 109 | 110 | --------------------------------------------------------------------------------