diff --git a/packages/locales/src/locales/en.json b/packages/locales/src/locales/en.json index af50b9a07..27a4c9484 100644 --- a/packages/locales/src/locales/en.json +++ b/packages/locales/src/locales/en.json @@ -8,6 +8,7 @@ "code-action.fix-workspace": "Fix all auto-fixable problems in the workspace", "code-action.id-attribute-datafix": "Update this attribute name to 1.16", "code-action.add-default-namespace": "Add default namespace", + "code-action.add-leading-slash": "Add leading slash", "code-action.create-undeclared-file": "Create %0% %1% in the same pack", "code-action.id-omit-default-namespace": "Omit default namespace", "code-action.id-zombified-piglin-datafix": "Change this ID to Zombified Piglin's", @@ -19,6 +20,7 @@ "code-action.nbt-type-to-long": "Convert to an NBT long tag", "code-action.nbt-type-to-short": "Convert to an NBT short tag", "code-action.nbt-uuid-datafix": "Update this UUID to 1.16", + "code-action.remove-leading-slash": "Remove leading slash", "code-action.remove-trailing-separation": "Remove trailing separation", "code-action.selector-sort-keys": "Sort selector argument", "code-action.string-double-quote": "Quote this string with double quotation marks", diff --git a/packages/mcfunction/src/parser/command.ts b/packages/mcfunction/src/parser/command.ts index 989f47402..43d7caa5e 100644 --- a/packages/mcfunction/src/parser/command.ts +++ b/packages/mcfunction/src/parser/command.ts @@ -36,12 +36,43 @@ export function command( if (src.trySkip('/')) { ans.slash = core.Range.create(start, src.cursor) if (!options.slash) { - ctx.err.report(localize('mcfunction.parser.leading-slash.unexpected'), ans.slash) + ctx.err.report( + localize('mcfunction.parser.leading-slash.unexpected'), + ans.slash, + core.ErrorSeverity.Error, + { + codeAction: { + title: localize('code-action.remove-leading-slash'), + isPreferred: true, + changes: [ + { + type: 'edit', + range: ans.slash, + text: '', + }, + ], + }, + }, + ) } } else if (options.slash === 'required') { ctx.err.report( localize('expected', localize('mcfunction.parser.leading-slash')), core.Range.create(start, start + 1), + core.ErrorSeverity.Error, + { + codeAction: { + title: localize('code-action.add-leading-slash'), + isPreferred: true, + changes: [ + { + type: 'edit', + range: core.Range.create(start), + text: '/', + }, + ], + }, + }, ) }