powershell.vim 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. if exists("current_compiler")
  9. finish
  10. endif
  11. let current_compiler = "powershell"
  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 s: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. execute 'CompilerSet makeprg=' .. escape(s:makeprg, ' ')
  45. " Showing error in context with underlining.
  46. CompilerSet errorformat=%+G+%m
  47. " Error summary.
  48. CompilerSet errorformat+=%E%*\\S\ :\ %m
  49. " Error location.
  50. CompilerSet errorformat+=%CAt\ %f:%l\ char:%c
  51. " Errors that span multiple lines (may be wrapped to width of terminal).
  52. CompilerSet errorformat+=%C%m
  53. " Ignore blank/whitespace-only lines.
  54. CompilerSet errorformat+=%Z\\s%#
  55. if g:ps1_efm_show_error_categories
  56. CompilerSet errorformat^=%+G\ \ \ \ +\ %.%#\\s%#:\ %m
  57. else
  58. CompilerSet errorformat^=%-G\ \ \ \ +\ %.%#\\s%#:\ %m
  59. endif
  60. " Parse file, line, char from of parse errors:
  61. " At C:\script.ps1:22 char:16
  62. " + Stop-Process -Name "invalidprocess
  63. " + ~~~~~~~~~~~~~~~
  64. " The string is missing the terminator: ".
  65. " + CategoryInfo : ParserError: (:) [], ParseException
  66. " + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
  67. CompilerSet errorformat+=At\ %f:%l\ char:%c
  68. let &cpo = s:cpo_save
  69. unlet s:cpo_save
  70. " vim:set sw=2 sts=2: