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

Settings writer looses comments #29453

Closed
dbaeumer opened this issue Jun 26, 2017 · 12 comments
Closed

Settings writer looses comments #29453

dbaeumer opened this issue Jun 26, 2017 · 12 comments
Assignees
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code

Comments

@dbaeumer
Copy link
Member

Have a setting defined that is an array of literal (an example is the tasks.json with the tasks property). Try to update the array using the settings API with comments used for elements inside the array or on elements in the array.

Observe: comments are lost

tasks.json

{
	// See https://go.microsoft.com/fwlink/?LinkId=733558
	// for the documentation about the tasks.json format
	"version": "2.0.0",
	"tasks": [
		{
			// a comment
			"type": "gulp",
			"task": "build",
			"problemMatcher": [
				"$tsc"
			]
		}
	]
}

configure a second task using the configuration UI (the gear icon in the task quick open). You get:

{
	// See https://go.microsoft.com/fwlink/?LinkId=733558
	// for the documentation about the tasks.json format
	"version": "2.0.0",
	"tasks": [
		{
			"type": "gulp",
			"task": "build",
			"problemMatcher": [
				"$tsc"
			]
		},
		{
			"type": "gulp",
			"task": "watch",
			"problemMatcher": []
		}
	]
}

I couldn't find a way to preserve the comment.

@vscodebot vscodebot bot added bug Issue identified by VS Code Team member as probable bug tasks Task system issues labels Jun 26, 2017
@dbaeumer dbaeumer added settings-editor VS Code settings editor issues and removed tasks Task system issues labels Jun 26, 2017
@sandy081
Copy link
Member

@dbaeumer IConfigurationService.updateValue always replace the existing value with the given value. There is no smartness involved in it and I guess that smartness is not necessary for normal configurations.

Tasks to me looks like a special case. From configuration service perspective key is tasks and value is the complete tasks object. It does not know the semantics of the value object. Hence coming up with smartness is tough.

My suggestion is to directly write into the file by computing the edits using jsonEdit. This will allow you to do small edits like inserting just a single task.

It's also worth referring to jsonEditing.

@sandy081 sandy081 added info-needed Issue requires more information from poster and removed bug Issue identified by VS Code Team member as probable bug labels Nov 15, 2017
@dbaeumer
Copy link
Member Author

@sandy081 I have to say I disagree here. That would mean you limit the configuration to single values only. Even in a settings file I can easily define a setting that has an array of values which would be writable via our API and loose comments. So instead of me fixing this in Task land we should fix this in settings land. I agree that this is not easy but it is not easy on both sides :-)

@dbaeumer
Copy link
Member Author

Just to clarify: in the given case I am not updating the while task settings. I am updating the tasks array. But there is no way for me to add, remove, ... elements from the array. I can only replace it.

@sandy081
Copy link
Member

sandy081 commented Nov 17, 2017

@dbaeumer I would say in Settings file most common way to comment is per setting. Commenting a sub portion of the value is very rare. Hence comments are retrieved while updating settings. Tasks from Configuration perspective, is just a single object with out any semantics known. But it is much more than that when you see Tasks as a feature.

Configuration writing API is simple and straight, update the existing value with given value for the given key. It does not mention about updating the sub section of the value which I think is your use case.

What I am saying is if your requirement is that you are programmatically adding a task to existing tasks, I would suggest to take a different route (as mentioned here) than using configuration service. It is not aligned with how it has to be used.

Since, this case which is very rare from Settings point of view, I am closing this.

@dbaeumer
Copy link
Member Author

@sandy081 and I discussed this via Slack and I am reopening this for now. Will discuss how to continue on this face 2 face.

Just for the record: Using arrays in configs is not so uncommon. Examples are: tslint.rulesDirectory, tslint.exclude, tslint.autoFixOnSave. ESLint uses arrays as well.

@dbaeumer dbaeumer reopened this Nov 20, 2017
@vscodebot vscodebot bot closed this as completed Nov 30, 2017
@vscodebot
Copy link

vscodebot bot commented Nov 30, 2017

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@sandy081 sandy081 added under-discussion Issue is under discussion for relevance, priority, approach and removed info-needed Issue requires more information from poster labels Dec 3, 2017
@sandy081 sandy081 reopened this Dec 3, 2017
@dbaeumer
Copy link
Member Author

dbaeumer commented Dec 4, 2017

@sandy081 thanks for reopening. Lets discuss this week. I have an idea how this could work . Basically we can use a path syntax that allows addressing array elements. Something like tasks.[2].label. That should not be so different than tasks.xxx.label

@dcharkes
Copy link

I've also ran into #37138. Any progress?

@sandy081 sandy081 added bug Issue identified by VS Code Team member as probable bug config VS Code configuration, set up issues and removed under-discussion Issue is under discussion for relevance, priority, approach settings-editor VS Code settings editor issues labels Jun 4, 2020
@sandy081 sandy081 added this to the Backlog milestone Jun 4, 2020
@sandy081 sandy081 removed the bug Issue identified by VS Code Team member as probable bug label Nov 2, 2020
@weinand
Copy link
Contributor

weinand commented Nov 10, 2020

@sandy081 Loosing comments is a "user data loss" that we must avoid.
We need to fix this.

@Tarang74
Copy link

Any progress on this issue?

@arsu-leo
Copy link

arsu-leo commented Feb 11, 2022

I would suggest to just create a field named "description" with string content. This way the writter will write it down as it reads it, you get a warning about a non allowed property but it's non breaking

@VSCodeTriageBot
Copy link
Collaborator

We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding, and happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config VS Code configuration, set up issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

9 participants