Search in sources :

Example 1 with GlobalVariableDefinition

use of ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition in project oxy-template-support-plugin by mutant-industries.

the class JsGlobalVariable method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiElement psiElement = parameters.getPosition();
    if (psiElement.getNode().getElementType() != JSTokenTypes.IDENTIFIER || !InnerJsReferenceExpressionResolver.isGlobalVariableSuspect(psiElement)) {
        return;
    }
    for (GlobalVariableDefinition variable : GlobalVariableIndex.getGlobals(parameters.getOriginalFile().getProject()).values()) {
        assert variable.getName() != null;
        String typeText = (variable.getType() == null || variable.getName().equals(GlobalVariableTypeProvider.CONTROLLERS_GLOBAL_VARIABLE_NAME)) ? "" : variable.getType().getTypeText().replaceFirst("^.+\\.", "");
        result.consume(LookupElementBuilder.create(variable.getName()).withInsertHandler(new TrailingPatternConsumer(INSERT_CONSUME)).withTailText(" (" + variable.getContainingFile().getName() + ")", true).withTypeText(typeText, true).withIcon(OxyTemplateFileType.INSTANCE.getIcon()).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE));
    }
}
Also used : TrailingPatternConsumer(ool.intellij.plugin.editor.completion.handler.TrailingPatternConsumer) GlobalVariableDefinition(ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition) PsiElement(com.intellij.psi.PsiElement)

Example 2 with GlobalVariableDefinition

use of ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition in project oxy-template-support-plugin by mutant-industries.

the class GlobalVariableReferenceSearch method processQuery.

@Override
public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    if (!(queryParameters.getElementToSearch() instanceof GlobalVariableDefinition)) {
        return;
    }
    final GlobalVariableDefinition target = (GlobalVariableDefinition) queryParameters.getElementToSearch();
    SearchScope scope = restrictScopeToOxyTemplates(queryParameters.getEffectiveSearchScope());
    queryParameters.getOptimizer().searchWord(target.getName(), scope, UsageSearchContext.IN_CODE, true, target.getExpression(), new RequestResultProcessor() {

        @Override
        public boolean processTextOccurrence(@NotNull PsiElement element, int offsetInElement, @NotNull Processor<PsiReference> consumer) {
            PsiReference reference;
            if (element instanceof JSReferenceExpression && (reference = element.getReference()) != null) {
                PsiElement resolveResult = reference.resolve();
                if (resolveResult instanceof GlobalVariableDefinition && target.getExpression().isEquivalentTo(((GlobalVariableDefinition) resolveResult).getExpression())) {
                    return consumer.process(reference);
                }
            }
            return true;
        }
    });
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) GlobalVariableDefinition(ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition) SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) RequestResultProcessor(com.intellij.psi.search.RequestResultProcessor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 GlobalVariableDefinition (ool.intellij.plugin.psi.reference.innerjs.globals.GlobalVariableDefinition)2 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 PsiReference (com.intellij.psi.PsiReference)1 RequestResultProcessor (com.intellij.psi.search.RequestResultProcessor)1 SearchScope (com.intellij.psi.search.SearchScope)1 TrailingPatternConsumer (ool.intellij.plugin.editor.completion.handler.TrailingPatternConsumer)1