Skip to content
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

Snippet Choice Traps Focus #236489

Open
brenapp opened this issue Dec 18, 2024 · 2 comments
Open

Snippet Choice Traps Focus #236489

brenapp opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug snippets

Comments

@brenapp
Copy link

brenapp commented Dec 18, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.96.0
  • OS Version: Windows 11, and Mac OS
Version: 1.96.0 (user setup)
Commit: 138f619c86f1199955d53b4166bef66ef252935c
Date: 2024-12-11T02:29:09.626Z
Electron: 32.2.6
ElectronBuildId: 10629634
Chromium: 128.0.6613.186
Node.js: 20.18.1
V8: 12.8.374.38-electron.0
OS: Windows_NT x64 10.0.22631

My extension's Language Server provides snippets to complete function documentation as part of its textDocument/completion handler. Here is an example snippet it provides:

;---------
; SCOPE:        ${1|PRIVATE,INTERNAL,PUBLIC|}
; DESCRIPTION:  ${2}
; PARAMETERS:
;   subject (${3|I,O,IO|},${4|REQ,OPT|}${5}) - ${6}
;   body (${7|I,O,IO|},${8|REQ,OPT|}${9}) - ${10}
;   inst (${11|I,O,IO|},${12|REQ,OPT|}${13}) - ${14}
;   interval (${15|I,O,IO|},${16|REQ,OPT|}${17}) - ${18}
;${0}
;---------

When the user offers the snippet, the content is inserted correctly. However, when they tab to one of the lines below PARAMETERS: and stop on any of the ${X|I,O,IO|} and ${X|REQ,OPT|} tab choices, they can no longer Shift+Tab to a tab stop before the choice. Interestingly, if the user has reached the ${2} tab stop, they can tab back to the $1 choice.

In order to verify this was not an issue with the extension itself, I copied this snippet to be a user-configured global snippet per these instructions.

{
	"Function Header": {
		"scope": "",
		"prefix": ";",
		"body": [
			";---------",
			"; SCOPE:        ${1|PRIVATE,INTERNAL,PUBLIC|}",
			"; DESCRIPTION:  ${2}",
			"; PARAMETERS:",
			";   subject (${3|I,O,IO|},${4|REQ,OPT|}${5}) - ${6}",
			";   body (${7|I,O,IO|},${8|REQ,OPT|}${9}) - ${10}",
			";   inst (${11|I,O,IO|},${12|REQ,OPT|}${13}) - ${14}",
			";   interval (${15|I,O,IO|},${16|REQ,OPT|}${17}) - ${18}",
			";${0}",
			";---------"
		]
	}
}

Steps to Reproduce:

  1. Create this snippet in your global snippet configuration
  2. In a new document, accept the snippet
  3. Tab to the I/O/IO tab choice on the line subject parameter.
  4. You can no longer shift tab back to ${2}
@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug snippets labels Dec 18, 2024
@jrieken
Copy link
Member

jrieken commented Dec 18, 2024

Thanks for the detailed issue ❤

I can see that no command is executed

 INFO [KeybindingService]: | Resolving shift+[Tab]
log.js:230  INFO [KeybindingService]: \ From 5 keybinding entries, no when clauses matched the context.
log.js:230  INFO [KeybindingService]: + Ignoring single modifier shift due to it being pressed together with other keys.

Which mean this condition doesn't hold (which seems wrong/strange)

precondition: ContextKeyExpr.and(SnippetController2.InSnippetMode, SnippetController2.HasPrevTabstop),

@jrieken
Copy link
Member

jrieken commented Dec 18, 2024

My former comment isn't correct (apart from the praise for this issue). Actually this command is being triggered

 INFO [KeybindingService]: | Resolving shift+[Tab]
log.js:230  INFO [KeybindingService]: \ From 5 keybinding entries, matched acceptAlternativeSelectedSuggestion, when: suggestWidgetHasFocusedSuggestion && suggestWidgetVisible && textInputFocus, source: built-in.
log.js:230  INFO [KeybindingService]: + Invoking command acceptAlternativeSelectedSuggestion.
log.js:230  INFO [KeybindingService]: / Soft dispatching keyboard event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug snippets
Projects
None yet
Development

No branches or pull requests

2 participants