/** * Checks if current {@link PsiFile} is allowed to enable range highlighting. * * @param file current file * @return allowed to highlight */ @Override public boolean isForceHighlightParents(@NotNull PsiFile file) { return file.getLanguage() instanceof IgnoreLanguage; } }
@Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (file.getFileType() != BallerinaFileType.INSTANCE) { return null; } PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); if (psiFile == null) { return null; } if (psiFile.getLanguage() != BallerinaLanguage.INSTANCE) { return null; } Module module = ModuleUtilCore.findModuleForPsiElement(psiFile); if (module == null) { return null; } String sdkHomePath = BallerinaSdkService.getInstance(myProject).getSdkHomePath(module); if (StringUtil.isEmpty(sdkHomePath)) { return createMissingSdkPanel(myProject, module); } return null; }
@Override public void visitSyntax(@NotNull IgnoreSyntax syntax) { IgnoreLanguage language = (IgnoreLanguage) syntax.getContainingFile().getLanguage(); if (!language.isSyntaxSupported()) { return; } String value = syntax.getValue().getText(); for (IgnoreBundle.Syntax s : IgnoreBundle.Syntax.values()) { if (s.toString().equals(value)) { return; } } holder.registerProblem(syntax, IgnoreBundle.message("codeInspection.syntaxEntry.message"), new IgnoreSyntaxEntryFix(syntax)); } };
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) { state.extendsSets = extendsSets; PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY); state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY); Language language = file == null? root.getLanguage() : file.getLanguage(); state.caseSensitive = language.isCaseSensitive(); PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language); state.braces = matcher == null ? null : matcher.getPairs(); if (state.braces != null && state.braces.length == 0) state.braces = null; }
@Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (file.getFileType() != GoFileType.INSTANCE) return null; PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); if (psiFile == null) return null; if (psiFile.getLanguage() != GoLanguage.INSTANCE) return null; Module module = ModuleUtilCore.findModuleForPsiElement(psiFile); if (module == null) return null; String sdkHomePath = GoSdkService.getInstance(myProject).getSdkHomePath(module); if (StringUtil.isEmpty(sdkHomePath)) { return createMissingSdkPanel(myProject, module); } if (!PropertiesComponent.getInstance().getBoolean(DO_NOT_SHOW_NOTIFICATION_ABOUT_EMPTY_GOPATH, false)) { String goPath = GoSdkUtil.retrieveGoPath(myProject, module); if (StringUtil.isEmpty(goPath.trim())) { return createEmptyGoPathPanel(myProject); } } return null; }
/** * Returns element syntax. * * @return syntax */ @NotNull public IgnoreBundle.Syntax getSyntax() { PsiElement previous = getPrevSibling(); while (previous != null) { if (previous.getNode().getElementType().equals(IgnoreTypes.SYNTAX)) { IgnoreBundle.Syntax syntax = IgnoreBundle.Syntax.find(((IgnoreSyntaxImpl) previous).getValue().getText()); if (syntax != null) { return syntax; } } previous = previous.getPrevSibling(); } return ((IgnoreLanguage) getContainingFile().getLanguage()).getDefaultSyntax(); }
@Override public Result postProcessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) { if (!file.getLanguage().is(BallerinaLanguage.INSTANCE)) { return Result.Continue;
@Override public Result postProcessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) { if (!file.getLanguage().is(BallerinaLanguage.INSTANCE)) { return Result.Continue; } // We need to save the file before checking. Otherwise issues can occur when we press enter in a string. Project project = file.getProject(); PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); // Checks whether the previous line starts with "#". LogicalPosition caretPos = editor.getCaretModel().getLogicalPosition(); int prevLine = caretPos.line - 1; String lineString = editor.getDocument().getText( new TextRange(editor.getDocument().getLineStartOffset(prevLine), editor.getDocument().getLineEndOffset(prevLine))); if (lineString.trim().startsWith("#")) { int newCol = lineString.indexOf("#"); String enteredText = editor.getDocument().getText( new TextRange(editor.getDocument().getLineStartOffset(caretPos.line), editor.getDocument().getLineEndOffset(caretPos.line))).trim(); editor.getDocument().deleteString(editor.getDocument().getLineStartOffset(caretPos.line), editor.getDocument().getLineEndOffset(caretPos.line)); editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(caretPos.line, 1)); enterNewLine(editor, enteredText, newCol); // Commit the document. PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument()); } return Result.Continue; }
private boolean hasYamlRootKey( final PsiFile psiFile, final String lookupKey, final String lookupVersion) { final Language language = psiFile.getLanguage(); if (!YAMLLanguage.INSTANCE.is(language)) { return false; } return new PathFinder() .findByPathFrom(lookupKey, psiFile) .filter(psiElement -> hasVersion(psiElement, lookupVersion)) .isPresent(); }
private boolean hasJsonRootKey( final PsiFile psiFile, final String lookupKey, final String lookupVersion) { final Language language = psiFile.getLanguage(); if (!JsonLanguage.INSTANCE.is(language)) { return false; } return new PathFinder() .findByPathFrom(lookupKey, psiFile) .filter(psiElement -> hasVersion(psiElement, lookupVersion)) .isPresent(); }
@Override public Language fun(PsiFile psiFile) { return psiFile.getLanguage(); } }));
@NotNull private AnnotationHolderImpl getAnnotationsAtCaret(String filename, String content) { PsiFile psiFile = myFixture.configureByText(filename, content); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); AnnotationHolderImpl annotations = new AnnotationHolderImpl(new AnnotationSession(psiFile)); for (Annotator annotator : LanguageAnnotators.INSTANCE.allForLanguage(psiFile.getLanguage())) { annotator.annotate(psiElement, annotations); } return annotations; }
/** * Get all cached supported brace token pair. * * @return all supported brace pair token */ @Override public List<Pair<IElementType, IElementType>> getSupportedBraceToken() { Language language = this.psiFile.getLanguage(); List<Pair<IElementType, IElementType>> braceList = LanguageBracePairs.get(language); return braceList == null ? super.getSupportedBraceToken() : braceList; } }
@NonNull @Override public Language getLanguage() { return getContainingFile().getLanguage(); }
@Nullable private static Editor getPreviewEditor(@NotNull AnActionEvent e) { Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext()); PsiFile psiFile = LangDataKeys.PSI_FILE.getData(e.getDataContext()); Language language = psiFile == null ? null : psiFile.getLanguage(); LivePreviewLanguage livePreviewLanguage = language instanceof LivePreviewLanguage ? (LivePreviewLanguage)language : null; if (livePreviewLanguage == null) return null; List<Editor> editors = livePreviewLanguage.getGrammarEditors(psiFile.getProject()); return editors.isEmpty() ? null : editor; }
@Override public List<AnAction> promote(List<AnAction> actions, DataContext context) { PsiFile psiFile = PlatformDataKeys.PSI_FILE.getData(context); if (psiFile != null) { String languageId = psiFile.getLanguage().getID(); if (isSupported(languageId)) { return checkForExecuteQueryAction(actions); } } return Collections.emptyList(); }
@Override public boolean isInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) { SearchScope useScope = element.getUseScope(); return useScope instanceof LocalSearchScope && element instanceof PsiNameIdentifierOwner && !(element instanceof PerlRenameUsagesHelper) && isInplaceAllowed(element, context) && !(((PsiNameIdentifierOwner)element).getNameIdentifier() instanceof PerlStringContentElement) && element.getContainingFile().getLanguage() == PerlLanguage.INSTANCE && !(((LocalSearchScope)useScope).getScope()[0] instanceof PsiFile) ; }
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement element = descriptor.getPsiElement(); Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile()); String separator = CsvCodeStyleSettings.getCurrentSeparator(element.getProject(), element.getContainingFile().getLanguage()); String text = document.getText(); document.setText(text.substring(0, element.getTextOffset()) + separator + text.substring(element.getTextOffset())); } catch (IncorrectOperationException e) { LOG.error(e); } } }
@Override public Object getCurrentEditorElement() { if (myEditor == null) return null; final int offset = myEditor.getCaretModel().getOffset(); final PsiFile file = getPsiFile(); final PsiElement element = file.getViewProvider().findElementAt(offset, file.getLanguage()); final PsiElement parent = element != null ? element.getParent() : null; if (parent instanceof Symbol) { return parent; } return null; }
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) { state.extendsSets = extendsSets; PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY); state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY); Language language = file == null? root.getLanguage() : file.getLanguage(); state.caseSensitive = language.isCaseSensitive(); PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language); state.braces = matcher == null ? null : matcher.getPairs(); if (state.braces != null && state.braces.length == 0) state.braces = null; }