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