powershell.vim 2.8 KB

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