Search in sources :

Example 16 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class PlatformIdTableBuilding method getTodoIndexer.

@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
    final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
    if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
        SubstitutedFileType sft = (SubstitutedFileType) fileType;
        extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
    } else {
        extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
    }
    if (extIndexer != null) {
        return extIndexer;
    }
    if (fileType instanceof LanguageFileType) {
        final Language lang = ((LanguageFileType) fileType).getLanguage();
        final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
        final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
        if (commentTokens != null) {
            return new TokenSetTodoIndexer(commentTokens, virtualFile);
        }
    }
    if (fileType instanceof CustomSyntaxTableFileType) {
        return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
    }
    return null;
}
Also used : FileContent(com.intellij.util.indexing.FileContent) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) SubstitutedFileType(com.intellij.util.indexing.SubstitutedFileType) Language(com.intellij.lang.Language) TokenSet(com.intellij.psi.tree.TokenSet) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-plugins by JetBrains.

the class AngularUiRouterDiagramBuilder method getModuleFiles.

@NotNull
private Set<VirtualFile> getModuleFiles(PsiFile file, String mainModule) {
    Set<VirtualFile> moduleFiles = myModuleRecursiveDependencies.get(file);
    if (moduleFiles != null)
        return moduleFiles;
    final NonCyclicQueue<String> modulesQueue = new NonCyclicQueue<>();
    final NonCyclicQueue<VirtualFile> filesQueue = new NonCyclicQueue<VirtualFile>() {

        @Override
        protected boolean check(VirtualFile file) {
            // do not add lib (especially angular) files
            return !NodeModuleUtil.isFromNodeModules(myProject, file);
        }
    };
    if (!StringUtil.isEmptyOrSpaces(mainModule)) {
        modulesQueue.add(mainModule);
    }
    filesQueue.add(file.getVirtualFile());
    while (!modulesQueue.isEmpty()) {
        final String moduleName = modulesQueue.removeNext();
        moduleDependenciesStep(moduleName, filesQueue, modulesQueue);
    }
    while (!filesQueue.isEmpty()) {
        final VirtualFile moduleFile = filesQueue.removeNext();
        filesDependenciesStep(moduleFile, filesQueue);
    }
    Set<VirtualFile> processed = filesQueue.getProcessed();
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myProject);
    processed = new HashSet<>(ContainerUtil.filter(processed, file1 -> file1.getFileType() instanceof LanguageFileType && ((LanguageFileType) file1.getFileType()).getLanguage().isKindOf(JavascriptLanguage.INSTANCE) && projectScope.contains(file1)));
    myModuleRecursiveDependencies.put(file, processed);
    return processed;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-plugins by JetBrains.

the class LanguageListCompletionContributor method doFillVariants.

private static void doFillVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    for (CodeFenceLanguageProvider provider : LanguageGuesser.INSTANCE.getCodeFenceLanguageProviders()) {
        final List<LookupElement> lookups = provider.getCompletionVariantsForInfoString(parameters);
        for (LookupElement lookupElement : lookups) {
            result.addElement(LookupElementDecorator.withInsertHandler(lookupElement, (context, item) -> {
                new MyInsertHandler(parameters).handleInsert(context, item);
                lookupElement.handleInsert(context);
            }));
        }
    }
    for (Map.Entry<String, Language> entry : LanguageGuesser.INSTANCE.getLangToLanguageMap().entrySet()) {
        final Language language = entry.getValue();
        final LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(entry.getKey()).withIcon(new DeferredIconImpl<>(null, language, true, language1 -> {
            final LanguageFileType fileType = language1.getAssociatedFileType();
            return fileType != null ? fileType.getIcon() : null;
        })).withTypeText(language.getDisplayName(), true).withInsertHandler(new MyInsertHandler(parameters));
        result.addElement(lookupElementBuilder);
    }
}
Also used : Language(com.intellij.lang.Language) MarkdownElementTypes(org.intellij.plugins.markdown.lang.MarkdownElementTypes) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) MarkdownTokenTypes(org.intellij.plugins.markdown.lang.MarkdownTokenTypes) MarkdownFile(org.intellij.plugins.markdown.lang.psi.impl.MarkdownFile) TextRange(com.intellij.openapi.util.TextRange) DeferredIconImpl(com.intellij.ui.DeferredIconImpl) com.intellij.codeInsight.completion(com.intellij.codeInsight.completion) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement) LookupElementDecorator(com.intellij.codeInsight.lookup.LookupElementDecorator) NotNull(org.jetbrains.annotations.NotNull) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Map(java.util.Map)

