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