use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.
the class XPathEvalAction method execute.
private void execute(Editor editor) {
final Project project = editor.getProject();
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
return;
}
InputExpressionDialog.Context input;
XmlElement contextNode = null;
final Config cfg = XPathAppComponent.getInstance().getConfig();
do {
RangeHighlighter contextHighlighter = null;
if (cfg.isUseContextAtCursor()) {
// find out current context node
contextNode = MyPsiUtil.findContextNode(psiFile, editor);
if (contextNode != null) {
contextHighlighter = HighlighterUtil.highlightNode(editor, contextNode, cfg.getContextAttributes(), cfg);
}
}
if (contextNode == null) {
// in XPath data model, / is the document itself, including comments, PIs and the root element
contextNode = ((XmlFile) psiFile).getDocument();
if (contextNode == null) {
FileViewProvider fileViewProvider = psiFile.getViewProvider();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
Language dataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
PsiFile templateDataFile = fileViewProvider.getPsi(dataLanguage);
if (templateDataFile instanceof XmlFile)
contextNode = ((XmlFile) templateDataFile).getDocument();
}
}
}
input = inputXPathExpression(project, contextNode);
if (contextHighlighter != null) {
contextHighlighter.dispose();
}
if (input == null) {
return;
}
HighlighterUtil.clearHighlighters(editor);
} while (contextNode != null && evaluateExpression(input, contextNode, editor, cfg));
}
use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.
the class AbstractXmlBlock method buildInjectedPsiBlocks.
protected boolean buildInjectedPsiBlocks(List<Block> result, final ASTNode child, Wrap wrap, Alignment alignment, Indent indent) {
if (isBuildIndentsOnly())
return false;
if (myInjectedBlockBuilder.addInjectedBlocks(result, child, wrap, alignment, indent)) {
return true;
}
PsiFile containingFile = child.getPsi().getContainingFile();
FileViewProvider fileViewProvider = containingFile.getViewProvider();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
Language templateLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
PsiElement at = fileViewProvider.findElementAt(child.getStartOffset(), templateLanguage);
if (at instanceof XmlToken) {
at = at.getParent();
}
// TODO: several comments
if (at instanceof PsiComment && at.getTextRange().equals(child.getTextRange()) && at.getNode() != child) {
return buildInjectedPsiBlocks(result, at.getNode(), wrap, alignment, indent);
}
}
return false;
}
use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.
the class XmlDocumentationProvider method generateHtmlAdditionalDocTemplate.
static String generateHtmlAdditionalDocTemplate(@NotNull PsiElement element) {
StringBuilder buf = new StringBuilder();
final PsiFile containingFile = element.getContainingFile();
if (containingFile != null) {
final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class, false);
boolean append;
if (tag instanceof HtmlTag) {
append = true;
} else {
final FileViewProvider provider = containingFile.getViewProvider();
Language language;
if (provider instanceof TemplateLanguageFileViewProvider) {
language = ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage();
} else {
language = provider.getBaseLanguage();
}
append = language == XHTMLLanguage.INSTANCE;
}
if (tag != null) {
EntityDescriptor descriptor = HtmlDescriptorsTable.getTagDescriptor(tag.getName());
if (descriptor != null && append) {
buf.append("<br>");
buf.append(XmlBundle.message("html.quickdoc.additional.template", descriptor.getHelpRef(), BASE_SITEPOINT_URL + tag.getName()));
}
}
}
return buf.toString();
}
use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.
the class XmlAutoPopupHandler method autoPopupXmlLookup.
public static void autoPopupXmlLookup(final Project project, final Editor editor) {
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, file -> {
int offset = editor.getCaretModel().getOffset();
PsiElement lastElement = InjectedLanguageUtil.findElementAtNoCommit(file, offset - 1);
if (lastElement instanceof PsiFile) {
lastElement = file.findElementAt(offset - 1);
}
if (lastElement == null || !lastElement.isValid())
return false;
if (doCompleteIfNeeded(offset, file, lastElement)) {
return true;
}
FileViewProvider fileViewProvider = file.getViewProvider();
Language templateDataLanguage;
final PsiElement parent = lastElement.getParent();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider && (templateDataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage()) != parent.getLanguage()) {
lastElement = fileViewProvider.findElementAt(offset - 1, templateDataLanguage);
if (lastElement == null || !lastElement.isValid())
return false;
return doCompleteIfNeeded(offset, file, lastElement);
}
return false;
});
}
use of com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider in project intellij-community by JetBrains.
the class HtmlUnknownTagInspection method createChangeTemplateDataFix.
@Nullable
@Override
protected LocalQuickFix createChangeTemplateDataFix(PsiFile file) {
if (file != TemplateLanguageUtil.getTemplateFile(file))
return null;
FileViewProvider vp = file.getViewProvider();
if (vp instanceof ConfigurableTemplateLanguageFileViewProvider) {
final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider) vp;
final String text = LangBundle.message("quickfix.change.template.data.language.text", viewProvider.getTemplateDataLanguage().getDisplayName());
return new LocalQuickFixOnPsiElement(file) {
@NotNull
@Override
public String getText() {
return text;
}
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
ChangeTemplateDataLanguageAction.editSettings(project, file.getVirtualFile());
}
@Nls
@NotNull
@Override
public String getFamilyName() {
return "Change template data language";
}
};
}
return null;
}
Aggregations