Give us better syntax highlighting

Currently on the DevForum, syntax highlighting is poor, only compatible with Lua, and even then missing certain libraries.

Current syntax highlighting is not even compliant with Roblox’s Luau, no type checking acknowledgement, missing libraries like task, and others.

As you can see below,

local Node = {}
Node.__index = Node

type Node = {
    _value: any,
    _bindable: BindableEvent,
    Changed: RBXScriptSignal
}

function Node.new(value: any): Node
    local self = setmetatable({
        _value = value,
        _bindable = Instance.new("BindableEvent"),
        Changed = nil
    }, Node)

    self.Changed = self._bindable.Event

    return self
end

function Node:Set(value: any): Node
    if self._value ~= value then
        self._value = value
        self._bindable:Fire()
    end

    return self
end

function Node:Get(): any
    return self._value
end

function Node:Destroy()
    if self._bindable == nil then
        return
    end

    self._value = nil

    self._bindable:Destroy()
    self._bindable = nil
    self.Changed = nil
end

return Node

It’s pretty poor. The only reason for the keyword type to be highlighted at all is that there is a global function type, which is now usually replaced by typeof.
Can we talk about how after at least 2 years of being added, it still doesn’t have proper highlighting?

Anyhow, obviously as you can see the Lua part of syntax highlighting seriously need a revamp of sorts, to add compatibility to Luau’s new features.

But another thing to note is that AFAIK there is no support for any other language to highlight. Correct me if I’m wrong.

If this was to be added for anything else, one of my top picks would be json compatibility, as it is pretty used in a lot of areas inside and outside Roblox, and is also used for data stores.

Discord handles syntax highlighting similarly but not exactly like the forum, it instead, allows you to tell it what language is the code in that block for.

You can do this on Discord in these ways:

```lua
```json
```javascript
```python

This is a great way to do this! Infact, I already do this when making a code block on Discourse because I’m used to it. Normal blocks with no specified language would default to lua.


With all that said, this request can wait! But I do believe it’s mandatory for it to be adapted to Luau as soon as possible! Luau is expected to, and definitely has a lot of things still planned, apparently there were some talks here and there about OOP syntax sugar coming to Luau, such thing would have to be added to it’s syntax highlighting on the forum later, so such task is better off waiting until such thing is implemented first. But at some point, it has to come.

6 Likes
function myFunction(p1, p2) {
  return p1 * p2; // javascript comment
}
# python comment
def my_function():
  print("Hello from a function")

It works the exact same as Discord and many other sites where you can input code blocks in-line in Markdown.

If you don’t file a feature request, don’t expect changes. So to go “why has this still not been added” when this request has never been made before is overly dramatic.

Roblox would need to contribute Luau definitions to https://highlightjs.org/, or somehow override the Lua definitions with their own for Luau. Roblox didn’t implement the code highlighter here themselves, so this is not a trivial request.

11 Likes

This is way less far off now that Luau has their own dedicated .luau file type, would still mean that older code posted on the Forum as lua would just be default Lua, but it’s definitely an improvement to be able to get Luau syntax going.

This probably wouldn’t include Roblox-only globals however, since Luau is also now independent. Don’t know if such an contribution could include something like that as robloxluau or not, but doesn’t matter, most of my complains are really just with types which such implementation would solve just fine. It would also include Luau only library functions like coroutine.close, etc.

1 Like