1*130cbfc3SBram Moolenaar" Vim compiler file
2*130cbfc3SBram Moolenaar" Compiler:	powershell
3*130cbfc3SBram Moolenaar" URL: https://github.com/PProvost/vim-ps1
4*130cbfc3SBram Moolenaar" Last Change: 2020 Mar 30
5*130cbfc3SBram Moolenaar
6*130cbfc3SBram Moolenaarif exists("current_compiler")
7*130cbfc3SBram Moolenaar  finish
8*130cbfc3SBram Moolenaarendif
9*130cbfc3SBram Moolenaarlet current_compiler = "powershell"
10*130cbfc3SBram Moolenaar
11*130cbfc3SBram Moolenaarif exists(":CompilerSet") != 2		" older Vim always used :setlocal
12*130cbfc3SBram Moolenaar  command -nargs=* CompilerSet setlocal <args>
13*130cbfc3SBram Moolenaarendif
14*130cbfc3SBram Moolenaar
15*130cbfc3SBram Moolenaarlet s:cpo_save = &cpo
16*130cbfc3SBram Moolenaarset cpo-=C
17*130cbfc3SBram Moolenaar
18*130cbfc3SBram Moolenaarif !exists("g:ps1_makeprg_cmd")
19*130cbfc3SBram Moolenaar  if executable('pwsh')
20*130cbfc3SBram Moolenaar    " pwsh is the future
21*130cbfc3SBram Moolenaar    let g:ps1_makeprg_cmd = 'pwsh'
22*130cbfc3SBram Moolenaar  elseif executable('pwsh.exe')
23*130cbfc3SBram Moolenaar    let g:ps1_makeprg_cmd = 'pwsh.exe'
24*130cbfc3SBram Moolenaar  elseif executable('powershell.exe')
25*130cbfc3SBram Moolenaar    let g:ps1_makeprg_cmd = 'powershell.exe'
26*130cbfc3SBram Moolenaar  else
27*130cbfc3SBram Moolenaar    let g:ps1_makeprg_cmd = ''
28*130cbfc3SBram Moolenaar  endif
29*130cbfc3SBram Moolenaarendif
30*130cbfc3SBram Moolenaar
31*130cbfc3SBram Moolenaarif !executable(g:ps1_makeprg_cmd)
32*130cbfc3SBram Moolenaar  echoerr "To use the powershell compiler, please set g:ps1_makeprg_cmd to the powershell executable!"
33*130cbfc3SBram Moolenaarendif
34*130cbfc3SBram Moolenaar
35*130cbfc3SBram Moolenaar" Show CategoryInfo, FullyQualifiedErrorId, etc?
36*130cbfc3SBram Moolenaarlet g:ps1_efm_show_error_categories = get(g:, 'ps1_efm_show_error_categories', 0)
37*130cbfc3SBram Moolenaar
38*130cbfc3SBram Moolenaar" Use absolute path because powershell requires explicit relative paths
39*130cbfc3SBram Moolenaar" (./file.ps1 is okay, but # expands to file.ps1)
40*130cbfc3SBram Moolenaarlet &l:makeprg = g:ps1_makeprg_cmd .' %:p:S'
41*130cbfc3SBram Moolenaar
42*130cbfc3SBram Moolenaar" Parse file, line, char from callstacks:
43*130cbfc3SBram Moolenaar"     Write-Ouput : The term 'Write-Ouput' is not recognized as the name of a
44*130cbfc3SBram Moolenaar"     cmdlet, function, script file, or operable program. Check the spelling
45*130cbfc3SBram Moolenaar"     of the name, or if a path was included, verify that the path is correct
46*130cbfc3SBram Moolenaar"     and try again.
47*130cbfc3SBram Moolenaar"     At C:\script.ps1:11 char:5
48*130cbfc3SBram Moolenaar"     +     Write-Ouput $content
49*130cbfc3SBram Moolenaar"     +     ~~~~~~~~~~~
50*130cbfc3SBram Moolenaar"         + CategoryInfo          : ObjectNotFound: (Write-Ouput:String) [], CommandNotFoundException
51*130cbfc3SBram Moolenaar"         + FullyQualifiedErrorId : CommandNotFoundException
52*130cbfc3SBram Moolenaar
53*130cbfc3SBram Moolenaar" Showing error in context with underlining.
54*130cbfc3SBram MoolenaarCompilerSet errorformat=%+G+%m
55*130cbfc3SBram Moolenaar" Error summary.
56*130cbfc3SBram MoolenaarCompilerSet errorformat+=%E%*\\S\ :\ %m
57*130cbfc3SBram Moolenaar" Error location.
58*130cbfc3SBram MoolenaarCompilerSet errorformat+=%CAt\ %f:%l\ char:%c
59*130cbfc3SBram Moolenaar" Errors that span multiple lines (may be wrapped to width of terminal).
60*130cbfc3SBram MoolenaarCompilerSet errorformat+=%C%m
61*130cbfc3SBram Moolenaar" Ignore blank/whitespace-only lines.
62*130cbfc3SBram MoolenaarCompilerSet errorformat+=%Z\\s%#
63*130cbfc3SBram Moolenaar
64*130cbfc3SBram Moolenaarif g:ps1_efm_show_error_categories
65*130cbfc3SBram Moolenaar  CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m
66*130cbfc3SBram Moolenaarelse
67*130cbfc3SBram Moolenaar  CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m
68*130cbfc3SBram Moolenaarendif
69*130cbfc3SBram Moolenaar
70*130cbfc3SBram Moolenaar
71*130cbfc3SBram Moolenaar" Parse file, line, char from of parse errors:
72*130cbfc3SBram Moolenaar"     At C:\script.ps1:22 char:16
73*130cbfc3SBram Moolenaar"     + Stop-Process -Name "invalidprocess
74*130cbfc3SBram Moolenaar"     +                    ~~~~~~~~~~~~~~~
75*130cbfc3SBram Moolenaar"     The string is missing the terminator: ".
76*130cbfc3SBram Moolenaar"         + CategoryInfo          : ParserError: (:) [], ParseException
77*130cbfc3SBram Moolenaar"         + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
78*130cbfc3SBram MoolenaarCompilerSet errorformat+=At\ %f:%l\ char:%c
79*130cbfc3SBram Moolenaar
80*130cbfc3SBram Moolenaar
81*130cbfc3SBram Moolenaarlet &cpo = s:cpo_save
82*130cbfc3SBram Moolenaarunlet s:cpo_save
83*130cbfc3SBram Moolenaar
84*130cbfc3SBram Moolenaar" vim:set sw=2 sts=2:
85