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

Problems with nested snippet insertion #39594

Closed
tnrich opened this issue Dec 4, 2017 · 23 comments
Closed

Problems with nested snippet insertion #39594

tnrich opened this issue Dec 4, 2017 · 23 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug snippets verified Verification succeeded
Milestone

Comments

@tnrich
Copy link

tnrich commented Dec 4, 2017

I couldn't leave a comment on any of the many issues that seemingly address this error:

#26907

#27015

#26915

#27015

because they were all locked. I am still definitely hitting this error and am on the latest possible stable vscode version:
image

Here is a screenshot of the issue popping up:

image

I'm not sure what causes the error to start occurring, but once it starts, every time I try to tab complete anything I get this annoying message and the cursor position gets off in a funky way such that I can't use my regular snippets.

@tnrich tnrich changed the title Still hitting: "Invalid Argument" error when pressing tab ranomly?" Still hitting: "Invalid Argument" error when pressing tab randomly?" Dec 4, 2017
@ramya-rao-a
Copy link
Contributor

Can you open the console (Help -> Toggle Developer Tools -> Console) and share any error messages there with call stacks?

@tnrich
Copy link
Author

tnrich commented Dec 4, 2017

I will once I'm able to reproduce it. I restarted so it might be a little bit before the error starts up again.

@ramya-rao-a ramya-rao-a added the info-needed Issue requires more information from poster label Dec 4, 2017
@Braincompiler
Copy link

Braincompiler commented Dec 5, 2017

I'm getting this error with a custom code snippet (elm.json, for elm language in this case):

"Function definition w/ 2 arguments": {
	"prefix": "fn2",
	"body": [
		"$1 : $2 -> $3 -> $4",
		"$1 $5 $6 =",
		"    $0"
	],
	"description": "Function definition w/ 2 arguments"
},

while this is working:

"Function definition w/ 1 arguments": {
	"prefix": "fn1",
	"body": [
		"$1 : $2 -> $3",
		"$1 $4 =",
		"    $0"
	],
	"description": "Function definition w/ 1 arguments"
},

The developer tools:
image

After restarting vscode it's working as expected.

@ramya-rao-a ramya-rao-a added snippets and removed info-needed Issue requires more information from poster labels Dec 6, 2017
@jrieken jrieken added the bug Issue identified by VS Code Team member as probable bug label Dec 6, 2017
@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

Exciting... I have been getting this via error telemetry since a long time but was never able to reproduce.

@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

Not exciting... @Braincompiler I jump on your snippet but it seems that you are taking this issue hostage as it unrelated to the invalid argument issue mentioned before. Still, please try to prodive reproducible steps. Just inserting the snippet doesn't do it, sadly...

@jrieken jrieken added info-needed Issue requires more information from poster and removed bug Issue identified by VS Code Team member as probable bug snippets labels Dec 6, 2017
@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

@tnrich I am sorry but we do need steps for this... Also, don't believe that all illegal-argument errors have the same cause. It's a general we use and it can occur in different places and be triggered in different ways

@microsoft microsoft deleted a comment from james-woodbridge Dec 6, 2017
@james-woodbridge
Copy link

@jrieken why was my comment deleted?

@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

Because you are taking this issue as hostage. There is roughly 20 different places in the code that can trigger this error. @tnrich Has not yet provided reproducible steps nor a stack trace which means it's not clear how and when this happens. So I wonder what data points make you believe that you encounter this exact same issue? Why are you so sure it's not a different issue? Last, why do you think saying me too, also without reproducible steps, is of any help?

It's not that we don't like issues and we do value feedback but don't take an issue hostage. Please create a new issue. Once steps are available we might know for sure that an issue is a duplicate. Saying "I see this too" on an 'needs-more-info' issue without having more insights is a logical flaw.

@james-woodbridge
Copy link

james-woodbridge commented Dec 6, 2017

@jrieken I find your tone and response to be overly aggressive and dramatic, and not a good way to carry out user support. My issue also occurred whilst using tab to autocomplete things, hence why I commented and although I did forgot to include reproducible steps, I did include error information and a screenshot. 'Taking hostage' is a gross exaggeration, I did not deman a solution, I simply contirbuted extra information.

Perhaps, instead of just deleting the comment without explanation, you could have asked me for further information, and thus sped up the resolution of an open issue?

@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

Perhaps, instead of just deleting the comment without comment, you could have asked me for further information,

Yes, you are right. Deleting the comment wasn't the nice thing to do and I am sorry for that. To explain my self (not to justify): When you get lots of issues every day you'll develop an allergy towards missing information.

Again, please file a new issue. It doesn't cost much. When an error occurs try to remember what you just did and then try to reproduce. That's the most valuable thing to do. Thanks

@jrieken
Copy link
Member

jrieken commented Dec 6, 2017

every time I try to tab complete anything

@tnrich Please clarify you understanding "tab complete". Is this

  1. the suggestion widget shows and you hit tab to select an item?
  2. you have enabled tab-completion ("editor.tabCompletion": true,), typed the prefix of a snippet, and you have hit tab?
  3. you have enabled emmet-tab-expansion ("emmet.triggerExpansionOnTab": true,) and the error occurs
  4. none of the above

