Skip to content

Commit 60f61be

Browse files
committed
Don't outdent on enter after raise with arguments
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. Previosly 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.
1 parent c2e9274 commit 60f61be

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

news/2 Fixes/10583.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Make on-enter behaviour after `raise` much more like that of `return`, fixing
2+
handling in the case of pressing enter to wrap the parentheses of an exception
3+
call.
4+
(thanks [PeterJCLaw](https://github.com/PeterJCLaw))

src/client/language/languageConfiguration.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,20 @@ export function getLanguageConfiguration(): LanguageConfiguration {
7676
},
7777
// outdent on enter (block-ending statements)
7878
{
79+
/**
80+
* This does not handle all cases. Notable omissions here are
81+
* "return" and "raise" which are complicated by the need to
82+
* only outdent when the cursor is at the end of an expression
83+
* rather than, say, between the parentheses of a tail-call or
84+
* exception construction. (see issue #10583)
85+
*/
7986
beforeText: verboseRegExp(`
8087
^
8188
(?:
8289
(?:
8390
\\s*
8491
(?:
85-
pass |
86-
raise \\s+ [^#\\s] [^#]*
92+
pass
8793
)
8894
) |
8995
(?:

0 commit comments

Comments
 (0)