Language (@NotNull PsiFile file, int offset) { final PsiElement elt = file.findElementAt(offset); if (elt == null) return file.getLanguage(); if (elt instanceof PsiWhiteSpace) { TextRange textRange = elt.getTextRange(); if (!textRange.contains(offset)) { LOG.error("PSI corrupted: in file "+file+" ("+file.getViewProvider().getVirtualFile()+") offset="+offset+" returned element "+elt+" with text range "+textRange); } final int decremented = textRange.getStartOffset() - 1; if (decremented >= 0) { return getLanguageAtOffset(file, decremented); } } return findLanguageFromElement(elt); }