Example 19 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class CheckRegExpForm method createUIComponents.

private void createUIComponents() {
    myProject = myRegexpFile.getProject();
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
    final Language language = myRegexpFile.getLanguage();
    final LanguageFileType fileType;
    if (language instanceof RegExpLanguage) {
        fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
    } else {
        // for correct syntax highlighting
        fileType = new RegExpFileType(language);
    }
    myRegExp = new EditorTextField(document, myProject, fileType);
    final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
    mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {

        @Override
        protected void updateBorder(@NotNull EditorEx editor) {
            setupBorder(editor);
        }
    };
    mySampleText.setOneLineMode(false);
    int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
    myRegExp.setPreferredWidth(preferredWidth);
    mySampleText.setPreferredWidth(preferredWidth);
    myRootPanel = new JPanel(new BorderLayout()) {

        Disposable disposable;

        Alarm updater;

        @Override
        public void addNotify() {
            super.addNotify();
            disposable = Disposer.newDisposable();
            IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
            new AnAction() {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
                }
            }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
            updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
            DocumentAdapter documentListener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    update();
                }
            };
            myRegExp.addDocumentListener(documentListener);
            mySampleText.addDocumentListener(documentListener);
            update();
            mySampleText.selectAll();
        }

        public void update() {
            final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
            updater.cancelAllRequests();
            if (!updater.isDisposed()) {
                updater.addRequest(() -> {
                    final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
                    TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
                }, 200);
            }
        }

        @Override
        public void removeNotify() {
            super.removeNotify();
            Disposer.dispose(disposable);
            PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
        }
    };
    myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) TransactionId(com.intellij.openapi.application.TransactionId) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) EditorTextField(com.intellij.ui.EditorTextField) Alarm(com.intellij.util.Alarm)

Example 20 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method isMyContext.

public boolean isMyContext(@Nullable PsiElement context) {
    if (context == null || !context.isValid())
        return false;
    PsiFile file = context.getContainingFile();
    if (file == null)
        return false;
    if (HtmlUtil.hasHtml(file))
        return false;
    final VirtualFile vFile = file.getOriginalFile().getVirtualFile();
    if (vFile != null) {
        final FileType type = vFile.getFileType();
        if (type instanceof LanguageFileType) {
            Language lang = ((LanguageFileType) type).getLanguage();
            if (lang.isKindOf(CSSLanguage.INSTANCE) && !lang.is(CSSLanguage.INSTANCE))
                return false;
        }
    }
    Module module = findModuleForPsiElement(file);
    if (module == null) {
        file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(context);
        if (file != null) {
            module = findModuleForPsiElement(file);
        }
    }
    if (module == null || ModuleType.get(module) != FlexModuleType.getInstance()) {
        return false;
    }
    if (vFile != null) {
        CssDialect dialect = CssDialectMappings.getInstance(context.getProject()).getMapping(vFile);
        return dialect == null || dialect == FlexCSSDialect.getInstance();
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) CSSLanguage(com.intellij.lang.css.CSSLanguage) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) CssDialect(com.intellij.lang.css.CssDialect) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Aggregations

LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)33 Language (com.intellij.lang.Language)20 FileType (com.intellij.openapi.fileTypes.FileType)14 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)8 PsiFile (com.intellij.psi.PsiFile)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 ParserDefinition (com.intellij.lang.ParserDefinition)4 IFileElementType (com.intellij.psi.tree.IFileElementType)4 PsiElement (com.intellij.psi.PsiElement)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)2 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 LookupElementDecorator (com.intellij.codeInsight.lookup.LookupElementDecorator)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1