Set<Language> (@NotNull PsiFile file, int offset) { Set<Language> languages = new HashSet<>(); int currOffset = offset == file.getTextLength() && offset > 0 ? offset - 1 : offset; PsiElement contextElement = file.findElementAt(currOffset); if (contextElement != null) { EditorConfigHeader header = findHeader(contextElement); if (header != null) { String pattern = header.getText(); pattern = StringUtil.trimEnd(StringUtil.trimStart(pattern, "["), "]").trim(); if ("*".equals(pattern)) return null; for (FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) { if (fileType instanceof LanguageFileType) { String testName = "/a." + fileType.getDefaultExtension(); // TODO verify that the pattern ends up being created from the same string //if (EditorConfig.filenameMatches("", pattern, testName)) { if (new Glob(pattern).match(Ec4jPath.Ec4jPaths.of(testName))) { languages.add(((LanguageFileType)fileType).getLanguage()); } } } } } return languages; } @Nullable private static EditorConfigHeader findHeader(@NotNull PsiElement contextElement) { if (contextElement instanceof PsiWhiteSpace) { PsiElement prev = contextElement.getPrevSibling(); if (prev instanceof EditorConfigSection) { return ((EditorConfigSection)prev).getHeader(); } } PsiElement parent = contextElement.getParent(); while (parent != null && !(parent instanceof PsiFile)) { if (parent instanceof EditorConfigSection) { return ((EditorConfigSection)parent).getHeader(); } parent = parent.getParent(); } return null; } }