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