Skip to content

Commit

Permalink
Don't outdent on enter after raise with arguments
Browse files Browse the repository at this point in the history
This changes the behaviour of pressing enter after a raise statement
which involves an explicit value so that the cursor position is no
longer outdented. Previously this worked well for things like:

    raise
    raise e

but less well for things like:

    raise Exception(|)

which wouuld end up like:

    raise Exception(
|)

With this change applied the latter case will end up like:

    raise Exception(
        |
    )

which matches the behaviour of 'return'. The first case (without
a value) is unaffected, though the case of:

    raise e

will, just like 'return' now require the user to explicitly
outdent after pressing enter. It is expected that this is an
accpetable trade-off, especially as it is alrady the case for
return statements.

Fixes microsoft#10583.
  • Loading branch information
PeterJCLaw committed Feb 27, 2021
1 parent c2e9274 commit fc3ac87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions news/2 Fixes/10583.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Make on-enter behaviour after `raise` much more like that of `return`, fixing
handling in the case of pressing enter to wrap the parentheses of an exception
call.
(thanks [PeterJCLaw](https://github.com/PeterJCLaw))
10 changes: 8 additions & 2 deletions src/client/language/languageConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,20 @@ export function getLanguageConfiguration(): LanguageConfiguration {
},
// outdent on enter (block-ending statements)
{
/**
* This does not handle all cases. Notable omissions here are
* "return" and "raise" which are complicated by the need to
* only outdent when the cursor is at the end of an expression
* rather than, say, between the parentheses of a tail-call or
* exception construction. (see issue #10583)
*/
beforeText: verboseRegExp(`
^
(?:
(?:
\\s*
(?:
pass |
raise \\s+ [^#\\s] [^#]*
pass
)
) |
(?:
Expand Down

0 comments on commit fc3ac87

Please sign in to comment.