blob: 821fea40859f57dd641ebedc03a1b4defc96521a [file] [log] [blame]
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02001" Vim compiler file
2" Compiler: powershell
3" URL: https://github.com/PProvost/vim-ps1
Enno18d730d2024-03-31 18:37:05 +02004" Contributors: Enno Nagel
5" Last Change: 2024 Mar 29
Doug Kearns408281e2024-04-04 22:00:58 +02006" 2024 Apr 03 by The Vim Project (removed :CompilerSet definition)
zeertzjqb73faa12024-04-06 02:01:16 +08007" 2024 Apr 05 by The Vim Project (avoid leaving behind g:makeprg)
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02008
9if exists("current_compiler")
10 finish
11endif
12let current_compiler = "powershell"
13
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020014let s:cpo_save = &cpo
15set cpo-=C
16
17if !exists("g:ps1_makeprg_cmd")
18 if executable('pwsh')
19 " pwsh is the future
20 let g:ps1_makeprg_cmd = 'pwsh'
21 elseif executable('pwsh.exe')
22 let g:ps1_makeprg_cmd = 'pwsh.exe'
23 elseif executable('powershell.exe')
24 let g:ps1_makeprg_cmd = 'powershell.exe'
25 else
26 let g:ps1_makeprg_cmd = ''
27 endif
28endif
29
30if !executable(g:ps1_makeprg_cmd)
31 echoerr "To use the powershell compiler, please set g:ps1_makeprg_cmd to the powershell executable!"
32endif
33
34" Show CategoryInfo, FullyQualifiedErrorId, etc?
35let g:ps1_efm_show_error_categories = get(g:, 'ps1_efm_show_error_categories', 0)
36
37" Use absolute path because powershell requires explicit relative paths
38" (./file.ps1 is okay, but # expands to file.ps1)
zeertzjqb73faa12024-04-06 02:01:16 +080039let s:makeprg = g:ps1_makeprg_cmd .. ' %:p:S'
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020040
41" Parse file, line, char from callstacks:
42" Write-Ouput : The term 'Write-Ouput' is not recognized as the name of a
43" cmdlet, function, script file, or operable program. Check the spelling
44" of the name, or if a path was included, verify that the path is correct
45" and try again.
46" At C:\script.ps1:11 char:5
47" + Write-Ouput $content
48" + ~~~~~~~~~~~
49" + CategoryInfo : ObjectNotFound: (Write-Ouput:String) [], CommandNotFoundException
50" + FullyQualifiedErrorId : CommandNotFoundException
51
zeertzjqb73faa12024-04-06 02:01:16 +080052execute 'CompilerSet makeprg=' .. escape(s:makeprg, ' ')
Enno18d730d2024-03-31 18:37:05 +020053
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020054" Showing error in context with underlining.
55CompilerSet errorformat=%+G+%m
56" Error summary.
57CompilerSet errorformat+=%E%*\\S\ :\ %m
58" Error location.
59CompilerSet errorformat+=%CAt\ %f:%l\ char:%c
60" Errors that span multiple lines (may be wrapped to width of terminal).
61CompilerSet errorformat+=%C%m
62" Ignore blank/whitespace-only lines.
63CompilerSet errorformat+=%Z\\s%#
64
65if g:ps1_efm_show_error_categories
66 CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m
67else
68 CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m
69endif
70
71
72" Parse file, line, char from of parse errors:
73" At C:\script.ps1:22 char:16
74" + Stop-Process -Name "invalidprocess
75" + ~~~~~~~~~~~~~~~
76" The string is missing the terminator: ".
77" + CategoryInfo : ParserError: (:) [], ParseException
78" + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
79CompilerSet errorformat+=At\ %f:%l\ char:%c
80
81
82let &cpo = s:cpo_save
83unlet s:cpo_save
84
85" vim:set sw=2 sts=2: