mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-13 12:30:40 +08:00
feat(xmake): add xmake support
This commit is contained in:
parent
e6ac093930
commit
6ebee744ca
1
.gitignore
vendored
1
.gitignore
vendored
@ -42,3 +42,4 @@ view/
|
||||
.vim-bookmarks
|
||||
# ignore cache
|
||||
.cache/
|
||||
.xmake/
|
||||
|
@ -102,6 +102,7 @@ function! s:self.warp_nvim(argv, opts) abort dict
|
||||
let obj = {}
|
||||
let obj._argv = a:argv
|
||||
let obj._opts = a:opts
|
||||
let obj._jobs = self.jobs
|
||||
" @vimlint(EVL103, 1, a:job_id)
|
||||
" @vimlint(EVL103, 1, a:event)
|
||||
function! obj.__on_stdout(id, data, event) abort dict
|
||||
@ -137,9 +138,9 @@ function! s:self.warp_nvim(argv, opts) abort dict
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! obj.__on_exit(id, data, event) abort dict
|
||||
if has_key(self._opts, 'on_exit')
|
||||
let self._jobs[a:id][1] = a:data ? 'failed' : 'dead'
|
||||
call self._opts.on_exit(a:id, a:data, 'exit')
|
||||
endif
|
||||
endfunction
|
||||
@ -150,6 +151,7 @@ function! s:self.warp_nvim(argv, opts) abort dict
|
||||
\ 'argv': a:argv,
|
||||
\ 'opts': {
|
||||
\ '_opts': obj._opts,
|
||||
\ '_jobs' : obj._jobs,
|
||||
\ '_eof': '',
|
||||
\ 'on_stdout': obj.__on_stdout,
|
||||
\ 'on_stderr': obj.__on_stderr,
|
||||
|
31
autoload/SpaceVim/layers/xmake.vim
Normal file
31
autoload/SpaceVim/layers/xmake.vim
Normal file
@ -0,0 +1,31 @@
|
||||
"=============================================================================
|
||||
" xmake.vim --- xmake support for spacevim
|
||||
" Copyright (c) 2016-2023 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
|
||||
""
|
||||
" @section xmake, layers-xmake
|
||||
" @parentsection layers
|
||||
" The `xmake` layer provides basic function for xmake command.
|
||||
" This layer is disabled by default, to use it:
|
||||
" >
|
||||
" [[layers]]
|
||||
" name = 'xmake'
|
||||
" <
|
||||
|
||||
|
||||
function! SpaceVim#layers#xmake#plugins() abort
|
||||
let plugins = []
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/xmake.vim', {'merged' : 0}])
|
||||
return plugins
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#layers#cscope#config() abort
|
||||
call add(g:spacevim_project_rooter_patterns, 'xmake.lua')
|
||||
let g:_spacevim_mappings_space.m.x = {'name' : '+xmake'}
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'x', 'b'], 'call xmake#buildrun()', 'xmake-build-without-running', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['m', 'x', 'r'], 'call xmake#buildrun(1)', 'xmake-build-amd-running', 1)
|
||||
endfunction
|
24
bundle/xmake.vim/README.md
vendored
Normal file
24
bundle/xmake.vim/README.md
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# xmake.vim
|
||||
|
||||
> Vim/Neovim plugin for [xmake](https://github.com/tboox/xmake)
|
||||
|
||||
This plugin is inspired by [`luzhlon/xmake.vim`](https://github.com/luzhlon/xmake.vim/tree/5b20e97f5d0b063a97be23451c730d0278eef927)
|
||||
|
||||
## 功能
|
||||
|
||||
* 使用Vim打开xmake.lua文件时,加载对应的配置
|
||||
* 保存xmake.lua时重新加载配置
|
||||
* XMakek命令Tab键自动完成
|
||||
* 异步构建,构建前会保存所有文件
|
||||
* 构建失败自动打开quickfix窗口显示错误列表
|
||||
* 构建并运行(Windows GVim下打开新的cmd窗口运行,不阻塞GVim窗口)
|
||||
|
||||
## 命令
|
||||
|
||||
| 命令 | 功能 |
|
||||
| -------------------- | -------------------------------------------------- |
|
||||
| XMake build [target] | 构建目标,不指定target则构建所有目标 |
|
||||
| XMake run [target] | 运行目标,不指定target会自动寻找可运行的目标运行 |
|
||||
| XMake [...] | 使用...参数运行xmake命令,输出会投递到quickfix窗口 |
|
||||
| XMakeLoad | 手动加载xmake.lua里的配置 |
|
||||
| XMakeGen | 根据当前的配置生成xmake.lua文件(实验性质) |
|
56
bundle/xmake.vim/UltiSnips/lua.snippets
vendored
Normal file
56
bundle/xmake.vim/UltiSnips/lua.snippets
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
snippet xmtmp "A template for xmake" b
|
||||
set_project '${1:project_name}'
|
||||
|
||||
if is_mode 'debug' then
|
||||
set_symbols("debug")
|
||||
set_optimize("none")
|
||||
end
|
||||
if is_mode 'release' then
|
||||
set_symbols("hidden")
|
||||
set_optimize("fastest")
|
||||
set_strip("all")
|
||||
end
|
||||
|
||||
target '${2:target_name}'
|
||||
set_kind '${3:target_kind}'
|
||||
endsnippet
|
||||
|
||||
snippet xmproj "set_project ..."
|
||||
set_project '${1}'
|
||||
endsnippet
|
||||
|
||||
snippet xmtarget "target ..."
|
||||
target '${1:name}'
|
||||
set_kind '${2:binary|shared|static}'
|
||||
add_files '${3:*.cpp}'
|
||||
endsnippet
|
||||
|
||||
snippet xmincdirs "add_includedirs"
|
||||
add_includedirs '${1}'
|
||||
endsnippet
|
||||
|
||||
snippet xmfiles "add_files"
|
||||
add_files '${1}'
|
||||
endsnippet
|
||||
|
||||
snippet xmpackage "on_package ..." b
|
||||
on_package(function(target)
|
||||
os.cp('${1:source-file}', '${2:dist-file}')${0}
|
||||
end)
|
||||
endsnippet
|
||||
|
||||
snippet xmisdbg "if is_mode 'debug' then ..."
|
||||
if is_mode 'debug' then
|
||||
set_symbols("debug")
|
||||
set_optimize("none")
|
||||
end
|
||||
endsnippet
|
||||
|
||||
snippet xmisrls "if is_mode 'release' then ..."
|
||||
if is_mode 'release' then
|
||||
set_symbols("hidden")
|
||||
set_optimize("fastest")
|
||||
set_strip("all")
|
||||
end
|
||||
endsnippet
|
6
bundle/xmake.vim/addon-info.json
vendored
Normal file
6
bundle/xmake.vim/addon-info.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "xmake",
|
||||
"description": "xmake support in vim",
|
||||
"author": "Wang Shidong"
|
||||
}
|
||||
|
152
bundle/xmake.vim/autoload/spy.lua
vendored
Normal file
152
bundle/xmake.vim/autoload/spy.lua
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
import 'core.project.project'
|
||||
import 'core.project.config'
|
||||
import 'core.base.global'
|
||||
|
||||
local help_content = [==[
|
||||
xmake lua spy.lua [OPTION] ACTION
|
||||
|
||||
OPTION:
|
||||
-o FILE output the content to FILE
|
||||
|
||||
ACTION:
|
||||
config get a config
|
||||
global get a global config
|
||||
getenv ... get some ENVIRONMENTs
|
||||
project get all project's configuration
|
||||
]==]
|
||||
|
||||
-- table of action's procedures(functions)
|
||||
local actions = {}
|
||||
local outfile = nil
|
||||
|
||||
-- main
|
||||
function main(...)
|
||||
local args = {...}
|
||||
local action = args[1]
|
||||
if action == '-o' then
|
||||
outfile = args[2]
|
||||
action = args[3]
|
||||
args = table.slice(args, 3)
|
||||
end
|
||||
if action then
|
||||
local func = actions[action]
|
||||
if func then func(args) end
|
||||
else
|
||||
print(help_content)
|
||||
end
|
||||
end
|
||||
-- convert the value 't' to JSON string, in a line
|
||||
local function tojson(t)
|
||||
if type(t) == 'table' then
|
||||
local list = {}
|
||||
if t[1] then
|
||||
for i = 1, #t do
|
||||
list[i] = tojson(t[i])
|
||||
end
|
||||
return table.concat({'[', table.concat(list, ','), ']'})
|
||||
else
|
||||
for k, v in pairs(t) do
|
||||
table.insert(list, tojson(k) .. ':' .. tojson(v))
|
||||
end
|
||||
return table.concat({'{', table.concat(list, ','), '}'})
|
||||
end
|
||||
end
|
||||
local tt = type(t)
|
||||
if tt == 'string' then
|
||||
-- t = t:gsub('[\\\n\r\t"]', {
|
||||
-- ['\\'] = '\\\\', ['\n'] = '\\n',
|
||||
-- ['\t'] = '\\t', ['"'] = '\\"', ['\r'] = '\\r'
|
||||
-- })
|
||||
-- return '"' .. t .. '"'
|
||||
return string.format('%q', t)
|
||||
elseif tt == 'nil' then
|
||||
return 'null'
|
||||
else -- number or boolean
|
||||
return tostring(t)
|
||||
end
|
||||
end
|
||||
|
||||
function output(t)
|
||||
local t = tojson(t)
|
||||
if outfile then
|
||||
local file = io.open(outfile, 'w')
|
||||
if not file then
|
||||
print('can not open file to write:', outfile)
|
||||
return
|
||||
end
|
||||
file:write(t)
|
||||
file:close()
|
||||
else
|
||||
print(t)
|
||||
end
|
||||
end
|
||||
-- Action: config ----- get the current configuration
|
||||
actions.config = function(args)
|
||||
config.load()
|
||||
local list = {}
|
||||
for i = 2,#args do
|
||||
list[i-1] = config.get(args[i]) or ''
|
||||
end
|
||||
output(list)
|
||||
end
|
||||
-- Action: global ----- get the global configuration
|
||||
actions.global = function(args)
|
||||
global.load()
|
||||
local list = {}
|
||||
for i = 2,#args do
|
||||
list[i-1] = global.get(args[i]) or ''
|
||||
end
|
||||
output(list)
|
||||
end
|
||||
-- Action: getenv ------ get environment variables inside xmake
|
||||
actions.getenv = function(args)
|
||||
local list = {}
|
||||
for i = 2,#args do
|
||||
list[i-1] = os.getenv(args[i]) or ''
|
||||
end
|
||||
output(list)
|
||||
end
|
||||
actions.incdirs = function(args)
|
||||
config.load()
|
||||
for name, target in pairs(project.targets()) do
|
||||
print(target:get('includedirs'))
|
||||
end
|
||||
print(os.getenv('INCLUDE'))
|
||||
end
|
||||
-- Action: project ----- get the project's configuration
|
||||
actions.project = function(args)
|
||||
config.load()
|
||||
-- os.cd(project.directory())
|
||||
-- project's configuration
|
||||
local xconfig = {
|
||||
config = {
|
||||
arch = config:arch(),
|
||||
plat = config:plat(),
|
||||
mode = config:mode(),
|
||||
cc = config.get('cc'),
|
||||
cxx = config.get('cxx')
|
||||
},
|
||||
-- project's name
|
||||
name = project.name() or '<unamed>',
|
||||
-- project's version
|
||||
version = project.version(),
|
||||
-- project's targets
|
||||
targets = {}
|
||||
}
|
||||
-- read the configuration of all targets
|
||||
for tname, target in pairs(project.targets()) do
|
||||
local tcfg = {}
|
||||
try { function ()
|
||||
tcfg.name = target:name()
|
||||
tcfg.targetkind = target:targetkind() or ''
|
||||
tcfg.sourcefiles = target:sourcefiles() or {}
|
||||
tcfg.headerfiles = target:headerfiles() or {}
|
||||
tcfg.targetfile = target:targetfile() or '' end,
|
||||
catch { function(err)
|
||||
print(err)
|
||||
end}}
|
||||
xconfig.targets[tname] = tcfg
|
||||
end
|
||||
-- output
|
||||
output(xconfig)
|
||||
end
|
244
bundle/xmake.vim/autoload/xmake.vim
vendored
Normal file
244
bundle/xmake.vim/autoload/xmake.vim
vendored
Normal file
@ -0,0 +1,244 @@
|
||||
"=============================================================================
|
||||
" xmake.vim --- xmake support for spacevim
|
||||
" Copyright (c) 2016-2023 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" Original Author: luzhlon
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
" This file is based on:
|
||||
" https://github.com/luzhlon/xmake.vim/tree/5b20e97f5d0b063a97be23451c730d0278eef927
|
||||
|
||||
""
|
||||
" @section Introduction, intro
|
||||
" @library
|
||||
" xmake.vim is a plugin for using xmake in vim and neovim.
|
||||
" This plugin requires SpaceVim API and |job| support.
|
||||
|
||||
" load the spacevim APIs:
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:NOTI = SpaceVim#api#import('notify')
|
||||
|
||||
let s:job = 0 " subprocess of xmake
|
||||
let s:xmake_need_to_run = 0 " run this command after building successfully
|
||||
let s:target = '' " target to build, build ALL if empty
|
||||
let s:cb_cexpr = {j,d,s->vim#cadde(join(d, "\n"))}
|
||||
|
||||
|
||||
function! s:xmake_stdout(id, data, event) abort
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:xmake_stderr(id, data, event) abort
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:xmake_exit(id, data, event) abort
|
||||
if a:data
|
||||
" copen
|
||||
" if build failed, we need to display the error message
|
||||
call s:NOTI.notify('build failed', 'Error')
|
||||
call s:NOTI.notify('xmake returned ' . a:data, 'Error')
|
||||
else
|
||||
call s:NOTI.notify('build success' . s:target, 'MoreMsg')
|
||||
if s:xmake_need_to_run
|
||||
let t = get(get(g:xmproj['targets'], s:target, {}), 'targetfile')
|
||||
if empty(t)
|
||||
call s:NOTI.notify('Target not exists:' . s:target, 'Error')
|
||||
else
|
||||
call SpaceVim#plugins#runner#open(empty(s:target) ? 'xmake run': t)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
" Get the bufnr about a target's sourcefiles and headerfiles
|
||||
func! s:targetbufs(target)
|
||||
let nrs = {}
|
||||
for i in a:target['sourcefiles'] + a:target['headerfiles']
|
||||
let n = bufnr(i)
|
||||
if n > 0 && getbufvar(n, '&mod')
|
||||
let nrs[n] = 1
|
||||
endif
|
||||
endfor
|
||||
return nrs
|
||||
endfunction
|
||||
|
||||
" Get the bufnrs to save
|
||||
fun! s:buf2save()
|
||||
if empty(s:target)
|
||||
" Save all target's file
|
||||
let nrs = {}
|
||||
for tf in values(g:xmproj['targets'])
|
||||
call extend(nrs, s:targetbufs(tf))
|
||||
endfor
|
||||
else
|
||||
" Save s:target's file
|
||||
let nrs = s:targetbufs(g:xmproj['targets'][s:target])
|
||||
endif
|
||||
return keys(nrs)
|
||||
endfunction
|
||||
" Save the file before building
|
||||
fun! s:savefiles()
|
||||
let n = bufnr('%') " save current bufnr
|
||||
let bufnrs = s:buf2save()
|
||||
let xnr = bufnr('xmake.lua')
|
||||
if xnr > 0
|
||||
call add(bufnrs, xnr)
|
||||
endif
|
||||
for nr in bufnrs " traverse project's files, and save them
|
||||
sil! exe nr . 'bufdo!' 'up'
|
||||
endfor
|
||||
" switch to original buffer
|
||||
exe 'b!' n
|
||||
endfunction
|
||||
|
||||
" If exists a xmake subprocess
|
||||
fun! s:isRunning()
|
||||
if !empty(s:job) && s:JOB.status(s:job) == 'run'
|
||||
call s:NOTI.notify('a xmake task is running')
|
||||
return 1
|
||||
endif
|
||||
endfunction
|
||||
" If loaded the xmake's configuration
|
||||
fun! s:notLoaded()
|
||||
if exists('g:xmproj')
|
||||
return 0
|
||||
endif
|
||||
call s:NOTI.notify('No xmake-project loaded')
|
||||
return 1
|
||||
endfunction
|
||||
" Building by xmake
|
||||
fun! xmake#buildrun(...)
|
||||
if s:notLoaded() | return | endif
|
||||
if s:isRunning() | return | endif
|
||||
" call s:savefiles() " save files about the target to build
|
||||
wall
|
||||
let s:xmake_need_to_run = a:0 && a:1
|
||||
let color = $COLORTERM
|
||||
cexpr ''
|
||||
let cmd = empty(s:target) ? 'xmake': ['xmake', 'build', s:target]
|
||||
if has_key(g:xmproj, 'compiler')
|
||||
exe 'compiler' g:xmproj['compiler']
|
||||
endif
|
||||
let s:job = s:JOB.start(cmd, {
|
||||
\ 'on_stdout': function('s:xmake_stdout'),
|
||||
\ 'on_stderr': function('s:xmake_stderr'),
|
||||
\ 'on_exit': function('s:xmake_exit'),
|
||||
\ 'env' : {'COLORTERM' : 'nocolor'}
|
||||
\ })
|
||||
endfunction
|
||||
" Interpret XMake command
|
||||
fun! xmake#xmake(...)
|
||||
let argv = filter(copy(a:000), {i,v->v!=''})
|
||||
let argc = len(argv)
|
||||
if !argc " building all targets without running
|
||||
let s:target = ''
|
||||
call xmake#buildrun()
|
||||
elseif argv[0] == 'run' || argv[0] == 'r' " building && running
|
||||
if argc > 1 | let s:target = argv[1] | endif
|
||||
call xmake#buildrun(1)
|
||||
elseif argv[0] == 'build' " building specific target
|
||||
if argc > 1 | let s:target = argv[1] | endif
|
||||
call xmake#buildrun()
|
||||
else " else xmake's commands
|
||||
if s:isRunning() | return | endif
|
||||
let s:job = s:JOB.start(['xmake'] + argv, {
|
||||
\ 'on_stdout': function('s:xmake_stdout'),
|
||||
\ 'on_stderr': function('s:xmake_stderr'),
|
||||
\ 'on_exit': function('s:xmake_exit'),
|
||||
\ 'env' : {'COLORTERM' : 'nocolor'}
|
||||
\ })
|
||||
endif
|
||||
endfunction
|
||||
|
||||
fun! s:onload(...)
|
||||
" Check the fields
|
||||
for t in values(g:xmproj['targets'])
|
||||
if empty(t.headerfiles)
|
||||
let t.headerfiles = []
|
||||
endif
|
||||
if empty(t.sourcefiles)
|
||||
let t.sourcefiles = []
|
||||
endif
|
||||
endfor
|
||||
" Support SpaceVim's tabmanager
|
||||
call s:NOTI.notify('XMake-Project loaded successfully', 'MoreMsg')
|
||||
let config = g:xmproj.config
|
||||
let t:_spacevim_tab_name = join(filter([g:xmproj['name'], get(config, 'mode', ''), get(config, 'arch', '')], '!empty(v:val)'), ' - ')
|
||||
call xmake#log#info('change the project name to:' . t:_spacevim_tab_name)
|
||||
" Find compiler
|
||||
let cc = get(g:xmproj.config, 'cc', '')
|
||||
let cxx = get(g:xmproj.config, 'cxx', '')
|
||||
let compiler = ''
|
||||
if !empty(cxx)
|
||||
let compiler = cxx
|
||||
elseif !empty(cc)
|
||||
let compiler = cc
|
||||
endif
|
||||
if !empty(compiler)
|
||||
let t = {'cl.exe': 'msvc', 'gcc': 'gcc'}
|
||||
let g:xmproj.compiler = t[compiler]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
augroup xmake_autoload
|
||||
autocmd!
|
||||
au User XMakeLoaded call <SID>onload()
|
||||
augroup END
|
||||
|
||||
|
||||
let s:path = expand('<sfile>:p:h')
|
||||
let s:xmake_load_stdout_cache = []
|
||||
let s:xmake_load_tempname = ''
|
||||
function! s:xmake_load_stdout(id, data, event) abort
|
||||
call add(s:xmake_load_stdout_cache, a:data)
|
||||
endfunction
|
||||
|
||||
function! s:xmake_load_stderr(id, data, event) abort
|
||||
for line in a:data
|
||||
let s:NOTI.notify_max_width = max([strwidth(line) + 5, s:NOTI.notify_max_width])
|
||||
call s:NOTI.notify(line, 'WarningMsg')
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:xmake_load_exit(id, data, event) abort
|
||||
call xmake#log#info('LoadXCfg entered.')
|
||||
if a:data
|
||||
call s:NOTI.notify('XMake-Project loaded unsuccessfully.')
|
||||
call s:NOTI.notify('xmake returned ' . a:data)
|
||||
else
|
||||
let l = ''
|
||||
try
|
||||
let l = readfile(s:xmake_load_tempname)
|
||||
let g:xmproj = json_decode(l[0])
|
||||
do User XMakeLoaded
|
||||
catch
|
||||
call xmake#log#debug('xmake_load_tempname is: ' . s:xmake_load_tempname)
|
||||
call xmake#log#debug('failed to paser s:xmake_load_tempname')
|
||||
call xmake#log#debug(' exception: ' . v:exception)
|
||||
call xmake#log#debug(' throwpoint: ' . v:throwpoint)
|
||||
endtry
|
||||
endif
|
||||
endfunction
|
||||
|
||||
fun! xmake#load()
|
||||
let s:xmake_load_stdout_cache = []
|
||||
let s:xmake_load_tempname = tempname()
|
||||
let cmdline = ['xmake', 'lua', s:path . '/spy.lua', '-o', s:xmake_load_tempname, 'project']
|
||||
call xmake#log#info('cmdline is:' . string(cmdline))
|
||||
let jobid = s:JOB.start(cmdline, {
|
||||
\ 'on_stdout' : function('s:xmake_load_stdout'),
|
||||
\ 'on_stderr' : function('s:xmake_load_stderr'),
|
||||
\ 'on_exit' : function('s:xmake_load_exit')
|
||||
\ }
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
|
||||
function! xmake#on_project_changed() abort
|
||||
if filereadable('xmake.lua')
|
||||
call xmake#load()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim:set et sw=2 cc=80:
|
18
bundle/xmake.vim/autoload/xmake/log.vim
vendored
Normal file
18
bundle/xmake.vim/autoload/xmake/log.vim
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"=============================================================================
|
||||
" log.vim --- xmake logger
|
||||
" Copyright (c) 2016-2023 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
let s:LOGGER = SpaceVim#logger#derive('xmake')
|
||||
|
||||
|
||||
function! xmake#log#info(msg) abort
|
||||
call s:LOGGER.info(a:msg)
|
||||
endfunction
|
||||
|
||||
|
||||
function! xmake#log#debug(msg) abort
|
||||
call s:LOGGER.debug(a:msg)
|
||||
endfunction
|
22
bundle/xmake.vim/doc/xmake.txt
vendored
Normal file
22
bundle/xmake.vim/doc/xmake.txt
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
*xmake.txt* xmake support in vim
|
||||
Wang Shidong *xmake*
|
||||
|
||||
==============================================================================
|
||||
CONTENTS *xmake-contents*
|
||||
1. Introduction................................................|xmake-intro|
|
||||
2. Commands.................................................|xmake-commands|
|
||||
|
||||
==============================================================================
|
||||
INTRODUCTION *xmake-intro*
|
||||
|
||||
xmake.vim is a plugin for using xmake in vim and neovim. This plugin requires
|
||||
SpaceVim API and |job| support.
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *xmake-commands*
|
||||
|
||||
:XMake *:XMake*
|
||||
Run `xmake` command based on provided arguments.
|
||||
|
||||
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
143
bundle/xmake.vim/plugin/xmake.vim
vendored
Normal file
143
bundle/xmake.vim/plugin/xmake.vim
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
"=============================================================================
|
||||
" xmake.vim --- xmake support for spacevim
|
||||
" Copyright (c) 2016-2023 Wang Shidong & Contributors
|
||||
" Author: Wang Shidong < wsdjeg@outlook.com >
|
||||
" Original Author: luzhlon
|
||||
" URL: https://spacevim.org
|
||||
" License: GPLv3
|
||||
"=============================================================================
|
||||
" This file is based on:
|
||||
" https://github.com/luzhlon/xmake.vim/tree/5b20e97f5d0b063a97be23451c730d0278eef927
|
||||
|
||||
if exists('s:xmake_loaded')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:xmake_loaded = 1
|
||||
|
||||
" Arguments of 'xmake'
|
||||
let s:xmake_args = [ 'run',
|
||||
\ 'config', 'global',
|
||||
\ 'create', 'package',
|
||||
\ 'install', 'uninstall',
|
||||
\ 'build', 'clean',
|
||||
\ 'project',
|
||||
\ 'doxygen',
|
||||
\ 'app2ipa']
|
||||
" Arguments of 'xmake create'
|
||||
let s:create_args = [
|
||||
\ '--name=', '-n',
|
||||
\ '--language=', '-l',
|
||||
\ '--template=', '-t']
|
||||
" Arguments of 'xmake config'
|
||||
let s:config_args = [
|
||||
\ '--verbose=', '-v',
|
||||
\ '--plat=', '-p',
|
||||
\ '--arch=', '-a',
|
||||
\ '--mode=', '-m',
|
||||
\ '--kind=', '-k',
|
||||
\ '--buildir=', '-o']
|
||||
let s:plat_args = ['android', 'iphoneos', 'linux', 'macos', 'mingw', 'watchos', 'windows']
|
||||
let s:language_args = ['c', 'c++', 'dlang', 'objc', 'objc++', 'rust', 'swift']
|
||||
let s:arch_args = ['x86', 'x64', 'x86_64', 'i386', 'armv7', 'armv7s', 'arm64', 'armv7-a', 'armv7k', 'armv5te', 'armv6', 'armv8-a', 'arm64-v8a']
|
||||
" Get the last operation
|
||||
fun! s:lastarg(args)
|
||||
let i = -1
|
||||
try | while 1
|
||||
let a = a:args[i]
|
||||
if a =~ '^-' | return a | endif
|
||||
let i -= 1
|
||||
endw | endt
|
||||
return ''
|
||||
endf
|
||||
" Function to complete the xmake args
|
||||
fun! s:xmake_complete(a, c, p)
|
||||
let args = split(strpart(a:c, 0, a:p), '\s\+')
|
||||
let op = len(args) > 1 ? args[1] : ''
|
||||
let larg = args[-1][0] == '-' ? args[-1] : len(args) > 1 ? args[-2] : ''
|
||||
let rets = []
|
||||
if op == 'run' || op == 'build'
|
||||
let rets = keys(g:xmproj['targets'])
|
||||
elseif op == 'create'
|
||||
if larg == '--language=' || larg == '-l'
|
||||
let rets = s:language_args
|
||||
else
|
||||
let rets = s:create_args
|
||||
endif
|
||||
elseif op == 'config'
|
||||
if larg == '--plat=' || larg == '-p'
|
||||
let rets = s:plat_args
|
||||
elseif larg == '--kind=' || larg == '-k'
|
||||
let rets = ['static', 'shared', 'binary']
|
||||
elseif larg == '--mode=' || larg == '-m'
|
||||
let rets = ['debug', 'release']
|
||||
elseif larg == '--arch' || larg == '-a'
|
||||
let rets = s:arch_args
|
||||
else
|
||||
let rets = s:config_args
|
||||
endif
|
||||
elseif op == 'project'
|
||||
if larg == '-k'
|
||||
let rets = ['vs2013', 'vs2015', 'vs2017', 'makefile']
|
||||
elseif larg == '--mode=' || larg == '-m'
|
||||
let rets = ['debug', 'release']
|
||||
else
|
||||
let rets = ['-k', '-m']
|
||||
endif
|
||||
else
|
||||
let rets = s:xmake_args
|
||||
endif
|
||||
return s:wildfilter(rets, a:a)
|
||||
endf
|
||||
|
||||
let s:patten = ''
|
||||
function! s:compare(a, b) abort
|
||||
return match(a:a, s:patten) - match(a:b, s:patten)
|
||||
endfunction
|
||||
|
||||
function! s:wildfilter(rets, patten) abort
|
||||
let ret = filter(copy(a:rets), 'v:val =~ a:patten')
|
||||
let s:patten = a:patten
|
||||
call sort(ret, function('s:compare'))
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
""
|
||||
" Run `xmake` command based on provided arguments.
|
||||
command! -complete=customlist,<SID>xmake_complete
|
||||
\ -nargs=* XMake call xmake#xmake(<f-args>)
|
||||
|
||||
let s:path = expand('<sfile>:p:h')
|
||||
|
||||
fun! s:xmgen()
|
||||
exe 'py3file' s:path . '/xmgen.py'
|
||||
endf
|
||||
|
||||
com! XMakeLoad call xmake#load()
|
||||
com! XMakeGen call <SID>xmgen()
|
||||
|
||||
let arg = argv(0)
|
||||
if fnamemodify(arg, ':t') == 'xmake.lua'
|
||||
" exe 'bw' arg
|
||||
if filereadable(arg)
|
||||
au VimEnter * XMakeLoad
|
||||
endif
|
||||
endif
|
||||
|
||||
fun! s:on_read()
|
||||
if !exists('b:deoplete_sources')
|
||||
if exists('g:deoplete#sources')
|
||||
let b:deoplete_sources =
|
||||
\ get(g:deoplete#sources, '_', []) +
|
||||
\ get(g:deoplete#sources, 'lua', [])
|
||||
else
|
||||
let b:deoplete_sources = []
|
||||
endif
|
||||
endif
|
||||
call add(b:deoplete_sources, 'xmake')
|
||||
endf
|
||||
|
||||
au BufWritePost xmake.lua XMakeLoad
|
||||
au BufRead,BufNew xmake.lua call <sid>on_read()
|
||||
|
||||
call SpaceVim#plugins#projectmanager#reg_callback(function('xmake#on_project_changed'))
|
37
bundle/xmake.vim/plugin/xmgen.py
vendored
Normal file
37
bundle/xmake.vim/plugin/xmgen.py
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
# Filename: xmgen.py
|
||||
# Author: luzhlon
|
||||
# Description: Generate xmake.lua
|
||||
import vim
|
||||
|
||||
try:
|
||||
_cfg = vim.eval('g:xcfg')
|
||||
_f = open('xmake.lua', 'w')
|
||||
_f.writelines([
|
||||
'''if is_mode("release") then
|
||||
set_symbols("hidden")
|
||||
set_optimize("fastest")
|
||||
set_strip("all")
|
||||
elseif is_mode("debug") then
|
||||
set_symbols("debug")
|
||||
set_optimize("none")
|
||||
end''', '\n\n'])
|
||||
# 写入工程名称
|
||||
_f.writelines(["set_project '%s'" % _cfg['project'], '\n\n'])
|
||||
Filelist = lambda l: ','.join(list(map(lambda v:"'%s'" % v, l)))
|
||||
# 写入目标配置
|
||||
for (name, target) in _cfg['targets'].items():
|
||||
t = ["target '%s'" % name, '\n',
|
||||
"set_kind '%s'" % target['targetkind'], '\n']
|
||||
if 'headerfiles' in target:
|
||||
t.append("add_headers(%s)" % Filelist(target['headerfiles']))
|
||||
t.append('\n')
|
||||
if 'sourcefiles' in target:
|
||||
t.append("add_files(%s)" % Filelist(target['sourcefiles']))
|
||||
t.append('\n')
|
||||
t.append('\n')
|
||||
_f.writelines(t)
|
||||
_f.close()
|
||||
except OSError:
|
||||
print('open xmake.lua failure')
|
||||
except vim.error as e:
|
||||
print(e)
|
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_defines
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_defines
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_deps
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_deps
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_files
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_files
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_headers
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_headers
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_includedirs
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_includedirs
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_linkdirs
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_linkdirs
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_links
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_links
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_subdirs
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/add_subdirs
vendored
Normal file
6
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/is_os
vendored
Normal file
6
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/is_os
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
Is the current compilation target system:
|
||||
* windows
|
||||
* linux
|
||||
* android
|
||||
* macosx
|
||||
* ios
|
8
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/is_plat
vendored
Normal file
8
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/is_plat
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
Is the current compilation platform:
|
||||
|
||||
* windows
|
||||
* linux
|
||||
* macosx
|
||||
* android
|
||||
* iphoneos
|
||||
* watchos
|
1
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_basename
vendored
Normal file
1
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_basename
vendored
Normal file
@ -0,0 +1 @@
|
||||
Set the name of target file to generate.
|
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_headerdir
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_headerdir
vendored
Normal file
5
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_kind
vendored
Normal file
5
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_kind
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
set target's type:
|
||||
|
||||
* binary
|
||||
* static - static library
|
||||
* shared - shared library (dynamic library)
|
5
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_languages
vendored
Normal file
5
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_languages
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
set target's language:
|
||||
|
||||
ansi c89 gnu89 c99 gnu99 cxx98
|
||||
gnuxx98 cxx11 gnuxx11 cxx14
|
||||
gnuxx14 cxx1z gnuxx1z cxx17 gnuxx17
|
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_objectdir
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_objectdir
vendored
Normal file
8
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_optimize
vendored
Normal file
8
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_optimize
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
set the level of optimize:
|
||||
|
||||
* none 禁用优化
|
||||
* fast 快速优化
|
||||
* faster 更快的优化
|
||||
* fastest 最快运行速度的优化
|
||||
* smallest 最小化代码优化
|
||||
* aggressive 过度优化
|
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_project
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_project
vendored
Normal file
4
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_strip
vendored
Normal file
4
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_strip
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
set the mode of strip:
|
||||
|
||||
* debug - 链接的时候,strip掉调试符号
|
||||
* all - 链接的时候,strip掉所有符号,包括调试符号
|
4
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_symbols
vendored
Normal file
4
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_symbols
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
set target's symbols mode:
|
||||
|
||||
* debug - 添加调试符号
|
||||
* hidden - 设置符号不可见
|
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_targetdir
vendored
Normal file
0
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_targetdir
vendored
Normal file
7
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_warnings
vendored
Normal file
7
bundle/xmake.vim/rplugin/python3/deoplete/sources/docs/set_warnings
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
set level of warning:
|
||||
|
||||
* none 禁用所有警告
|
||||
* less 启用较少的警告
|
||||
* more 启用较多的警告
|
||||
* all 启用所有警告
|
||||
* error 将所有警告作为编译错误
|
59
bundle/xmake.vim/rplugin/python3/deoplete/sources/xmake.py
vendored
Normal file
59
bundle/xmake.vim/rplugin/python3/deoplete/sources/xmake.py
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
from .base import Base
|
||||
import re, os
|
||||
import glob
|
||||
|
||||
PATH, _ = os.path.split(__file__)
|
||||
|
||||
apis = []
|
||||
for docpath in glob.glob(PATH + '/docs/*'):
|
||||
path, name = os.path.split(docpath)
|
||||
f = open(docpath, 'rb')
|
||||
apis.append({'word': name, 'info': f.read().decode('utf-8')})
|
||||
f.close()
|
||||
|
||||
os.aaa = apis
|
||||
|
||||
_ = {
|
||||
'os': 'Current OS of compiling-system',
|
||||
'host': 'Current OS of localhost',
|
||||
'tmpdir': 'Temporary directory',
|
||||
'curdir': 'Current directory',
|
||||
'buildir': 'Build directory',
|
||||
'scriptdir': 'Script dictionary',
|
||||
'globaldir': 'Global-config directory',
|
||||
'configdir': 'Local-config directory',
|
||||
'programdir': 'Program directory',
|
||||
'projectdir': 'Project directory',
|
||||
'shell': 'Extern shell',
|
||||
'env': 'Get environment variable',
|
||||
'reg': 'Get windows register value'
|
||||
}
|
||||
builtin_vars = [{'word': k, 'menu': v} for k, v in _.items()]
|
||||
|
||||
|
||||
class Source(Base):
|
||||
def __init__(self, vim):
|
||||
Base.__init__(self, vim)
|
||||
|
||||
self.vim = vim
|
||||
self.name = 'xmake'
|
||||
self.mark = '[xmake]'
|
||||
self.filetypes = ['lua']
|
||||
self.input_pattern = r'\w+$|\$\($'
|
||||
|
||||
def get_complete_position(self, context):
|
||||
input = context['input']
|
||||
word = re.search(r'\w+$', input)
|
||||
if word:
|
||||
return word.start()
|
||||
else:
|
||||
return len(input)
|
||||
|
||||
def gather_candidates(self, context):
|
||||
global apis, builtin_vars
|
||||
|
||||
if re.search('\$\(\w*$', context['input'][:context['complete_position']]):
|
||||
return builtin_vars
|
||||
else:
|
||||
return apis
|
@ -239,6 +239,7 @@ CONTENTS *SpaceVim-contents*
|
||||
142. treesitter.............................|SpaceVim-layers-treesitter|
|
||||
143. ui.............................................|SpaceVim-layers-ui|
|
||||
144. unite.......................................|SpaceVim-layers-unite|
|
||||
145. xmake.......................................|SpaceVim-layers-xmake|
|
||||
7. Usage....................................................|SpaceVim-usage|
|
||||
1. alternate file........................|SpaceVim-usage-alternate-file|
|
||||
2. buffers-and-files..................|SpaceVim-usage-buffers-and-files|
|
||||
@ -5762,6 +5763,16 @@ KEY BINDINGS
|
||||
<
|
||||
|
||||
|
||||
==============================================================================
|
||||
XMAKE *SpaceVim-layers-xmake*
|
||||
|
||||
The `xmake` layer provides basic function for xmake command. This layer is
|
||||
disabled by default, to use it:
|
||||
>
|
||||
[[layers]]
|
||||
name = 'xmake'
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
USAGE *SpaceVim-usage*
|
||||
|
||||
|
42
docs/cn/layers/xmake.md
Normal file
42
docs/cn/layers/xmake.md
Normal file
@ -0,0 +1,42 @@
|
||||
---
|
||||
title: "SpaceVim xmake 模块"
|
||||
description: "这一模块为 SpaceVim 提供了一些在 Vim 内操作 xmake 的功能。"
|
||||
lang: zh
|
||||
---
|
||||
|
||||
# [可用模块](../) >> xmake
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [模块简介](#模块简介)
|
||||
- [功能特性](#功能特性)
|
||||
- [启用模块](#启用模块)
|
||||
- [快捷键](#快捷键)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## 模块简介
|
||||
|
||||
该模块主要提供了一些在 Vim 内操作 xmake 的功能。
|
||||
|
||||
## 功能特性
|
||||
|
||||
- xmake 配置文件语法高亮
|
||||
- xmake 状态栏
|
||||
- 快速执行 xmake 命令
|
||||
|
||||
## 启用模块
|
||||
|
||||
可通过在配置文件内加入如下配置来启用该模块:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "xmake"
|
||||
```
|
||||
|
||||
## 快捷键
|
||||
|
||||
| 快捷键 | 功能描述 |
|
||||
| ----------- | --------------------------- |
|
||||
| `SPC m x b` | xmake build without running |
|
||||
| `SPC m x r` | xmake build and running |
|
30
docs/layers/xmake.md
Normal file
30
docs/layers/xmake.md
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
title: "SpaceVim xmake layer"
|
||||
description: "xmake layer provides basic xmake client for SpaceVim."
|
||||
---
|
||||
|
||||
# [Available Layers](../) >> xmake
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Description](#description)
|
||||
- [Key Mappings](#key-mappings)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
## Description
|
||||
|
||||
The `xmake` layer provides basic function for xmake command.
|
||||
To use this configuration layer, add the following snippet to your custom configuration file.
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "xmake"
|
||||
```
|
||||
|
||||
## Key Mappings
|
||||
|
||||
| Key Bingding | Description |
|
||||
| ------------ | --------------------------- |
|
||||
| `SPC m x b` | xmake build without running |
|
||||
| `SPC m x r` | xmake build and running |
|
Loading…
x
Reference in New Issue
Block a user