How to make symbols available outside of certain scopes?

I’m not sure how to best describe this, so sorry for the non-descriptive title.

I’m having some issues getting my symbol scoping to work properly. In Matlab, all variables defined in a function are local to that function. So far so good, this works perfectly with my basic understanding of Nova symbolication. But other than functions, there are no blocks that have truly “local” variables. For example, a variable defined in an if block is available anywhere else in the function, including outside of the block. For a concrete example,

function x(y)
    if(y>0)
        greater_than_zero = true;
    else
        greater_than_zero = false;
    end
    disp(sprintf("Is this greater than zero? %b", greater_than_zero))
end

would execute. However, if I appended a new line to the end of this:

disp(sprintf("This won't work! Nonexistent value: %b", greater_than_zero))

will produce an error, because greater_than_zero is out of scope.

In my language definition, variables are defined like this:

<scope name="matlab.definition.variable">
    <symbol type="variable" scope="local" />
    <expression>...</expression>
</scope>

If blocks are defined as start-next-end contexts. This means that in the first example, greater_than_zero would not be suggested if I try to type in the sprintf form. Is there a good way to make it available there? Essentially what I want to do is make blocks share the same symbolic context as what contains them (a function, another block, or top-level in a file), but also have proper code folding and such.

Hello,

It appears that our documentation was unclear on this, and the section explaining it was not present. I’ve made modifications to the documentation that should now be available:

https://docs.nova.app/syntax-reference/symbols/#grammar-symbolication-options

You should be able to control this using the Grammar Symbolication Options for controlling what “local” scope means, as well as potentially the options for symbol redefinition behavior, depending on how they apply to Matlab.

If these do not provide enough granularity for the options you need, please do let us know!

1 Like

That was all I needed to get it working how I expect. It’s possible there’s some syntactic weirdness that I’m not aware of, but this sure fits my mental model. Thanks!

1 Like