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

code-snippets autocomplete is broken #209534

Closed
umnovI opened this issue Apr 4, 2024 · 21 comments · Fixed by #236245 · May be fixed by #235605
Closed

code-snippets autocomplete is broken #209534

umnovI opened this issue Apr 4, 2024 · 21 comments · Fixed by #236245 · May be fixed by #235605
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders json JSON support issues verified Verification succeeded
Milestone

Comments

@umnovI
Copy link

umnovI commented Apr 4, 2024

Type: Bug

  1. Add a new snippet to any of the code-snippets for any language
    For example:
"test": {
}
  1. Type ", it gets completed to "|" (this steps is important)
  2. Start typing any of the keywords, for example, "body".
  3. Choose autocomplete suggestion

Inserted Autocomplete is an invalid json with """

VS Code version: Code 1.87.2 (863d258, 2024-03-08T15:20:17.278Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs AMD Ryzen 7 5800H with Radeon Graphics (16 x 3194)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 27.86GB (14.35GB free)
Process Argv E:\cloned-projects\project-examples\dioxus\.docker\README.md --crash-reporter-id 01bfe09d-0674-44f2-89ca-c8d7b1e31919
Screen Reader no
VM 0%
Extensions: none
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscorecescf:30445987
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:30899288
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:31000450
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
d34g3935:30971562
fegfb526:30981948
bg6jg535:30979843
ccp2r3:30993541
dsvsc020:30976470
pythonait:31006305
gee8j676:31009558
dsvsc021:30996838
gd77d436:30999572

@umnovI
Copy link
Author

umnovI commented Apr 4, 2024

clideo_editor_bcd22b3726e3474aaf9769e263a967a2

@jrieken jrieken added info-needed Issue requires more information from poster snippets labels Dec 9, 2024
@jrieken
Copy link
Member

jrieken commented Dec 9, 2024

I am using your steps, but I cannot reproduce this. Do you have any other setting that could influence this?

Copy link

Please diagnose the root cause of the issue by running the command F1 > Help: Troubleshoot Issue and following the instructions. Once you have done that, please update the issue with the results.

Happy Coding!

@RedCMD
Copy link
Contributor

RedCMD commented Dec 9, 2024

can confirm

@jrieken reload VSCode with the file open
more specifically; have that Snippet file the first Snippet file you've opened since reload

have "editor.suggest.insertMode" set to default "insert"

related #231224

@RedCMD
Copy link
Contributor

RedCMD commented Dec 9, 2024

"[snippets]" will need to be added to "configurationDefaults"

"configurationDefaults": {
"[json]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"[jsonc]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
}
},

"[jsonl]" should also be added aswell

PR #235605

@RedCMD
Copy link
Contributor

RedCMD commented Dec 9, 2024

partial pr #235605

@jrieken
Copy link
Member

jrieken commented Dec 9, 2024

@RedCMD Sorry, I can still not produce. Please help by distilling exact reproducible step and do not jump to any conclusions yet

@RedCMD
Copy link
Contributor

RedCMD commented Dec 9, 2024

can confirm insiders.vscode.dev

20241209-1041-57.1286095.mp4

thank you for your time

@jrieken
Copy link
Member

jrieken commented Dec 9, 2024

🤷

Screen.Recording.2024-12-09.at.11.51.22.mov

@jrieken
Copy link
Member

jrieken commented Dec 9, 2024

@aeschli Do you have a clue? This seems to be JSON-schema based completions related but I can't reproduce

@RedCMD
Copy link
Contributor

RedCMD commented Dec 9, 2024

type the double quotes first "|"

or place any character after your cursor

eg. bo|dy results in "body": "|"dy
Image
Image

@RedCMD
Copy link
Contributor

RedCMD commented Dec 9, 2024

  1. make sure "editor.suggest.insertMode" is set to default "insert"
  2. Create .code-snippets file with code
{
	"test": {
		""
	}
}
  1. assign language snippets
  2. place cursor at the "" position and attempt code completion of "body"
    image
  3. expect the correct number of valid double quotes
    image

actual:
3 sets of double quotes """ are created 🐛

