Change:
<ins> /*--------------------------------------------------------------------------------------------- *  Copyright (c) Microsoft Corporation. All rights reserved. *  Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { EditorAction2 } from 'vs/editor/browser/editorExtensions'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2'; import { localize } from 'vs/nls'; import { registerAction2 } from 'vs/platform/actions/common/actions'; import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { pickSnippet } from 'vs/workbench/contrib/snippets/browser/snippetPicker'; import { ISnippetsService } from 'vs/workbench/contrib/snippets/browser/snippets.contribution'; registerAction2(class SurroundWithAction extends EditorAction2 { constructor() { super({ id: 'editor.action.surroundWithSnippet', title: { value: localize('label', 'Surround With Snippet...'), original: 'Surround With Snippet...' }, precondition: ContextKeyExpr.and(EditorContextKeys.writable, EditorContextKeys.hasNonEmptySelection), f1: true }); } async runEditorCommand(accessor: ServicesAccessor, editor: ICodeEditor, ...args: any[]) { const snippetService = accessor.get(ISnippetsService); const clipboardService = accessor.get(IClipboardService); const instaService = accessor.get(IInstantiationService); if (!editor.hasModel()) { return; } const { lineNumber, column } = editor.getPosition(); editor.getModel().tokenizeIfCheap(lineNumber); const languageId = editor.getModel().getLanguageIdAtPosition(lineNumber, column); const allSnippets = await snippetService.getSnippets(languageId, { includeNoPrefixSnippets: true, includeDisabledSnippets: true }); const surroundSnippets = allSnippets.filter(snippet => snippet.usesSelection); const snippet = await instaService.invokeFunction(pickSnippet, surroundSnippets); if (!snippet) { return; } let clipboardText: string | undefined; if (snippet.needsClipboard) { clipboardText = await clipboardService.readText(); } SnippetController2.get(editor)?.insert(snippet.codeSnippet, { clipboardText }); } }); </ins>

Discussion:
Snippets that use the SELECTION variable should be grouped into a new "Surround With..."-command, e.g support selection with try-catch or if-else. We should also consider not showing such snippets in IntelliSense because the selection is always where users are typing.
closing this in favour of
After and given that a dedicated command is more visible we should add this
hi, Thanks for your adding support for outside code and could please add some identification for those snippet support and/or when users are using command e.g.: when using insert snippet, users never know which snippet is outside-code supported there is the ui: ! and the snippet code from C# official extension ! for that reason, I have to add some tip/text for the name of snippet when I develop the snippet extension. after that, user could know that which is outside code supported. ! I could do it for myself and my extension, I there are many snippets that have no tip or identification Please add some identification for those outside code supported in UI when users using insert snippet. that will be useful and helpful for user to distinguish
! maybe some icon for text is good
BTW, there is another issues related to this. please
hi, should I file a new issue?
To verify open a typescript files select some code select F1 Surround with Snippet try-catch ensure the selected code is surrounded by the snippet
Verification looked good with both TS and CS files.