is it possible to define the sub autocomplement command

I am using codemirror6 to implement a online latex editor, I was wonder is that possible to implement the sub autocomplement command? For example, when the user enter \ then pop up the \userpackage{} command, when the user selected the \userpackage{} command, then popup the autocomplement UI to make user select the next level commnad to let user select the avaliable package like xcolor table and so on.

My legacy idea is open the autocomplemention activateOnCompletion then get the user select command, then define the match like this:

{ label: "\\usepackage{xcolor", type: "text", apply: "xcolor" },

but I can not get the user select command, and this popup look like some issue that will popup the usepackage{xcolor, actually I just want to popup the latex package name xcolor . Any other way to do like this? I have already keep learning and trying for days.

Using activateOnCompletion for this is a good idea. I think you’d want to have to make sure your completion source is able to recognize when it is in a \usepackage command and complete just package names in that context, not the entire command.