Mercurial > vim-unreal
comparison autoload/unreal.vim @ 9:b5040cfea052
Tweak how configs and targets are parsed and handled
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 29 Aug 2023 13:06:44 -0700 |
parents | 5cd58b3fd93d |
children | 06af9916ba7c |
comparison
equal
deleted
inserted
replaced
8:5cd58b3fd93d | 9:b5040cfea052 |
---|---|
280 endfunction | 280 endfunction |
281 | 281 |
282 let s:extra_args_version = 1 | 282 let s:extra_args_version = 1 |
283 | 283 |
284 function! unreal#generate_vimcrosoft_extra_args(solution) abort | 284 function! unreal#generate_vimcrosoft_extra_args(solution) abort |
285 let l:argdir = | |
286 \fnamemodify(a:solution, ':p:h').s:dirsep.'.vimcrosoft' | |
285 let l:argfile = | 287 let l:argfile = |
286 \fnamemodify(a:solution, ':p:h').s:dirsep. | 288 \l:argdir.s:dirsep.fnamemodify(a:solution, ':t').'.flags' |
287 \'.vimcrosoft'.s:dirsep. | |
288 \fnamemodify(a:solution, ':t').'.flags' | |
289 | 289 |
290 let l:do_regen = 0 | 290 let l:do_regen = 0 |
291 let l:version_line = "# version ".string(s:extra_args_version) | 291 let l:version_line = "# version ".string(s:extra_args_version) |
292 try | 292 try |
293 call unreal#trace("Checking for extra clang args file: ".l:argfile) | 293 call unreal#trace("Checking for extra clang args file: ".l:argfile) |
302 catch | 302 catch |
303 call unreal#trace("Extra clang args file doesn't exist... regenerating") | 303 call unreal#trace("Extra clang args file doesn't exist... regenerating") |
304 let l:do_regen = 1 | 304 let l:do_regen = 1 |
305 endtry | 305 endtry |
306 if l:do_regen | 306 if l:do_regen |
307 if !isdirectory(l:argdir) | |
308 call mkdir(l:argdir) | |
309 endif | |
310 | |
307 let l:arglines = [ | 311 let l:arglines = [ |
308 \l:version_line, | 312 \l:version_line, |
309 \"-DUNREAL_CODE_ANALYZER" | 313 \"-DUNREAL_CODE_ANALYZER" |
310 \] | 314 \] |
311 call writefile(l:arglines, l:argfile) | 315 call writefile(l:arglines, l:argfile) |
315 " }}} | 319 " }}} |
316 | 320 |
317 " Configuration and Platform {{{ | 321 " Configuration and Platform {{{ |
318 | 322 |
319 let s:unreal_configs = [] | 323 let s:unreal_configs = [] |
324 let s:unreal_configs_map = {} | |
320 | 325 |
321 function! s:cache_unreal_configs() abort | 326 function! s:cache_unreal_configs() abort |
322 if len(s:unreal_configs) == 0 | 327 if len(s:unreal_configs) == 0 |
323 for l:state in g:unreal_config_states | 328 for l:state in g:unreal_config_states |
324 for l:target in g:unreal_config_targets | 329 for l:target in g:unreal_config_targets |
325 call add(s:unreal_configs, l:state.l:target) | 330 let l:key = l:state.l:target |
331 call add(s:unreal_configs, l:key) | |
332 let s:unreal_configs_map[l:key] = [l:state, l:target] | |
326 endfor | 333 endfor |
327 endfor | 334 endfor |
328 endif | 335 endif |
329 endfunction | 336 endfunction |
330 | 337 |
331 function! s:parse_config_state_and_target(config) abort | 338 function! s:parse_config_state_and_target(config) abort |
332 let l:alen = len(a:config) | 339 let l:config = trim(a:config) |
333 | 340 |
334 let l:config_target = "" | 341 for l:key in keys(s:unreal_configs_map) |
335 for l:target in g:unreal_config_targets | 342 if l:config == l:key |
336 let l:tlen = len(l:target) | 343 let [l:config_state, l:config_target] = s:unreal_configs_map[l:key] |
337 if l:alen > l:tlen && a:config[l:alen - l:tlen : ] == l:target | |
338 let l:config_target = l:target | |
339 break | 344 break |
340 endif | 345 endif |
341 endfor | 346 endfor |
342 | 347 |
343 let l:config_state = a:config[0 : l:alen - t:tlen - 1] | |
344 | |
345 if index(g:unreal_config_states, l:config_state) >= 0 || | 348 if index(g:unreal_config_states, l:config_state) >= 0 || |
346 \index(g:unreal_config_targets, l:config_target) >= 0 | 349 \index(g:unreal_config_targets, l:config_target) >= 0 |
347 return [l:config_state, l:config_target] | 350 return [l:config_state, l:config_target] |
348 else | 351 else |
349 call unreal#throw("Invalid config state or target: ".l:config_state.l:config_target) | 352 call unreal#throw("Invalid config state or target: ".l:config_state.l:config_target) |
355 let g:unreal_config_state = l:config_state | 358 let g:unreal_config_state = l:config_state |
356 let g:unreal_config_target = l:config_target | 359 let g:unreal_config_target = l:config_target |
357 endfunction | 360 endfunction |
358 | 361 |
359 function! unreal#set_platform(platform) abort | 362 function! unreal#set_platform(platform) abort |
360 if index(g:unreal_platforms, a:platform) < 0 | 363 if index(g:unreal_platforms, trim(a:platform)) < 0 |
361 call unreal#throw("Invalid Unreal platform: ".a:platform) | 364 call unreal#throw("Invalid Unreal platform: ".a:platform) |
362 endif | 365 endif |
363 let g:unreal_project_platform = a:platform | 366 let g:unreal_project_platform = a:platform |
364 endfunction | 367 endfunction |
365 | 368 |