diff --git a/news/2 Fixes/10583.md b/news/2 Fixes/10583.md new file mode 100644 index 000000000000..3052bb2a28ea --- /dev/null +++ b/news/2 Fixes/10583.md @@ -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)) diff --git a/src/client/language/languageConfiguration.ts b/src/client/language/languageConfiguration.ts index 8dfe6dc0174b..13434a9ecf55 100644 --- a/src/client/language/languageConfiguration.ts +++ b/src/client/language/languageConfiguration.ts @@ -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 ) ) | (?: diff --git a/src/test/language/languageConfiguration.unit.test.ts b/src/test/language/languageConfiguration.unit.test.ts index 87f89ae9221a..a9f74dff2c1a 100644 --- a/src/test/language/languageConfiguration.unit.test.ts +++ b/src/test/language/languageConfiguration.unit.test.ts @@ -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 = [ @@ -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/, ];