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));
}
}
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;
}
});
}
Aggregations