diff --git a/extensions/positron-r/src/test/snapshots/indentation-cases.R b/extensions/positron-r/src/test/snapshots/indentation-cases.R index 45888014f60..b37623f068d 100644 --- a/extensions/positron-r/src/test/snapshots/indentation-cases.R +++ b/extensions/positron-r/src/test/snapshots/indentation-cases.R @@ -60,7 +60,7 @@ data |> # --- # Continuing a one-liner pipeline (after a comment line) -# FIXME (once we merge the sticky dedent PR) +# FIXME data |> fn1() |> # foo @@ -113,14 +113,12 @@ data |> # --- # Stickiness of dedent after pipeline # https://github.com/posit-dev/positron/issues/1727 -# FIXME data |> fn() "<>" # --- # Stickiness of dedent after pipeline (trailing comment) -# FIXME data |> fn() "<>" # foo diff --git a/extensions/positron-r/src/test/snapshots/indentation-snapshots.R b/extensions/positron-r/src/test/snapshots/indentation-snapshots.R index 32006570dbb..632ffdc4b2c 100644 --- a/extensions/positron-r/src/test/snapshots/indentation-snapshots.R +++ b/extensions/positron-r/src/test/snapshots/indentation-snapshots.R @@ -97,7 +97,7 @@ data |> # --- # Continuing a one-liner pipeline (after a comment line) -# FIXME (once we merge the sticky dedent PR) +# FIXME data |> fn1() |> # foo @@ -108,7 +108,7 @@ data |> fn1() |> # foo - "<>" +"<>" # --- # Continuing a one-liner pipeline (longer pipeline) @@ -198,7 +198,6 @@ data |> # --- # Stickiness of dedent after pipeline # https://github.com/posit-dev/positron/issues/1727 -# FIXME data |> fn() "<>" @@ -207,11 +206,10 @@ data |> data |> fn() - "<>" +"<>" # --- # Stickiness of dedent after pipeline (trailing comment) -# FIXME data |> fn() "<>" # foo @@ -220,7 +218,7 @@ data |> data |> fn() -"<>" # foo +"<>"# foo # --- # Indent after function in call diff --git a/src/vs/editor/common/languages/autoIndent.ts b/src/vs/editor/common/languages/autoIndent.ts index 9ae3df974aa..bff68c1f193 100644 --- a/src/vs/editor/common/languages/autoIndent.ts +++ b/src/vs/editor/common/languages/autoIndent.ts @@ -75,7 +75,10 @@ export function getInheritIndentForLine( model: IVirtualModel, lineNumber: number, honorIntentialIndent: boolean = true, - languageConfigurationService: ILanguageConfigurationService + // --- Start Positron --- + languageConfigurationService: ILanguageConfigurationService, + indentConverter: IIndentConverter | undefined = undefined + // --- End Positron --- ): { indentation: string; action: IndentAction | null; line?: number } | null { if (autoIndent < EditorAutoIndentStrategy.Full) { return null; @@ -165,8 +168,33 @@ export function getInheritIndentForLine( } if (honorIntentialIndent) { + // --- Start Positron --- + // Patch from https://github.com/microsoft/vscode/pull/136593 + // For https://github.com/posit-dev/positron/issues/1727 + + let indentation = strings.getLeadingWhitespace(model.getLineContent(precedingUnIgnoredLine)); + // Check for onEnter rules that should decrease the indent + if (indentConverter) { + const richEditSupport = languageConfigurationService.getLanguageConfiguration(model.tokenization.getLanguageId()); + if (richEditSupport) { + const previousLineText = precedingUnIgnoredLine < 1 ? '' : model.getLineContent(precedingUnIgnoredLine - 1); + const afterEnterText = ''; + const enterResult = richEditSupport.onEnter(autoIndent, previousLineText, precedingUnIgnoredLineContent, afterEnterText); + if (enterResult) { + if (enterResult.indentAction === IndentAction.Outdent) { + indentation = indentConverter.unshiftIndent(indentation); + } else if (enterResult.removeText && indentation.length >= enterResult.removeText) { + indentation = indentation.substring(0, indentation.length - enterResult.removeText - 1); + } + } + } + } + // --- End Positron --- + return { - indentation: strings.getLeadingWhitespace(model.getLineContent(precedingUnIgnoredLine)), + // --- Start Positron --- + indentation, + // --- End Positron --- action: null, line: precedingUnIgnoredLine }; @@ -235,7 +263,9 @@ export function getGoodIndentForLine( return null; } - const indent = getInheritIndentForLine(autoIndent, virtualModel, lineNumber, undefined, languageConfigurationService); + // --- Start Positron --- + const indent = getInheritIndentForLine(autoIndent, virtualModel, lineNumber, undefined, languageConfigurationService, indentConverter); + // --- End Positron --- const lineContent = virtualModel.getLineContent(lineNumber); if (indent) { @@ -361,7 +391,9 @@ export function getIndentForEnter( }; const currentLineIndent = strings.getLeadingWhitespace(lineTokens.getLineContent()); - const afterEnterAction = getInheritIndentForLine(autoIndent, virtualModel, range.startLineNumber + 1, undefined, languageConfigurationService); + // --- Start Positron --- + const afterEnterAction = getInheritIndentForLine(autoIndent, virtualModel, range.startLineNumber + 1, undefined, languageConfigurationService, indentConverter); + // --- End Positron --- if (!afterEnterAction) { const beforeEnter = embeddedLanguage ? currentLineIndent : beforeEnterIndent; return { @@ -430,7 +462,9 @@ export function getIndentActionForType( if (!indentRulesSupport.shouldDecrease(beforeTypeText + afterTypeText) && indentRulesSupport.shouldDecrease(beforeTypeText + ch + afterTypeText)) { // after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner. // 1. Get inherited indent action - const r = getInheritIndentForLine(autoIndent, model, range.startLineNumber, false, languageConfigurationService); + // --- Start Positron --- + const r = getInheritIndentForLine(autoIndent, model, range.startLineNumber, false, languageConfigurationService, indentConverter); + // --- End Positron --- if (!r) { return null; }