powershell.vim 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. " Vim compiler file
  2. " Compiler: powershell
  3. " URL: https://github.com/PProvost/vim-ps1
  4. " Last Change: 2020 Mar 30
  5. if exists("current_compiler")
  6. finish
  7. endif
  8. let current_compiler = "powershell"
  9. if exists(":CompilerSet") != 2 " older Vim always used :setlocal
  10. command -nargs=* CompilerSet setlocal <args>
  11. endif
  12. let s:cpo_save = &cpo
  13. set cpo-=C
  14. if !exists("g:ps1_makeprg_cmd")
  15. if executable('pwsh')
  16. " pwsh is the future
  17. let g:ps1_makeprg_cmd = 'pwsh'
  18. elseif executable('pwsh.exe')
  19. let g:ps1_makeprg_cmd = 'pwsh.exe'
  20. elseif executable('powershell.exe')
  21. let g:ps1_makeprg_cmd = 'powershell.exe'
  22. else
  23. let g:ps1_makeprg_cmd = ''
  24. endif
  25. endif
  26. if !executable(g:ps1_makeprg_cmd)
  27. echoerr "To use the powershell compiler, please set g:ps1_makeprg_cmd to the powershell executable!"
  28. endif
  29. " Show CategoryInfo, FullyQualifiedErrorId, etc?
  30. let g:ps1_efm_show_error_categories = get(g:, 'ps1_efm_show_error_categories', 0)
  31. " Use absolute path because powershell requires explicit relative paths
  32. " (./file.ps1 is okay, but # expands to file.ps1)
  33. let &l:makeprg = g:ps1_makeprg_cmd .' %:p:S'
  34. " Parse file, line, char from callstacks:
  35. " Write-Ouput : The term 'Write-Ouput' is not recognized as the name of a
  36. " cmdlet, function, script file, or operable program. Check the spelling
  37. " of the name, or if a path was included, verify that the path is correct
  38. " and try again.
  39. " At C:\script.ps1:11 char:5
  40. " + Write-Ouput $content
  41. " + ~~~~~~~~~~~
  42. " + CategoryInfo : ObjectNotFound: (Write-Ouput:String) [], CommandNotFoundException
  43. " + FullyQualifiedErrorId : CommandNotFoundException
  44. " Showing error in context with underlining.
  45. CompilerSet errorformat=%+G+%m
  46. " Error summary.
  47. CompilerSet errorformat+=%E%*\\S\ :\ %m
  48. " Error location.
  49. CompilerSet errorformat+=%CAt\ %f:%l\ char:%c
  50. " Errors that span multiple lines (may be wrapped to width of terminal).
  51. CompilerSet errorformat+=%C%m
  52. " Ignore blank/whitespace-only lines.
  53. CompilerSet errorformat+=%Z\\s%#
  54. if g:ps1_efm_show_error_categories
  55. CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m
  56. else
  57. CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m
  58. endif
  59. " Parse file, line, char from of parse errors:
  60. " At C:\script.ps1:22 char:16
  61. " + Stop-Process -Name "invalidprocess
  62. " + ~~~~~~~~~~~~~~~
  63. " The string is missing the terminator: ".
  64. " + CategoryInfo : ParserError: (:) [], ParseException
  65. " + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
  66. CompilerSet errorformat+=At\ %f:%l\ char:%c
  67. let &cpo = s:cpo_save
  68. unlet s:cpo_save
  69. " vim:set sw=2 sts=2: