Source:
<code>protected GoVisitor buildGoVisitor(@NotNull final ProblemsHolder holder, @SuppressWarnings({"UnusedParameters", "For future"}) @NotNull LocalInspectionToolSession session) { return new GoVisitor() { @Override public void visitParameters(@NotNull GoParameters o) { super.visitParameters(o); if (o.getParameterDeclarationList().size() == 0) return; if (PsiTreeUtil.getParentOfType(o, GoInterfaceType.class, GoTypeDeclaration.class, GoConversionExpr.class, GoTypeCaseClause.class) != null) return; <START> GoFunctionType funcType = PsiTreeUtil.getParentOfType(o, GoFunctionType.class); <END> if (funcType != null) { if (PsiTreeUtil.getParentOfType(funcType, GoParameterDeclaration.class) != null) return; } boolean isResult = PsiTreeUtil.getParentOfType(o, GoResult.class) != null; for (GoParameterDeclaration parameterDeclaration : o.getParameterDeclarationList()) { for (GoParamDefinition parameter : parameterDeclaration.getParamDefinitionList()) { ProgressManager.checkCanceled(); String paramName = parameter.getIdentifier().getText(); if (paramName.equals("_")) continue; Query<PsiReference> search = ReferencesSearch.search(parameter, o.getUseScope()); if (search.findFirst() == null) { String what = "parameter"; if (isResult) what = "named return parameter"; holder.registerProblem(parameter, "Unused " + what + " '" + paramName + "'", ProblemHighlightType.LIKE_UNUSED_SYMBOL); } } } } }; }</code><technical_language>I override visitFunctionDeclaration() retrieve signature/parameters/result/etc. for GoFunctionDeclaration instead of visiting parameters PSI tree for needed elements</technical_language>

Target:
protected GoVisitor buildGoVisitor(@NotNull final ProblemsHolder holder, @SuppressWarnings({"UnusedParameters", "For future"}) @NotNull LocalInspectionToolSession session) { return new GoVisitor() { @Override public void visitMethodDeclaration(@NotNull GoMethodDeclaration o) { super.visitMethodDeclaration(o); visitDeclaration(o); } @Override public void visitFunctionDeclaration(@NotNull GoFunctionDeclaration o) { super.visitFunctionDeclaration(o); visitDeclaration(o); } private void visitDeclaration(@NotNull GoFunctionOrMethodDeclaration o) { GoSignature signature = o.getSignature(); if (signature == null) return; GoParameters parameters = signature.getParameters(); visitParameterList(parameters.getParameterDeclarationList(), "parameter"); GoResult result = signature.getResult(); if (result == null) return; parameters = result.getParameters(); if (parameters == null) return; visitParameterList(parameters.getParameterDeclarationList(), "named return parameter"); } private void visitParameterList(List<GoParameterDeclaration> parameters, String what) { if (parameters.isEmpty()) return; for (GoParameterDeclaration parameterDeclaration : parameters) { for (GoParamDefinition parameter : parameterDeclaration.getParamDefinitionList()) { ProgressManager.checkCanceled(); if (parameter.isBlank()) continue; Query<PsiReference> search = ReferencesSearch.search(parameter, parameter.getUseScope()); if (search.findFirst() != null) continue; String paramName = parameter.getIdentifier().getText(); holder.registerProblem(parameter, "Unused " + what + " '" + paramName + "'", ProblemHighlightType.LIKE_UNUSED_SYMBOL); } } } }; }