Sublime Forum

Nesting in Sublime Text custom autocomplete hierarchy

#1

Im using a .sublime-completions file to write my custom autocomplete code:

{
    "scope": "source.python",

    "completions":
    [
        "logic",
        "True",
        "False",
        "Object"
    ]
}

But I’m missing a way of creating a hierarchy/nest , like this:

{
    "scope": "source.python",

    "completions":
    [
        "logic",
        "True",
        "False",

        "Object":
        [
            "worldPosition",
            "applyForce",
            "name",
            "delete"
        ]
    ]
}

Does this feature exists? Is there a way to create it?

0 Likes

#2

It’s a little unclear what you want the nesting to do here. Are you trying to set something up so that the items in the Object list autocomplete if you trigger when Object is in the buffer?

1 Like

#3

Basically if I have a comand like this:

Object.applyRotation()

how do I write the autocomplete file in a way that only after i write:

Object.

this comand will be suggested:

applyRotation()

0 Likes

#4

I think you’ll need to create a .sublime-syntax file for this. There you can assign different scopes to different parts of code, which will let you apply different completions in different scopes.

1 Like

#5

Won’t be enough as noone wants to write a syntax with dedicated rules for each Object identifier.

Something like that is clearly a task for a language server.

A plugin may try to use existing syntaxes and do custom code analysis to find hints about the current context, but I guess noone wants to do that seriously for python.

0 Likes

#6

Thank you, I think that is what I’m looking for, where do I find this file?

0 Likes

#7

Take a look at Syntax Definitions – Sublime Text 3 Documentation. The .sublime-syntax file can be saved in your User package, and then you could change to this syntax manually in the bottom right corner.

But if you want to keep existing python syntax highlighting, then you would need to include standard python syntax from the Python.sublime-package and prior to that handle your special cases, what is at the least not trivial, as deathaxe writes.

Maybe LSP - Packages - Package Control is what you are actually after?

0 Likes