blob: d5dd692096c38fca9f6970bbfde09919716e7a9f [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
Konfekt4927dae2024-11-19 22:41:14 +01006" 2024 Apr 03 by the Vim Project (removed :CompilerSet definition)
7" 2024 Apr 05 by the Vim Project (avoid leaving behind g:makeprg)
8" 2024 Nov 19 by the Vim Project (properly escape makeprg setting)
Konfekt4fa2dd22025-03-11 21:35:48 +01009" 2025 Mar 11 by the Vim Project (add comment for Dispatch)
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020010
11if exists("current_compiler")
12 finish
13endif
14let current_compiler = "powershell"
15
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020016let 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)
zeertzjqb73faa12024-04-06 02:01:16 +080041let s: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
Konfekt4fa2dd22025-03-11 21:35:48 +010054" CompilerSet makeprg=pwsh
55" CompilerSet makeprg=powershell
Konfekt4927dae2024-11-19 22:41:14 +010056execute 'CompilerSet makeprg=' .. escape(s:makeprg, ' \|"')
Enno18d730d2024-03-31 18:37:05 +020057
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020058" Showing error in context with underlining.
59CompilerSet errorformat=%+G+%m
60" Error summary.
61CompilerSet errorformat+=%E%*\\S\ :\ %m
62" Error location.
63CompilerSet errorformat+=%CAt\ %f:%l\ char:%c
64" Errors that span multiple lines (may be wrapped to width of terminal).
65CompilerSet errorformat+=%C%m
66" Ignore blank/whitespace-only lines.
67CompilerSet errorformat+=%Z\\s%#
68
69if g:ps1_efm_show_error_categories
70 CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m
71else
72 CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m
73endif
74
75
76" Parse file, line, char from of parse errors:
77" At C:\script.ps1:22 char:16
78" + Stop-Process -Name "invalidprocess
79" + ~~~~~~~~~~~~~~~
80" The string is missing the terminator: ".
81" + CategoryInfo : ParserError: (:) [], ParseException
82" + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
83CompilerSet errorformat+=At\ %f:%l\ char:%c
84
85
86let &cpo = s:cpo_save
87unlet s:cpo_save
88
89" vim:set sw=2 sts=2: