Code Monkey home page Code Monkey logo

language-mcfunction's Introduction

language-mcfunction

Language grammars and syntax highlighting for mcfunction files.

github-license-badge vscode-version-badge discord-chat-badge

This project provides two types of grammars: the default, version-agnostic grammar (shown below), and WIP version-specific grammars.

Showcase

Install

Installing the VSCode extension

The extension language-mcfunction is available from the Marketplace: https://marketplace.visualstudio.com/items?itemName=arcensoth.language-mcfunction

Installing the SublimeText package

It is recommended you use Package Control to manage the package:

  1. Install Package Control if it is not already present.
  2. Run the Package Control: Add Repository command and enter https://github.com/Arcensoth/language-mcfunction to add the repository as a package.
  3. Run the Package Control: Install Package and search for language-mcfunction to install it as you would a normal package.

This will keep the package updated with the repository automatically.

Otherwise you can clone the repository into user packages (e.g. %appdata%\Sublime Text 3\Packages) and update it manually.

Features

Syntax highlighting

Here's an album with everything below.

Custom block comments

It's common for datapack developers to comment parts of their code with things like headings, parameters, return values, etc. To support these patterns for those who wish to use them, the grammar implements custom block comments. These types of comments are gated behind a vanilla-compatible alternate comment style.

The prefix #> can be used to initiate a block comment:

#> This is a block heading
# All adjacent comments will be considered part of the block.
#
# So long as you keep comments attached, they will remain part of the block.

# This line no longer attached to the block.

#> But we can start a new block here!

Click here for a detailed example.

As of writing there is no documentation standard, however the grammar has the capacity to support this via block comments and alternate comment styles.

Configure

Configuring the version-agnostic grammar

This is a generic "version-agnostic" grammar that does not target any particular version of Minecraft. As a result it may not be as accurate as version-specific grammars, however it will continue to work for multiple versions of the game.

The version-agnostic mcfunction language should be active by default. It provides a decent fallback for otherwise unsupported versions of Minecraft. In order to do this, it must not assume any particular version. Because it cannot assume a version, it cannot provide context-sensitive highlighting.

In the future, the version-specific grammars will be preferred when available.

Configuring the version-specific grammars

The version-specific grammars are currently under heavy development. These grammars are incomplete and experimental. They do not yet support the same feature set as the version-agnostic grammar. Please only use these grammars if you intend to contribute in some form, such as pull requests, bug reports, or general feedback. To use the version-specific grammars, you will need to build them and configure the extension yourself.

The version-specific grammars are partially generated based on Minecraft's generated data, which is available for Minecraft versions 1.13 and higher. They have context-sensitive highlighting and command validation comparable to the in-game command bar.

In VSCode, you can easily choose which version of mcfunction to use by changing the .mcfunction extension association in your workspace settings:

"files.associations": {
  "*.mcfunction": "mcfunction-snapshot"
}

This option can also be set on the user-level in settings.json or folder-level in .vscode/settings.json.

Customize

Currently available for the version-specific grammars.

Scopes have been assigned with user customization in mind. If your editor allows scope overrides, this will make it easy to customize your own colours for a variety of scopes.

Customizing errors

Short name Full scope name Examples
invalid invalid.illegal._.invalid.mcfunction execute (foo)
underline markup.underline._.underline.mcfunction execute (foo)

Customizing comments

Short name Full scope name Examples
comment.plain comment._.plain.comment.mcfunction (# This is a plain comment)
comment.block comment.block._.block.comment.mcfunction (#> This is part of a block comment)
comment.block.symbol markup.list._.symbol.block.comment.mcfunction (#)> This is part of a block comment
comment.block.prefix markup.list._.prefix.block.comment.mcfunction #(>) This is part of a block comment
comment.block.heading_1 markup.bold._.heading_1.block.comment.mcfunction #> (This is part of a block comment)
comment.block.heading_2 markup.list._.heading_2.block.comment.mcfunction #> (This is part of a block comment)
comment.block.annotation.label markup.heading._.label.annotation.block.comment.mcfunction #> (@annotation) some annotation
comment.block.annotation.text comment.block._.text.annotation.block.comment.mcfunction #> @annotation (some annotation)

Customizing commands

Short name Full scope name Examples
command keyword.control._.command.mcfunction (execute) as @a run (function)
subcommand keyword.other._.subcommand.mcfunction execute (as) @a (run) function
command.slash keyword.control._.command.mcfunction /

Customizing selectors

Short name Full scope name Examples
target_selector.base support.class._.base.target_selector.mcfunction @a
target_selector.bracket support.class._.bracket.target_selector.mcfunction []
target_selector.equals support.class._.equals.target_selector.mcfunction =
target_selector.comma support.class._.comma.target_selector.mcfunction ,
target_selector.not constant.character.escape._.not.target_selector.mcfunction !
target_selector.param keyword.other._.param.target_selector.mcfunction tag / type
score_map.bracket storage._.bracket.score_map.mcfunction {}
score_map.equals storage._.equals.score_map.mcfunction =
score_map.comma storage._.comma.score_map.mcfunction ,
advancement_map.bracket storage._.bracket.advancement_map.mcfunction {}
advancement_map.equals storage._.equals.advancement_map.mcfunction =
advancement_map.comma storage._.comma.advancement_map.mcfunction ,

Customizing NBT

Short name Full scope name Examples
nbt_compound.bracket storage._.bracket.nbt_compound.mcfunction {}
nbt_compound.colon storage._.colon.nbt_compound.mcfunction :
nbt_compound.comma storage._.comma.nbt_compound.mcfunction ,
nbt_list.bracket storage._.bracket.nbt_list.mcfunction []
nbt_list.comma storage._.comma.nbt_list.mcfunction ,

Customizing NBT paths

Short name Full scope name Examples
nbt_path.property string._.property.nbt_path.mcfunction (RecordItem)
nbt_path.dot storage._.dot.nbt_path.mcfunction RecordItem(.)tag
nbt_path.compound.bracket storage._.bracket.compound.nbt_path.mcfunction SelectedItem({)(})
nbt_path.index.bracket storage._.bracket.index.nbt_path.mcfunction Inventory([)(])

Customizing text components

Short name Full scope name Examples
text_component.bracket storage._.bracket.text_component.mcfunction {}[]
text_component.colon storage._.colon.text_component.mcfunction :
text_component.comma storage._.comma.text_component.mcfunction ,
text_component.property string._.property.text_component.mcfunction text / color / selector
text_component.property.color string._.color.property.text_component.mcfunction red / green / blue
text_component.property.keybind string._.keybind.property.text_component.mcfunction key.drop / key.use
text_component.property.event string._.event.property.text_component.mcfunction run_command / show_text

Customizing resource locations

Short name Full scope name Examples
resource_location.namespace entity.name.function._.namespace.resource_location.mcfunction (mypack):some/resource
resource_location.colon entity.name.function._.colon.resource_location.mcfunction mypack(:)some/resource
resource_location.path entity.name.function._.path.resource_location.mcfunction mypack:(some/resource)
tagged_resource_location.hash entity.name.function._.hash.tagged_resource_location.mcfunction (#)mypack:some/resource
tagged_resource_location.namespace entity.name.function._.namespace.tagged_resource_location.mcfunction #(mypack):some/resource
tagged_resource_location.colon entity.name.function._.colon.tagged_resource_location.mcfunction #mypack(:)some/resource
tagged_resource_location.path entity.name.function._.path.tagged_resource_location.mcfunction #mypack:(some/resource)

Customizing strings

Short name Full scope name Examples
string string._.string.mcfunction ("hello world")
string_escape constant.character.escape._.string_escape.mcfunction "hello(\n)newline"
word string._.word.mcfunction foo / foo_bar
keyword keyword._.word.mcfunction nearest / creative

Customizing numbers

Short name Full scope name Examples
number constant.numeric._.number.mcfunction 0 / 123 / -99
range.minimum constant.numeric._.minimum.range.mcfunction (10)..20
range.maximum constant.numeric._.maximum.range.mcfunction 10..(20)
range.ellipsis keyword.control._.ellipsis.range.mcfunction 10(..)20
position.absolute.number constant.numeric._.number.absolute.position.mcfunction (10) ~20 (30)
position.relative.operator keyword.control._.operator.relative.position.mcfunction 10 (~)20 30
position.relative.number constant.numeric._.number.relative.position.mcfunction 10 ~(20) 30
position.local.operator keyword.control._.operator.local.position.mcfunction (^)10 (^)20 (^)30
position.local.number constant.numeric._.number.local.position.mcfunction ^(10) ^(20) ^(30)

Customizing tags, teams, and objectives

Short name Full scope name Examples
entity_tag entity.other.attribute-name._.entity_tag.mcfunction mypack.some.tag
scoreboard_team entity.other.attribute-name._.scoreboard_team.mcfunction mypack.blue
scoreboard_objective entity.other.attribute-name._.scoreboard_objective.mcfunction mypack.points
score_holder.all support.class._.all.score_holder.mcfunction *
score_holder.fakeplayer support.class._.fakeplayer.score_holder.mcfunction #temp / $mypack.calc

Other customizable scopes

Short name Full scope name Examples
boolean constant.numeric._.boolean.mcfunction true / false
entity_anchor constant.numeric._.entity_anchor.mcfunction eyes / feet
swizzle constant.numeric._.swizzle.mcfunction y / xz / xyz
target.uuid support.class._.uuid.target.mcfunction f7a39418-72ca-4bf2-bc7e-ba9df67a4707 / 0-0-0-0-0
target.player_name support.class._.uuid.target.mcfunction Arcensoth / some_guy
generic.dict.bracket storage._.bracket.dict.generic.mcfunction ({) key: value (})
generic.dict.content string._.content.dict.generic.mcfunction {( key: value )}
generic.list.bracket storage._.bracket.list.generic.mcfunction ([) item, item (])
generic.list.content string._.content.list.generic.mcfunction [( item, item )]

Contribute

Contributions are welcome; see CONTRIBUTING.md.

Resources

language-mcfunction's People

Contributors

arcensoth avatar luexa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

language-mcfunction's Issues

Bedrock functions may start with "HIDE"

Bug report checklist

  • The language-mcfunction extension only provides syntax highlighting. Have you confirmed that your issue is with the syntax highlighting, and not other features such as squiggly underlines, warning indicators, and/or pop-ups?
  • Ensure that you are able to reproduce the issue without any other datapack-related extensions enabled.
  • Make sure you attach a screenshot to your bug report. Bug reports without a screenshot will be closed.

Description

From the MC wiki page for Bedrock functions:

If the first line of the function is HIDE (excluding any commented lines), then the function is not visible in the suggestions for the function command, but can still be called by typing the command manually.

However, syntax highlighting marks "HIDE" on the first line as invalid:

image

Only the second line should be marked invalid.

I have tested this feature in-game and the keyword does indeed work.

New Item command for 1.17

Can the new item command in version 1.17 be supported by the extension? Because right now it's constantly giving me errors... TY
Love the extension btw!

Question

Can I we change the syntax color ?
Cuz mine is almost similar to the normal text.
Not like those pictures u have upload

Remove explicit error highlighting

Removing the explicit "in-your-face" error highlighting should be considered for a variety of reasons:

  1. Confusion: it has resulted in several bug reports, often regarding uncommon/obscure but valid syntax.
  2. Inconsistency: the grammar is broad yet inaccurate, and there are plenty of errors that are not being highlighted.
  3. Conflict: avoiding conflict with third-party formats that extend the vanilla mcfunction syntax is considered a bonus.

The alternative approach is to skip over violating syntax and leave it unclassified. Doing this may also fix the long-standing issue #32 with line endings, as well as #42 in that extraneous trailing characters will simply be skipped and not highlighted as an error.

Summary of issues discovered with GitHub Linguist release

The grammar module employed by linguist might simply be out-of-date, in which case some issues may be resolved upon the next release of linguist.

Highlight entity tags the same in all places

Entity tags (via /tag) appear in three different places:

  1. /tag command
  2. Tags: [] NBT
  3. tag= selector argument

Being able to highlight tags consistently in all of these places would be useful to quickly locate them.

This would be relatively easy to implement, however would require several hard-coded exceptions.

No syntax highlighting without (#)minecraft:xxxx

Screenshot 15-12-2019 à 13h06m59s
This issue is also valid for the entities (eg: /summon creeper instead of /summon minecraft:creeper)

And if I am not mistaken, the tags are not supposed to be a different color than the blocks?

Generalizing the custom block comment syntax `#>`

The custom block comment syntax introduced by language-mcfunction was inspired by my own usage; the same usage that eventually lead to the documentation format IMP-Doc.

Those involved with IMP-Doc have discussed additional comment prefixes (specifically for IMP-Doc) to denote different types of directives, because the existing block comment syntax #> is limited but has resulted in a variety of use-cases.

Now, as far as I'm concerned, IMP-Doc is its own independent project and has no influence over language-mcfunction's default (GitHub) grammar. However, the issue raised by IMP-Doc begs the question: could language-mcfunction benefit from a similar change?

I think it's important to keep the base language-mcfunction grammar separate from and uninfluenced by IMP-Doc, because the way GitHub highlights comments should not be influenced by (what is effectively) an arbitrary third-party documentation format.

However, it could be argued that language-mcfunction's block comment syntax #> was based on an equally arbitrary decision. Perhaps it should have never been added and should be removed in a future update, to eliminate any possible confusion. This is a fair argument.

That being said, I think it's also fair to argue that block comment syntax #> should be kept simply because of how useful it's proven itself in practice. Moreover; perhaps it's also fair to argue that this syntax should be generalized, to reduce the impact of the initial (arbitrary) decision to choose > as the trigger character.


In short: I'd like to generalize the custom block comment syntax #> by extending the set of trigger characters. This would widen the pool of possible options for users as well as third-party formats/tools. For example: instead of just using > to initiate a block comment, make it so that any special character out of, say, ~!@$%^*, or even \W (any non-word character), does the same thing.

Any thoughts/comments/concerns are appreciated.

Commands Showing as Red

Is your feature request related to a problem? Please describe.
When using any key words as effect, execute, and tellraw. It is all fine but the text after those are all bright red and underlined.

Describe the solution you'd like
The give, me, kill, summon, gamerule, setspawn, setworldspawn, and spawn commands are all bright red.
These being red make it seem like the command is not right. Another nice feature would be to just look for those key words and assume that the command following it is correct and not red as well.

setworldspawn.mcfunction: setworldspawn
setspawn.mcfunction: spawnpoint @p ~ ~ ~
home.mcfunction: gamerule keepinventory true execute at @s run kill @s gamerule keepinventory false
heal.mcfunction: effect @p instant_health 10 10 true effect @e instant_health 10 10 true effect @p[r=1,c=1] saturation 10 10 true effect @e[r=1,c=1] saturation 10 10 true
dragon_summon.mcfunction: summon ender_dragon
dragon_kill.mcfunction: kill @e[type=ender_dragon]
diamond_tools.mcfunction: give @s diamond_sword give @s diamond_shovel give @s diamond_pickaxe give @s diamond_axe me Has been given §bDiamond Tools§r. tellraw @s{"rawtext":[{"text":"This is:\n/tellraw"}]}

Fakeplayers incorrectly invalid with `.` and `+`

Bug report checklist:
[x] The language-mcfunction extension only provides syntax highlighting. Have you confirmed that your issue is with the syntax highlighting, and not other features such as squiggly underlines, warning indicators, and/or pop-ups?
[x] Ensure that you are able to reproduce the issue without any other datapack-related extensions enabled.
[x] Make sure you attach a screenshot to your bug report. Bug reports without a screenshot will be closed.

Describe the bug:
image
In this image, the fakeplayer, rx.EnderChest+ is marked as invalid when this is a completely valid fakeplayer name.
I've tested w/ DHP off and on, this seems like a syntax related issue

Confusion involving comment styling

Several people have reported the highlighter "breaking" in comments under certain conditions.

It has become apparent that this confusion is being caused by the stylistic overrides used to support built-in TODO and @annotation and ## Heading within the language grammar.

image

There are several solutions to this problem, but the likely outcome is that no additional styling will be applied within comments unless directed to do so, such as with a community-declared comment prefix (e.g. ## or #> ).

TODO support will be removed entirely in favour of specialized editor/IDE tools.

Comment directives such as headings/separators and annotations will be support via a TBD community-declared standard comment prefix.

Submit package to PackageControl

Having the package hosted on the central PackageControl repository will make it easier for people to install the package with SublimeText.

Submitting a bug report? Read me first!

The language-mcfunction extension only provides syntax highlighting. Before reporting a bug, confirm that your issue is with the syntax highlighting, and not other features such as squiggly underlines, warning indicators, and/or pop-ups.

For example, the following is not an issue with language-mcfunction:

image

You can tell by the squiggly yellow line and the pop-up box that this is an issue with another extension, such as Datapack Helper Plus. If this is indeed an issue with DHP you can report the issue over on that repository, but make sure you check that the issue has not already been reported or even resolved in a development version.

If you think you've found an issue with language-mcfuntion syntax highlighting specifically:

  1. Ensure that you are able to reproduce the issue without any other datapack-related extensions enabled.
  2. Make sure you attach a screenshot to your bug report. Bug reports without a screenshot will be closed.

Inconsistant Color Highlighting with scores

So I have been using this for a while (on mac, if that matters), and I noticed that highlighting score names is quite inconsistant. So things like score names in commands like
execute as @a[scores={test=1}] will highlight the score called test correctly
but then in things such as execute if score global test matches 1 then It will not color the fake player or the score.

This score highlighting issue is also present in the /scoreboard command aswell.

Player names in specific like my user name, Anime_Watcher2, or Animewatcher2, will not get highlighted either.

Screen Shot 2021-07-02 at 8 00 36 PM
Screen Shot 2021-07-02 at 8 00 11 PM
Screen Shot 2021-07-02 at 7 55 05 PM
Screen Shot 2021-07-02 at 8 01 21 PM

Edit for another thing:
Quotes are not properly highlighted in color either
Screen Shot 2021-07-02 at 8 03 34 PM

Auto-Complete

Add support for auto-complete with IDs, commands, etc. similar to how Minecraft has suggestions.

Handling greedy strings in the version-agnostic grammar

Consolidating #23 and #24 into one report. Also acts as a reference point for any future related issues.

Here are some visuals:
image
image
image

Here are my comments from #24:

This is related to #23 in that, without context of the command, it is difficult to know whether these are selectors or just garbled strings.

Additional rambling follows...

I don't immediately see a solution that highlights adjacent selectors, because this type of syntax isn't actually allowed anywhere. As far as the in-game command parser is concerned, what follows say is just a greedy all-consuming string. But of course without context it's impossible to know that we are within a say command in the first place.

One work-around would be stop these tokens from being highlighted as an error simply by providing a fallback that captures any type of whitespace-delimited string of characters. The problem with this solution is that it would leave us without the error highlighting for every place we're using real selector arguments.

Another work-around is to add a hard-coded case for say (or any command that uses a greedy string), but given that this is a version-agnostic grammar it's a last resort at best. I already do this for execute run and I still feel dirty for it to this day. But considering that most of these bugs are with commands that use greedy strings, this might just be the solution I go with.

Solution is TBD.

[Request] Add submission guidelines

Having submission guidelines would help people wanting to contribute (like me).

It could recap:

  • What important files do, to have an idea of which files should be changed to add a functionality / fix a bug
  • What commands are used to compile files (if needed)
  • Any additional tips from the main contributor (you)

This project is very interesting, and I'd like to help with my free time. Having guidelines would help me a lot to contribute!

Windows-style line endings are sometimes highlighted as errors

This issue became apparent in #16 but was deferred until more information was available.

Here are the relevant details from the discussion in that report:

At some point - probably as a side-effect of an earlier fix - I must have fixed the trailing arguments being highlighted as errors, but the ^M is a slightly different red and I don't think it's a problem with the syntax highlighter. Here's some research:

It looks like people might be committing files with CRLF and then GitHub decides to force-highlight the carriage returns.

We'll see how the next Linguist update handles the affected files and re-open if it's clear there's more to be done here.

An update, for posterity:

GitHub Linguist has been updated, and is now running v0.13.0 of language-mcfunction.

As expected, the trailing arguments are being highlighted properly but the ^M characters remain:

https://github.com/Gamemode4Dev/GM4_Datapacks/blob/master/gm4_phantom_scarecrows/data/phantom_scarecrows/functions/main.mcfunction#L2

Like I mentioned in my last comment, I'm not confident that this is a problem with the grammar itself but instead that people are committing carriage returns to mcfunction files. It may be the grammar's fault that these characters are being highlighted, but after some testing (via github-lightshow) I was unable to remove these characters by any means.

Until I have more definitive information about the problem and/or people reporting it, I'm going to work under the assumption that this is out of the grammar's control.

I'm still unsure exactly what's causing this problem, but it any case it can probably be fixed with some effort.

Hex Colors marked as problem in tellraw command

I'm sure this is already known about and is going to be fixed in an update, but in case it isn't..

Tellraw now supports custom hex colors in its NBT. However, using it results in a problem although it's valid.
image

Finding Language Specific Grammer is like trying to navigate a maze

I have been using this for a while (in sublime) and honestly its amazing, however I am trying to switch to the version specific instead of the version agnostic.
Little did I know that I would spend 2 hours looking though the files and online trying to figure out where/how I can do this.
There are files about customization, but they dont tell you how to enable the version specific in the first place.
So if possible, I request that is made more clear where you switch between the version specific, and version agnostic.

Edit: I still have no idea how to go to/enable the version specific grammar.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.