aboutsummaryrefslogtreecommitdiff
path: root/.vim/autoload/neomake/jobinfo.vim
blob: 278a3f556c21f0c5ffa1c9a5ef82352952990b5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
let s:jobinfo_base = {
            \ 'cd_back_cmd': '',
            \ 'pending_output': [],
            \ }
function! s:jobinfo_base.get_pid() abort
    if has_key(self, 'vim_job')
        let info = job_info(self.vim_job)
        if info.status ==# 'run'
            return info.process
        endif
        return -1
    endif
    try
        return jobpid(self.nvim_job)
    catch /^Vim(return):E900:/
        return -1
    endtry
endfunction

function! s:jobinfo_base.as_string() abort
    let extra = []
    for k in ['canceled', 'finished']
        if get(self, k, 0)
            let extra += [k]
        endif
    endfor
    return printf('Job %d: %s%s', self.id, self.name,
                \ empty(extra) ? '' : ' ['.join(extra, ', ').']')
endfunction

function! s:jobinfo_base.cd_back() abort
    if !empty(self.cd_back_cmd)
        exe self.cd_back_cmd
        let self.cd_back_cmd = ''
    endif
endfunction

function! s:jobinfo_base.cd(...) abort
    if a:0
        if has_key(self, 'cd_from_setting')
            call neomake#log#debug(printf(
                        \ 'jobinfo.cd(): keeping cwd from setting: %s.',
                        \ string(self.cd_from_setting)), self)
            return ''
        endif
        let dir = a:1
    else
        let maker = self.maker
        let dir = neomake#utils#GetSetting('cwd', maker, '', self.ft, self.bufnr, 1)
        if !empty(dir)
            let self.cd_from_setting = dir
        endif
    endif

    if dir !=# ''
        if dir[0:1] ==# '%:'
            let dir = neomake#utils#fnamemodify(self.bufnr, dir[1:])
        else
            let dir = expand(dir, 1)
        endif
        let dir = fnamemodify(dir, ':p')
        " NOTE: need to keep trailing backslash with "/" and "X:\" on Windows.
        if dir !=# '/' && dir[-1:] ==# neomake#utils#Slash() && dir[-2] !=# ':'
            let dir = dir[:-2]
        endif
    else
        let dir = get(self, 'cwd', $HOME)
    endif

    let cur_wd = getcwd()
    if dir !=# cur_wd
        let [cd_error, cd_back_cmd] = neomake#utils#temp_cd(dir, cur_wd)
        if !empty(cd_error)
            call neomake#log#debug(printf('jobinfo.cd(): error when trying to change cwd to %s: %s.',
                        \ dir, cd_error))
            return cd_error
        endif
        let self.cwd = dir
        let self.cd_back_cmd = cd_back_cmd
    else
        let self.cwd = cur_wd
    endif
    return ''
endfunction

let g:neomake#jobinfo#base = s:jobinfo_base
" vim: ts=4 sw=4 et