Search in sources :

Example 1 with CodeFenceLanguageProvider

use of org.intellij.plugins.markdown.injection.CodeFenceLanguageProvider in project intellij-plugins by JetBrains.

the class LanguageListCompletionTest method testCustomCompletionProvider.

public void testCustomCompletionProvider() {
    try {
        PlatformTestUtil.registerExtension(CodeFenceLanguageProvider.EP_NAME, new CodeFenceLanguageProvider() {

            @Nullable
            @Override
            public Language getLanguageByInfoString(@NotNull String infoString) {
                return null;
            }

            @NotNull
            @Override
            public List<LookupElement> getCompletionVariantsForInfoString(@NotNull CompletionParameters parameters) {
                return Collections.singletonList(LookupElementBuilder.create("{js is a great ecma}").withInsertHandler((context, item) -> {
                    context.getDocument().insertString(context.getEditor().getCaretModel().getOffset(), "Customized insertion");
                    context.getEditor().getCaretModel().moveCaretRelatively("Customized insertion".length(), 0, true, false, true);
                }));
            }
        }, myFixture.getTestRootDisposable());
        LanguageGuesser.INSTANCE.resetCodeFenceLanguageProviders();
        configure();
        myFixture.completeBasic();
        assertContainsElements(myFixture.getLookupElementStrings(), "js", "javascript", "{js is a great ecma}");
        myFixture.type("ecm\t");
        checkResult();
    } finally {
        LanguageGuesser.INSTANCE.resetCodeFenceLanguageProviders();
    }
}
Also used : CodeFenceLanguageProvider(org.intellij.plugins.markdown.injection.CodeFenceLanguageProvider) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) Language(com.intellij.lang.Language) JavascriptLanguage(com.intellij.lang.javascript.JavascriptLanguage) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CompletionParameters (com.intellij.codeInsight.completion.CompletionParameters)1 Language (com.intellij.lang.Language)1 JavascriptLanguage (com.intellij.lang.javascript.JavascriptLanguage)1 List (java.util.List)1 CodeFenceLanguageProvider (org.intellij.plugins.markdown.injection.CodeFenceLanguageProvider)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1