SeeminglyScience / EditorServicesCommandSuite

Collection of editor commands for use in PowerShell Editor Services.
Other
151 stars 13 forks source link

Improve ConvertTo-SplatExpression error message when cursor position is not within a command. #27

Open SeeminglyScience opened 6 years ago

SeeminglyScience commented 6 years ago

Right now the error message is this:

ConvertTo-SplatExpression : Unable to find an AST of type 'CommandAst' at the specified location.
At line:1 char:1
+ ConvertTo-SplatExpression
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [ConvertTo-SplatExpression], ArgumentException
+ FullyQualifiedErrorId : MissingAst,ConvertTo-SplatExpression

Which is pretty meaningless to most people. Should be something like "Unable to determine which command to splat. Ensure the cursor is placed within a command and try again."

I should also check for active selections and look for CommandAst's anywhere within.

Thank you @jkavanagh58!

jkavanagh58 commented 6 years ago

Thank you sir, definitely operator error but a more descriptive error may have kept me from performing the same action expecting different behavior. 🤕

SeeminglyScience commented 5 years ago

There's a few improvements coming in 0.5.0 that make this a bit easier to use

  1. If your cursor is directly after the command AST it'll pick that up
  2. It'll recurse parent ASTs to find the most likely target when your cursor is within nested expressions