Fix VSCode tasks.json parsing for tasks without explicit labels#47754
Conversation
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you, this looks good but #47749 mentions more cases that this PR does not implement.
Yet, in the documentation link I see no such rules too, so quite confused: should we actually do what's proposed in the issue, what's in the PR, something else?
Can we have a link to the docs/sources with these rules?
Lastly, we want to test more conversion cases for coverage, even at the current PR's state.
33a190d to
db18600
Compare
|
Thanks for the feedback!
The issue mentions grunt and typescript task types, but these aren't currently supported by Zed's parser. Adding label generation for them would require first implementing full parsing support. Here's what Zed currently handles: enum Command {
Npm {
script: String,
},
Shell {
command: String,
#[serde(default)]
args: Vec<String>,
},
Gulp {
task: String,
},
}
Sure! Here's where VSCode implements this: The core logic is in taskConfiguration.ts lines 1533-1547: if (result.configurationProperties.name) {
result._label = result.configurationProperties.name;
} else {
let label = result.configures.type;
if (typeDeclaration.required && typeDeclaration.required.length > 0) {
for (const required of typeDeclaration.required) {
const value = result.configures[required];
if (value) {
label = label + ': ' + value;
break;
}
}
}
result._label = label;
}Basically: if there's no label field, VSCode takes the task type and appends the first required property value. The task type definitions show what's required: https://github.com/microsoft/vscode/blob/main/extensions/npm/package.json#L344-L360 if (!taskName) {
context.problemReporter.error(nls.localize('ConfigurationParser.noTaskName',
'Error: a task must provide a label property. The task will be ignored.\n{0}\n',
JSON.stringify(external, null, 4)));
return undefined;
}This brings up the shell task question - the PR currently generates labels for shell tasks (using the first word of the command), but VSCode actually errors on these. We have a few options:
I'd lean toward option 2 since it's more user-friendly and Zed already diverges from VSCode on which task types are supported. But what's your preference?
Done! I refactored the label generation into a standalone generate_label() function that can be tested independently. |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you for sharing the context.
Seems reasonable to keep things as they are then, one last concern about the shell command:
is it really ok to keep just the first word of the command?
I imagine there could be multiple echo or cargo or npm or whatnot and we'll have a conflict — instead, does it make sense to have the entire command as a label?
Implements automatic label generation for VSCode tasks that don't have
explicit 'label' fields, matching VSCode's behavior.
Changes:
- Made label field optional in VsCodeTaskDefinition deserialization
- Implemented custom deserializer to auto-generate labels:
- npm tasks: 'npm: {script}' (e.g., 'npm: start')
- shell tasks: first word of command (e.g., 'echo')
- gulp tasks: 'gulp: {task}' (e.g., 'gulp: build')
- fallback: 'Untitled Task'
- Added test data file with tasks without labels
- Added comprehensive test cases
Closes zed-industries#47749
Release Notes:
- Fixed: VSCode tasks.json files with tasks missing explicit `label`
fields now parse correctly. Labels are auto-generated matching
VSCode's behavior (e.g., "npm: start").
db18600 to
1bd4a6c
Compare
Good catch, improved it the way you suggested. Did a quick check what zed does with very long labels. No issue as far as I can see. |
Auto-applied queued documentation suggestions from: - PR #48908 - PR #48909 - PR #48910 - PR #48912 - PR #48930 - PR #44794 - PR #48763 - PR #45073 - PR #48495 - PR #49374 - PR #49139 - PR #48780 - PR #48619 - PR #48978 - PR #48962 - PR #48988 - PR #47860 - PR #49015 - PR #47095 - PR #47475 - PR #48542 - PR #46766 - PR #47754 - PR #48807 - PR #44506 - PR #49051 - PR #49069 - PR #48842 - PR #48851 - PR #48736 - PR #47673 - PR #49094 - PR #49098 - PR #49622 Generated with script/docs-suggest-publish for human review in draft PR.
Auto-applied queued documentation suggestions from: - PR #48908 - PR #48909 - PR #48910 - PR #48912 - PR #48930 - PR #44794 - PR #48763 - PR #45073 - PR #48495 - PR #49374 - PR #49139 - PR #48780 - PR #48619 - PR #48978 - PR #48962 - PR #48988 - PR #47860 - PR #49015 - PR #47095 - PR #47475 - PR #48542 - PR #46766 - PR #47754 - PR #48807 - PR #44506 - PR #49051 - PR #49069 - PR #48842 - PR #48851 - PR #48736 - PR #47673 - PR #49094 - PR #49098 - PR #49622 - PR #49554 - PR #49710 - PR #49716 - PR #49732 - PR #49788 - PR #49876 - PR #49902 - PR #49910 - PR #49390 - PR #50027 Generated with script/docs-suggest-publish for human review in draft PR.
Auto-applied documentation from: - PR #48542: Bedrock extended context window - PR #46766: LSP adapters in settings schema - PR #47754: VSCode tasks.json label generation Skipped (no target file exists): - PR #49069: panel zoom state persistence Already documented from prior batches: - PR #48807, PR #44506, PR #49051, PR #48842, PR #48851, PR #48736
Auto-applied queued documentation suggestions from: - PR #48908 - PR #48909 - PR #48910 - PR #48912 - PR #48930 - PR #44794 - PR #48763 - PR #45073 - PR #48495 - PR #49374 - PR #49139 - PR #48780 - PR #48619 - PR #48978 - PR #48962 - PR #48988 - PR #47860 - PR #49015 - PR #47095 - PR #47475 - PR #48542 - PR #46766 - PR #47754 - PR #48807 - PR #44506 - PR #49051 - PR #49069 - PR #48842 - PR #48851 - PR #48736 - PR #47673 - PR #49094 - PR #49098 - PR #49622 - PR #49554 - PR #49710 - PR #49716 - PR #49732 - PR #49788 - PR #49876 - PR #49902 - PR #49910 - PR #49390 - PR #50027 Generated with script/docs-suggest-publish for human review in draft PR.
Auto-applied documentation from: - PR #48542: Bedrock extended context window - PR #46766: LSP adapters in settings schema - PR #47754: VSCode tasks.json label generation Skipped (no target file exists): - PR #49069: panel zoom state persistence Already documented from prior batches: - PR #48807, PR #44506, PR #49051, PR #48842, PR #48851, PR #48736
Implements automatic label generation for VSCode tasks that don't have explicit 'label' fields, matching VSCode's behavior.
Changes:
Closes #47749
Release Notes:
labelfields now parse correctly. Labels are auto-generated matching VSCode's behavior (e.g., "npm: start").