Skip to content

Don't outdent on enter after raise with arguments #15516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 deletions src/test/language/languageConfiguration.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { getLanguageConfiguration } from '../../client/language/languageConfigur
const NEEDS_INDENT = [
/^break$/,
/^continue$/,
/^raise$/, // only re-raise
// raise is indented unless it's the only thing on the line
/^raise\b/,
/^return\b/,
];
const INDENT_ON_ENTER = [
Expand All @@ -37,7 +38,9 @@ const DEDENT_ON_ENTER = [
///^return\b/,
/^break$/,
/^continue$/,
/^raise\b/,
// For now we are mostly ignoring "return".
// See https://github.com/microsoft/vscode-python/issues/10583.
/^raise$/,
/^pass\b/,
];

Expand Down