Repository: vscode
Issue: Incorrect indentation when passing snippet string as argument in inline suggestions
Labels: bug,inline-completions

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.81.1
- OS Version: Development done in MacOS Ventura (Version 13.5), occurs in all OSes.

## USE-CASE:
We are currently using Inline suggestions, and the text that goes in as the parameter is a snippetString. The snippet string is used as we need tab stops as the inline suggestion is committed.

## BUG:
We have noticed something unusual:
All the strings are passed through a function that converts them to snippet strings and adds tab stops to a particular substring if it matches a regex. 
For the cases where no tab stops are added, the indentation seems to be fine.
But, for the cases where tab stops are added, on committing the inline suggestion, extra indentation appears.

Eg of no indentation changes:
![ezgif-2-d435563887](https://github.com/microsoft/vscode/assets/42550351/87aab291-352c-47ab-ab3e-f6b11438358a)


Eg of change in indentation when tab-stops are added:
![ezgif-2-565c0ab68b](https://github.com/microsoft/vscode/assets/42550351/e25b72ba-2581-4f65-aa8f-5d3027a97441)


## CODE:
Here's the code that does the conversion:
```typescript
export function convertToSnippetString(suggestion: string): string {
  const regex = /({{ )(_[a-zA-Z_]\w*_)( }})/gm;
  const matches = [...suggestion.matchAll(regex)];

  let modifiedSuggestion = suggestion;

  let counter = 0;
  matches.forEach((matchArray) => {
    const exactMatch = matchArray[2]; // get only the variable, without the braces
    counter = counter + 1;
    modifiedSuggestion = modifiedSuggestion.replace(
      exactMatch,
      `\$\{${counter}:${exactMatch}\}`
    ); // replace the match with tab stop syntax according to vscode snippet strings, i.e., ${1:foo}
  });

  let newIndentedSuggestion = modifiedSuggestion;

  return newIndentedSuggestion;
}
```

Here's how it is called:
```typescript
    // convert text to snippet string
    const insertTextSnippetString = new vscode.SnippetString(
      convertToSnippetString(insertText)
    );

    const inlineSuggestionItem = new vscode.InlineCompletionItem(
      insertTextSnippetString
    );
    inlineSuggestionUserActionItems.push(inlineSuggestionItem);
```

Let us know if this is a bug from the vscode code side or if there's some implementation error in the code.