troy351 / emmet-monaco-es

Emmet support for Monaco Editor
MIT License
75 stars 14 forks source link

Extensibility support #102

Open mhsdesign opened 2 years ago

mhsdesign commented 2 years ago

I'm working with a Html(Xml) and Jsx like DSL The problem is that elements support a dot in their name like:

<Neos.Fusion:Tag tagName='h1' content='foo' />

So I was wondering if one could use this Emmet package to somehow add custom Emmet snippets (and don't interprete the dot as css class)

edit: I fear this is not possible as Emmet itself doesn't even support this for Jsx. For now I will use 'normal' Monaco snippets. (difficulty is figuring out if the cursor is in an attribute but that can be copied from here ^^ - or extracted/exposed? )

troy351 commented 2 years ago

Does VS Code supports feature like this? If not, I'm afraid you need to figure it out yourself

mhsdesign commented 2 years ago

i know its not api currently, but you are using this helper isValidLocationForEmmetAbbreviation. It pretty useful and id like to use it to not trigger a custom completion within html attributes. Do you think it would make sense to make it API?

import { isValidLocationForEmmetAbbreviation } from "emmet-monaco-es/src/abbreviationActions";
if (
    !isValidLocationForEmmetAbbreviation(
        model,
        position,
        "html",
        "html"
    )
) {
    return;
}
troy351 commented 2 years ago

What do you mean by "make it API"? You want to use it outside of this plugin or you want to make this check configurable?

mhsdesign commented 2 years ago

the latter, i want to use this externally, as i dont need to rewrite it then ^^ but id understand if you want to keep the API surface clean and small so you can change behaviour more easily.

edit: i mean the first

troy351 commented 2 years ago

So you want to set your own isValidLocationForEmmetAbbreviation, right? If so, I could add an option to overwrite it. Maybe expose isValidEmmetToken is a better way since you always need to check it according to tokens.

mhsdesign commented 2 years ago

sorry my previous answer was missleading, i mistyped - i meant:

That i want to use it in a custom completion provider. (Im using your emmet simutaneosly so i thought this package might as well properly expose: isValidLocationForEmmetAbbreviation)

for more context, this is how im planning to use it:


import { isValidLocationForEmmetAbbreviation } from "emmet-monaco-es/src/abbreviationActions";

monaco.languages.registerCompletionItemProvider(languageId, {
    provideCompletionItems(model, position) {
        if (
            !isValidLocationForEmmetAbbreviation(
                model,
                position,
                "html",
                "html"
            )
        ) {
            return;
        }        

        return myCustomSuggestion(...);
}
troy351 commented 2 years ago

Oh, so the first one is what you want