@james-woodbridge
Copy link

Again, please file a new issue. It doesn't cost much. When an error occurs try to remember what you just did and then try to reproduce. That's the most valuable thing to do. Thanks
@jrieken I understand, I handle support for clients too and deal with missing information daily. I have opened a separate issue. I will leave this thread now. Good luck narrowing down the problem :)

@tnrich
Copy link
Author

tnrich commented Dec 6, 2017

Okay, it started happening again. Not sure what caused it to start still. Here is the stack trace @ramya-rao-a

/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:10 Cannot read property 'startLineNumber' of null: TypeError: Cannot read property 'startLineNumber' of null
    at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:1011239
    at t._changeDecorations (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:951992)
    at t.changeDecorations (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:951213)
    at e.move (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:1011003)
    at e._move (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:1017225)
    at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:1016877
    at e.pushEditOperation (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:426645)
    at t._pushEditOperations (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:963461)
    at t.pushEditOperations (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:962458)
    at e.merge (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.main.js:9:1016691)

Hmm my copy didn't seem to get the whole message so here is a screenshot of the stack trace:
image

Hope it helps!

@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

@tnrich Interesting and I'd really like to know the steps leading up to that but this isn't the 'Illegal Arguments' error you have mentioned in the beginning. Is it that this error happens and that it also shows the error message in the UI?

@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

Drilling into this black hole... There is something off with nested snippets. I can tell that by the stack traces and I have seen this via error telemetry. It's just not clear to me how exactly that happens 😕

The 'Invalid arguments' error is, I believe, a side-effect of that. The snippet-logic wants to compute the next cursor positions, fails, and computes an empty array of selections. The editor will refuse to accept that and throw that error... (there are many other code paths leading to this but I take this as the most likely case).

@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

This is related (likely the same as) to #36330 and #36329

jrieken added a commit that referenced this issue Dec 7, 2017
@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

I have pushed a change that prevents the 'in-your-face-error' and that adds lots of logging, esp. it will write the snippets and merge attempting to a log-file. That is information we cannot automatically collect as telemetry...

@tnrich @Braincompiler This requires your help! When snippets, esp. snippets or IntelliSense inside another snippet, act weirdly check the error log (F1 > Show Logs... > Renderer) for line around snippet_error. Thanks and Happy Coding

@jrieken jrieken added this to the December 2017 milestone Dec 7, 2017
@jrieken jrieken changed the title Still hitting: "Invalid Argument" error when pressing tab randomly?" Problems with nested snippet insertion Dec 7, 2017
@james-woodbridge
Copy link

@jrieken I have noticed that my issue also occurs when using snippets - particulary one of my custom snippets? Would you like me to provide information here if I am able to reproduce, or would you prefer that I keep it to issue #1118 ?

@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

Sure this is #1118?

Yeah, maybe yours is the same... Initially I was not aware that the bad snippet behaviour can cause the 'Invalid arguments' error to pop up. Because of that I mentally put things into different bugs. Separate issue or not doesn't matter much at this point. What I need is repro-steps...

Is this plain snippets and completions or anything fancy like starting with multiple cursors?

@james-woodbridge
Copy link

My steps to easily reproduce are using the following custom snippet in powershell:

"Convert self to JSON":{
		"prefix": "Convert",
		"body": "$1 = ConvertTo-Json $1",
		"description": "One liner to convert a object into a JSON version of itself."
	},

As you can see it uses multiple cursors. Either this will cause the issue straight away, or the next time IntelliSense is used the issue occurs. If that enough info? If not I will happily try to get more, or bow out.

@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

@james-woodbridge I owe you a beer. I mean it, I am in London early next Feb.

I believe the culprit is changing the selection when inside a repeated placeholder and when invoking another snippets (nested insertion). Steps to reproduce this:

  • empty test.ps1 file
  • insert snippet from above
  • manually set selection (e.g. via mouse) to the end of that line
  • insert that snippet again
  • 💥

@jrieken jrieken modified the milestones: December 2017, November 2017 Dec 7, 2017
@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Dec 7, 2017
@jrieken jrieken closed this as completed in 1c13647 Dec 7, 2017
@jrieken
Copy link
Member

jrieken commented Dec 7, 2017

Pushed a fix, will be in next insiders build. Tricky, crazy issue... The snippet controller tracks the current selection while a snippet is being inserted and cancels snippet mode when the selection leaves a placeholder range. That logic was flawed and wouldn't cancel snippet mode when the selection changes from n to 1 while still being on a placeholder (see above staying on $1 but on just one of them). Subsequently, nested snippet insertion would explode because it relies on that behaviour...

@james-woodbridge
Copy link

@jrieken I will take you up on that beer - there are quite a few good pubs around here and it's always good to meet new people :)
Glad to hear you found the flawed logic around snippet mode, I look forward to the next insider's build!

@mjbvz mjbvz added the verified Verification succeeded label Dec 8, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 21, 2018
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 snippets verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants