blob: 3d37d7c847775fab81813be7ce9eb855c3674f93 [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)
Bram Moolenaar130cbfc2021-04-07 21:07:20 +02009
10if exists("current_compiler")
11 finish
12endif
13let current_compiler = "powershell"
14
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020015let s:cpo_save = &cpo
16set cpo-=C
17
18if !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
29endif
30
31if !executable(g:ps1_makeprg_cmd)
32 echoerr "To use the powershell compiler, please set g:ps1_makeprg_cmd to the powershell executable!"
33endif
34
35" Show CategoryInfo, FullyQualifiedErrorId, etc?
36let 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)
zeertzjqb73faa12024-04-06 02:01:16 +080040let s:makeprg = g:ps1_makeprg_cmd .. ' %:p:S'
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020041
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
Konfekt4927dae2024-11-19 22:41:14 +010053execute 'CompilerSet makeprg=' .. escape(s:makeprg, ' \|"')
Enno18d730d2024-03-31 18:37:05 +020054
Bram Moolenaar130cbfc2021-04-07 21:07:20 +020055" Showing error in context with underlining.
56CompilerSet errorformat=%+G+%m
57" Error summary.
58CompilerSet errorformat+=%E%*\\S\ :\ %m
59" Error location.
60CompilerSet errorformat+=%CAt\ %f:%l\ char:%c
61" Errors that span multiple lines (may be wrapped to width of terminal).
62CompilerSet errorformat+=%C%m
63" Ignore blank/whitespace-only lines.
64CompilerSet errorformat+=%Z\\s%#
65
66if g:ps1_efm_show_error_categories
67 CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m
68else
69 CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m
70endif
71
72
73" Parse file, line, char from of parse errors:
74" At C:\script.ps1:22 char:16
75" + Stop-Process -Name "invalidprocess
76" + ~~~~~~~~~~~~~~~
77" The string is missing the terminator: ".
78" + CategoryInfo : ParserError: (:) [], ParseException
79" + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
80CompilerSet errorformat+=At\ %f:%l\ char:%c
81
82
83let &cpo = s:cpo_save
84unlet s:cpo_save
85
86" vim:set sw=2 sts=2: