Skip to content

Commit

Permalink
Add quick fix to remove or add leading command slash
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Dec 30, 2024
1 parent 6350cde commit a5c7bca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/locales/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
33 changes: 32 additions & 1 deletion packages/mcfunction/src/parser/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '/',
},
],
},
},
)
}

Expand Down

0 comments on commit a5c7bca

Please sign in to comment.