Skip to content

Commit 6967ff2

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. 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 acceptable trade-off, especially as it is already the case for return statements. Fixes microsoft#10583.
1 parent c2e9274 commit 6967ff2

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
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
(?:

src/test/language/languageConfiguration.unit.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { getLanguageConfiguration } from '../../client/language/languageConfigur
1010
const NEEDS_INDENT = [
1111
/^break$/,
1212
/^continue$/,
13-
/^raise$/, // only re-raise
13+
// raise is indented unless it's the only thing on the line
14+
/^raise\b/,
1415
/^return\b/,
1516
];
1617
const INDENT_ON_ENTER = [
@@ -37,7 +38,9 @@ const DEDENT_ON_ENTER = [
3738
///^return\b/,
3839
/^break$/,
3940
/^continue$/,
40-
/^raise\b/,
41+
// For now we are mostly ignoring "return".
42+
// See https://github.com/microsoft/vscode-python/issues/10583.
43+
/^raise$/,
4144
/^pass\b/,
4245
];
4346

0 commit comments

Comments
 (0)