please do not skip any steps
and provide a video if it's not reproducing
thanks

@jrieken jrieken removed info-needed Issue requires more information from poster snippets labels Dec 16, 2024
@jrieken jrieken assigned aeschli and unassigned jrieken Dec 16, 2024
@jrieken
Copy link
Member

jrieken commented Dec 16, 2024

I have updated the original steps, it's important to start with "|" before asking for suggestions

@aeschli I can see that JSON gives this completion text and no "overwrite after", which then leads to double quotes. Check insertText here

Image

@aeschli
Copy link
Contributor

aeschli commented Dec 16, 2024

The problem is that for snippets, the default is 'insert' mode. For JSON it is 'replace' mode.

For this example:

"test": {
""
}

with the cursor between the "", the JSON language server produces the following suggestion:
replace: insertText: "body": "$1", range: [1, 0] - [1, 2]
insert: insertText: "body": "$1", range: [1, 0] - [1, 1]

The JSON server produces the correct results, it's just that users don't expect insert mode, they expect replace mode.

@aeschli aeschli added json JSON support issues bug Issue identified by VS Code Team member as probable bug labels Dec 16, 2024
@aeschli aeschli added this to the January 2025 milestone Dec 16, 2024
@jrieken
Copy link
Member

jrieken commented Dec 16, 2024

The problem is that for snippets, the default is 'insert' mode. For JSON it is 'replace' mode.

Which is incompatible with VS Code's default. Can't we get alignment here?

@vs-code-engineering vs-code-engineering bot added the unreleased Patch has not yet been released in VS Code Insiders label Dec 16, 2024
@RedCMD
Copy link
Contributor

RedCMD commented Dec 16, 2024

Which is incompatible with VS Code's default. Can't we get alignment here?

@jrieken #209534 (comment)

@aeschli
Copy link
Contributor

aeschli commented Dec 16, 2024

IMO using insert as default would mean for JSON to no longer return richer completions such as "value": "property" when completing inside "". The completion would have to be value only. The user would then move the cursor over the " and type : and then complete the value.
That would be quite a change in how JSON editing works and a loss of convenience to the user.
Same would apply to CSS and HTML which also have values as quoted strings
IMO insert is not good for languages with quoted strings given that we always auto close quotes.

@jrieken
Copy link
Member

jrieken commented Dec 17, 2024

IMO insert is not good for languages with quoted strings given that we always auto close quotes.

We added replace-ranges quite late to VS Code, how did JSON work the years before that?

@vs-code-engineering vs-code-engineering bot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Dec 17, 2024
@RedCMD
Copy link
Contributor

RedCMD commented Dec 17, 2024

og commits:
2017 "editor.quickSuggestions": dc31a48
2019 "editor.suggest.insertMode": 5f1b81b#diff-85bdebc30242f87ed2d5fde09e5db9b58126b1d5c8b14bd18164f250ac9a649bR101

@aeschli
Copy link
Contributor

aeschli commented Dec 17, 2024

Code completions started with insertText. Shortly after the range was added, allowing completions to have full control of what was replaced before and after the cursor as well. That's when JSON/CSS/HTML was mostly written. Only much later, the concepts of insert and replace mode was added and 'insert' was declared as the default. I already brought it up at the time that this didn't fit well with what we already had with JSON/CSS/HTML and going to a pure 'insert' mode would be a step back for the user experience in JSON/CSS/HTML

@jrieken
Copy link
Member

jrieken commented Dec 17, 2024

Only much later, the concepts of insert and replace mode was added and 'insert' was declared as the default.

But that's only a user default (because it matches what mostlanguages were doing at the time, and still do). It does not mean each language must implement insert and replace for all completions, you could have left everything as before.

In JSON, with a complex suggestion like "key": "value" only offer one variant, for a simple suggestion like value offer both, unbiased wrt the user's config.

@TylerLeonhardt TylerLeonhardt added the verified Verification succeeded label Jan 30, 2025
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Feb 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders json JSON support issues verified Verification succeeded
Projects
None yet
5 participants