package ru.adelf.idea.dotenv.go;

import com.goide.GoFileType;
import com.goide.psi.GoFile;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import ru.adelf.idea.dotenv.api.EnvironmentVariablesUsagesProvider;
import ru.adelf.idea.dotenv.models.KeyUsagePsiElement;

import java.util.Collection;
import java.util.Collections;

public class GoEnvironmentVariablesUsagesProvider implements EnvironmentVariablesUsagesProvider {
    @Override
    public boolean acceptFile(VirtualFile file) {
        return file.getFileType().equals(GoFileType.INSTANCE);
    }

    @Override
    public @NotNull Collection<KeyUsagePsiElement> getUsages(PsiFile psiFile) {
        if(psiFile instanceof GoFile) {
            GoEnvironmentCallsVisitor visitor = new GoEnvironmentCallsVisitor();
            psiFile.acceptChildren(visitor);

            return visitor.getCollectedItems();
        }

        return Collections.emptyList();
    }
}
