microsoft / vscode-textmate

A library that helps tokenize text using Text Mate grammars.
MIT License
562 stars 108 forks source link

How to find all local variables? #213

Closed eterlan closed 6 months ago

eterlan commented 9 months ago

Please help! I just study this whole day and cannot get the job done..

        {
            "include": "#local_variable"
        }
    ],
    "repository": {
        "local_variable":{
            "name": "localvariable.gdscript",
            "match": "(?<=\\tvar\\s)\\b\\w+\\b"
        },

https://regex101.com/r/9siVIE/1 this works, but how to use this variable to find its usages inside function?

RedCMD commented 8 months ago

what you're probably wanting is semantic highlighting textmate should only be used for basic items as it is tokenizes everything line by line and cant jump around

jeff-hykin commented 8 months ago

To support what RedCMD said, finding local variables is impossible for Textmate parser to do reliably for languages like python/C++/Java/JavaScript. It's only realistic when local variables always start/end with something like $.

You'll need to use an LSP, or some other custom parser to get information about local variables. If you want to highlight them, there is a "decorations" API in VS Code you can use.