rokucommunity / brighterscript

A superset of Roku's BrightScript language
MIT License
152 stars 47 forks source link

Validation of CDATA script methods inside XML #318

Open darktasevski opened 3 years ago

darktasevski commented 3 years ago

Currently, I have a few components that don't have their own dedicated brs files, but a small CDATA script:

<?xml version="1.0" encoding="UTF-8"?>
<component name="TestComponent" extends="ContentNode" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">
    <interface>
        <function name="testFunction" />
    </interface>

    <script type="text/brightscript">
        <![CDATA[
            function testFunction()
                print "this is a test"
            end function
        ]]>
    </script>
</component>

This is causing validation errors:

Cannot find function with name 'testFunction' in component scope

I'm also not aware of any way to disable bsc validation inside XML files.

It would be great if disabling validation for some XML line is enabled, and if CDATA function detection is working correctly. Thanks.

TwitchBronBron commented 3 years ago

Unfortunately we don't currently support CDATA scripts. You do bring up a good point that there is no way to disable a bsc diagnostic per-line in xml files. I created #325 to track this specific feature.

If you want to completely disable diagnostics for xml files, you could do this in your bsconfig file:

{
    "diagnosticFilters": [
        "components/**/*.xml"
     ]
}

Or, if you only wanted to disable that specific error in xml files, you could do this

{
    "diagnosticFilters": [{
         "src": "components/**/*.xml",
         "codes": [1067]
     }]
}
TwitchBronBron commented 3 years ago

Also, just to set expectations, CDATA support is pretty low on our priority list since there's a simple CDATA workaround: move the code to a script file instead.

Now, we'd always be open to accepting a pull request if you're interested in trying to implement CDATA support, but I expect it to be fairly complicated because it most likely means a redesign of the way both .brs/.bs and .xml files are handled by the compiler.