private void processRoot(final List<InferenceCapable> files, VirtualFile f) { LuaFileUtil.iterateLuaFilesRecursively(f, new ContentIterator() { @Override public boolean processFile(VirtualFile fileOrDir) { ProgressManager.checkCanceled(); log.debug("process " + fileOrDir.getName()); if (fileOrDir.isDirectory()) return true; indicator.setText2(fileOrDir.getPresentableName()); final FileViewProvider viewProvider = p.findViewProvider(fileOrDir); if (viewProvider == null) return true; final PsiFile psiFile = viewProvider.getPsi(viewProvider.getBaseLanguage()); if (!(psiFile instanceof InferenceCapable)) return true; indicator.setText2(fileOrDir.getName()); log.debug("forcing inference for: " + fileOrDir.getName()); files.add((InferenceCapable) psiFile); return true; } }); }
public static void divideInsideAndOutside(@NotNull PsiFile file, int startOffset, int endOffset, @NotNull TextRange range, @NotNull List<PsiElement> inside, @NotNull List<ProperTextRange> insideRanges, @NotNull List<PsiElement> outside, @NotNull List<ProperTextRange> outsideRanges, boolean includeParents, @NotNull Condition<PsiFile> filter) { final FileViewProvider viewProvider = file.getViewProvider(); for (Language language : viewProvider.getLanguages()) { final PsiFile psiRoot = viewProvider.getPsi(language); if (filter.value(psiRoot)) { divideInsideAndOutside(psiRoot, startOffset, endOffset, range, inside, insideRanges, outside, outsideRanges, includeParents); } } }
protected Block getRootBlock(PsiElement element, FileViewProvider viewProvider, CodeStyleSettings settings) { ASTNode node = element.getNode(); if (node == null) { return createDummyBlock(node); } if (viewProvider instanceof TemplateLanguageFileViewProvider) { final Language dataLanguage = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage(); final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(dataLanguage); if (builder instanceof DelegatingFormattingModelBuilder && ((DelegatingFormattingModelBuilder)builder).dontFormatMyModel()) { return createDummyBlock(node); } if (builder != null) { final FormattingModel model = builder.createModel(viewProvider.getPsi(dataLanguage), settings); List<DataLanguageBlockWrapper> childWrappers = buildChildWrappers(model.getRootBlock()); if (childWrappers.size() == 1) { childWrappers = buildChildWrappers(childWrappers.get(0).getOriginal()); } return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, filterBlocksByRange(childWrappers, node.getTextRange()), settings); } } return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null, Collections.<DataLanguageBlockWrapper>emptyList(), settings); }
@Override @Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) return null; if (!file.isPhysical()) return null; FileViewProvider viewProvider = file.getViewProvider(); if (viewProvider.getBaseLanguage() != file.getLanguage()) return null; VirtualFile virtualFile = file.getVirtualFile(); if (virtualFile == null) return null; if (!virtualFile.isInLocalFileSystem()) return null; CharSequence text = viewProvider.getContents(); Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text); // no sense in checking transparently decoded file: all characters there are already safely encoded if (charset instanceof Native2AsciiCharset) return null; List<ProblemDescriptor> descriptors = new SmartList<ProblemDescriptor>(); boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, virtualFile, charset, descriptors); if (ok) { checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors); } return descriptors.toArray(new ProblemDescriptor[descriptors.size()]); }
@Override public void doCollectInformation(@NotNull ProgressIndicator progress) { final FileViewProvider viewProvider = myFile.getViewProvider(); final Set<Language> relevantLanguages = viewProvider.getLanguages(); List<LineMarkerInfo> markers = new SmartList<LineMarkerInfo>(); for (Language language : relevantLanguages) { PsiElement psiRoot = viewProvider.getPsi(language); if (psiRoot == null || !HighlightingLevelManager.getInstance(myProject).shouldHighlight(psiRoot)) continue; List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(psiRoot, myBounds.getStartOffset(), myBounds.getEndOffset()); final List<LineMarkerProvider> providers = LineMarkersPass.getMarkerProviders(language, myProject); addLineMarkers(elements, providers, markers, progress); LineMarkersPass.collectLineMarkersForInjected(markers, elements, this, myFile, progress); } myMarkers = LineMarkersPass.mergeLineMarkers(markers, myEditor); }
@Override public void update(final AnActionEvent e) { e.getPresentation().setVisible(false); VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); if (files != null && files.length > 1) { virtualFile = null; } if (virtualFile == null || virtualFile.isDirectory()) return; Project project = e.getData(CommonDataKeys.PROJECT); if (project == null) return; final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(virtualFile); if (provider instanceof ConfigurableTemplateLanguageFileViewProvider) { final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider)provider; e.getPresentation().setText(LangBundle.message("quickfix.change.template.data.language.text", viewProvider.getTemplateDataLanguage().getDisplayName())); e.getPresentation().setEnabled(true); e.getPresentation().setVisible(true); } }
@Override public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) { PsiFile hostPsiFile = element.getContainingFile(); if (hostPsiFile == null) return null; FileViewProvider viewProvider = hostPsiFile.getViewProvider(); final DocumentEx hostDocument = (DocumentEx)viewProvider.getDocument(); if (hostDocument == null) return null; PsiManager psiManager = viewProvider.getManager(); final Project project = psiManager.getProject(); InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project); final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile); return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument); }
@NotNull @Override public FileViewProvider createFileViewProvider( @NotNull VirtualFile virtualFile, Language language, @NotNull PsiManager psiManager, boolean eventSystemEnabled) { assert language.isKindOf(SoyLanguage.INSTANCE); return new SoyFileViewProvider(psiManager, virtualFile, eventSystemEnabled); }
@Override public PsiFile createFile(FileViewProvider fileViewProvider) { if (fileViewProvider != null) { return new MelFile(fileViewProvider); } else { throw new RuntimeException("Invalid file viewer null!!!"); } }
@Override public PsiFile createFile(FileViewProvider viewProvider) { if (viewProvider != null) { return new WeaveFile(viewProvider); } else { throw new RuntimeException("Invalid file viewer null!!!"); } }
public static void autoPopupXmlLookup(final Project project, final Editor editor){ AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition<PsiFile>() { @Override public boolean value(PsiFile file) { int offset = editor.getCaretModel().getOffset(); PsiElement lastElement = InjectedLanguageUtil.findElementAtNoCommit(file, offset - 1); if (lastElement instanceof PsiFile) { //the very end of an injected file 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; } }); }
@NotNull @Override public FileViewProvider createFileViewProvider(@NotNull VirtualFile virtualFile, Language language, @NotNull PsiManager psiManager, boolean eventSystemEnabled){ assert language.isKindOf(RythmLanguage.INSTANCE); return new RythmFileViewProvider(psiManager, virtualFile, eventSystemEnabled, language); }
@Override public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) { List<LineExtensionInfo> res = ContainerUtil.newSmartList(); PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); final Document doc = FileDocumentManager.getInstance().getDocument(file); if (doc != null && lineNumber < doc.getLineCount()) { PsiFile psiFile = psiDocumentManager.getPsiFile(doc); if (psiFile != null) { int offset = doc.getLineStartOffset(lineNumber); FileViewProvider viewProvider = psiFile.getViewProvider(); PsiElement element = viewProvider.findElementAt(offset); while (element != null) { int startOffset = element.getTextRange().getStartOffset(); if (startOffset >= doc.getTextLength()) break; int startOffsetLine = doc.getLineNumber(startOffset); if (startOffsetLine < lineNumber) { element = PsiTreeUtil.nextVisibleLeaf(element); continue; } if (startOffsetLine > lineNumber) break; try { element = addExtensions(res, element); } catch (IndexNotReadyException ignored) { element = null; } } } } return res; }
@Override public boolean canHandleElement(@NotNull OpenInBrowserRequest request) { if (request.getVirtualFile() instanceof HttpVirtualFile) { return true; } // we must use base language because we serve file - not part of file, but the whole file // handlebars, for example, contains HTML and HBS psi trees, so, regardless of context, we should not handle such file FileViewProvider viewProvider = request.getFile().getViewProvider(); return viewProvider.isPhysical() && !(request.getVirtualFile() instanceof LightVirtualFile) && isMyLanguage(viewProvider.getBaseLanguage()); }
protected PsiFileBase(@NotNull FileViewProvider viewProvider, @NotNull Language language) { super(viewProvider); myLanguage = findLanguage(language, viewProvider); final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(myLanguage); if (parserDefinition == null) { throw new RuntimeException("PsiFileBase: language.getParserDefinition() returned null for: "+myLanguage); } myParserDefinition = parserDefinition; final IFileElementType nodeType = parserDefinition.getFileNodeType(); assert nodeType.getLanguage() == myLanguage: nodeType.getLanguage() + " != " + myLanguage; init(nodeType, nodeType); }
@Override public void setViewProvider(@NotNull final VirtualFile virtualFile, final FileViewProvider singleRootFileViewProvider) { if (!(virtualFile instanceof VirtualFileWindow)) { if (singleRootFileViewProvider == null) { myVFileToViewProviderMap.remove(virtualFile); } else { myVFileToViewProviderMap.put(virtualFile, singleRootFileViewProvider); } } }
protected void processXmlFile(VirtualFile t) { myIndicator.setText(findBundleMessage("find.searching.for.string.in.file.progress", myExpression.expression, t.getPresentableUrl())); final PsiFile psiFile = myManager.findFile(t); if (psiFile instanceof XmlFile) { final XmlFile t1 = (XmlFile)psiFile; final XmlDocument document; FileViewProvider fileViewProvider = t1.getViewProvider(); if (fileViewProvider instanceof TemplateLanguageFileViewProvider) { final PsiFile root = fileViewProvider.getPsi(((TemplateLanguageFileViewProvider)fileViewProvider).getTemplateDataLanguage()); if (root instanceof XmlFile) { document = ((XmlFile)root).getDocument(); } else { document = null; } } else { document = t1.getDocument(); } if (document != null) { process(document); } } myIndicator.setFraction(++myFileCount / (double)myTotalFileCount); }
public static void processRanges(@Nullable PsiElement element, CharSequence text, int cursorOffset, Editor editor, Processor<TextRange> consumer) { if (element == null) return; PsiFile file = element.getContainingFile(); FileViewProvider viewProvider = file.getViewProvider(); processInFile(element, consumer, text, cursorOffset, editor); for (PsiFile psiFile : viewProvider.getAllFiles()) { if (psiFile == file) continue; FileASTNode fileNode = psiFile.getNode(); if (fileNode == null) continue; ASTNode nodeAt = fileNode.findLeafElementAt(element.getTextOffset()); if (nodeAt == null) continue; PsiElement elementAt = nodeAt.getPsi(); while (!(elementAt instanceof PsiFile) && elementAt != null) { if (elementAt.getTextRange().contains(element.getTextRange())) break; elementAt = elementAt.getParent(); } if (elementAt == null) continue; processInFile(elementAt, consumer, text, cursorOffset, editor); } }
@Override public void doPostponedOperationsAndUnblockDocument(@NotNull Document doc) { if (doc instanceof DocumentWindow) doc = ((DocumentWindow)doc).getDelegate(); final PostprocessReformattingAspect component = myProject.getComponent(PostprocessReformattingAspect.class); final FileViewProvider viewProvider = getCachedViewProvider(doc); if (viewProvider != null && component != null) component.doPostponedFormatting(viewProvider); }
@Override public void registerErrorQuickFix(@NotNull final PsiErrorElement errorElement, @NotNull final HighlightInfo highlightInfo) { final PsiFile psiFile = errorElement.getContainingFile(); final FileViewProvider provider = psiFile.getViewProvider(); if (!(provider instanceof TemplateLanguageFileViewProvider)) return; if (psiFile.getLanguage() != ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage()) return; QuickFixAction.registerQuickFixAction(highlightInfo, createChangeTemplateDataLanguageFix(errorElement)); }
@Override @NotNull public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) { if (element instanceof PsiFile) { final FileViewProvider viewProvider = ((PsiFile)element).getViewProvider(); if (viewProvider instanceof TemplateLanguageFileViewProvider) { final Language language = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage(); FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language); if (builder != null) { return builder.createModel(viewProvider.getPsi(language), settings); } } } final PsiFile file = element.getContainingFile(); return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) { @Override protected List<Block> buildChildren() { return Collections.emptyList(); } @Override public Spacing getSpacing(final Block child1, @NotNull final Block child2) { return Spacing.getReadOnlySpacing(); } @Override public boolean isLeaf() { return true; } }, element.getProject(), settings, file.getFileType(), file); }
@Override public PsiFile createFile(FileViewProvider fileViewProvider) { return new TSFile(fileViewProvider); }
protected TSFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, TSLanguage.INSTANCE); }
public AppleScriptFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, com.intellij.plugin.applescript.AppleScriptLanguage.INSTANCE); }
public PsiFile createFile(FileViewProvider viewProvider) { return new AppleScriptFile(viewProvider); }
public PsiFile createFile(FileViewProvider viewProvider) { return new RmlFile(viewProvider); }
public PsiFile createFile(FileViewProvider viewProvider) { return new Ml4File(viewProvider); }
public PsiFile createFile(FileViewProvider viewProvider) { return new OclFile(viewProvider); }
public RmlFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, RmlLanguage.INSTANCE); }
FileBase(@NotNull FileViewProvider viewProvider, @NotNull Language language) { super(viewProvider, language); m_moduleName = RmlPsiUtil.fileNameToModuleName(getName()); }
public Ml4File(@NotNull FileViewProvider viewProvider) { super(viewProvider, OclLanguage.INSTANCE); }
public OclFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, OclLanguage.INSTANCE); }
public PsiFile createFile(FileViewProvider viewProvider) { return new GCMFile(viewProvider); }
public GCMFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, GCMLanguage.INSTANCE); }
public PsiFile createFile(FileViewProvider viewProvider) { return new SoyFile(viewProvider); }
public SoyFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, SoyLanguage.INSTANCE); }
public DotEnvFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, DotEnvLanguage.INSTANCE); }
protected EmojiResourceFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, EmojiResourceLanguage.INSTANCE); }
@Override public PsiFile createFile(FileViewProvider fileViewProvider) { return new EmojiResourceFile(fileViewProvider); }
public CptFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, CptLanguage.INSTANCE); }