Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs (C#)

Code before:
                    break;
            }

            if (result.Count == 0)
            {
                result = pseudoBinding.CommandName.Equals("Set-Location", StringComparison.OrdinalIgnoreCase)
                             ? new List<CompletionResult>(CompleteFilename(context, containerOnly: true, extension: null))
                             : new List<CompletionResult>(CompleteFilename(context));
            }

            return result;
        }

        /// <summary>
        /// Get the parameter completion results when the pseudo binding was successful.
        /// </summary>
        /// <param name="parameterName"></param>
        /// <param name="bindingInfo"></param>
        /// <param name="parameterAst"></param>
        /// <param name="withColon"></param>
        /// <returns></returns>
        private static List<CompletionResult> GetParameterCompletionResults(string parameterName, PseudoBindingInfo bindingInfo, CommandParameterAst parameterAst, bool withColon)
        {
            Diagnostics.Assert(bindingInfo.InfoType.Equals(PseudoBindingInfoType.PseudoBindingSucceed), "The pseudo binding should succeed");
            List<CompletionResult> result = new List<CompletionResult>();
            Assembly commandAssembly = bindingInfo.CommandInfo.CommandMetadata.CommandType.Assembly;

            if (parameterName == string.Empty)
            {
                result = GetParameterCompletionResults(
                    parameterName,
                    bindingInfo.ValidParameterSetsFlags,
                    bindingInfo.UnboundParameters,
                    withColon,
                    commandAssembly);
                return result;
            }

            if (bindingInfo.ParametersNotFound.Count > 0)
            {
                // The parameter name cannot be matched to any parameter
                if (bindingInfo.ParametersNotFound.Any(pAst => parameterAst.GetHashCode() == pAst.GetHashCode()))
                {
                    return result;
                }
            }

            if (bindingInfo.AmbiguousParameters.Count > 0)
            {
                // The parameter name is ambiguous. It's ignored in the pseudo binding, and we should search in the UnboundParameters
                if (bindingInfo.AmbiguousParameters.Any(pAst => parameterAst.GetHashCode() == pAst.GetHashCode()))

Review comment (suggestion):
For functions and script, the `CommandType` will be `typeof(PSScriptCmdlet)`. I think you should get the assembly only if the `CommandInfo` is `CmdletInfo`.

Code after:
                return CompleteCommandArgument(context);
            }

            switch (pseudoBinding.InfoType)
            {
                case PseudoBindingInfoType.PseudoBindingFail:
                    // The command is a cmdlet or script cmdlet. Binding failed
                    result = GetParameterCompletionResults(partialName, uint.MaxValue, pseudoBinding.UnboundParameters, withColon);
                    break;
                case PseudoBindingInfoType.PseudoBindingSucceed:
                    // The command is a cmdlet or script cmdlet. Binding succeeded.
                    result = GetParameterCompletionResults(partialName, pseudoBinding, parameterAst, withColon);
                    break;
            }

            if (result.Count == 0)
            {
                result = pseudoBinding.CommandName.Equals("Set-Location", StringComparison.OrdinalIgnoreCase)
                             ? new List<CompletionResult>(CompleteFilename(context, containerOnly: true, extension: null))
                             : new List<CompletionResult>(CompleteFilename(context));
            }

            return result;
        }

        /// <summary>
        /// Get the parameter completion results when the pseudo binding was successful.
        /// </summary>
        /// <param name="parameterName"></param>
        /// <param name="bindingInfo"></param>
        /// <param name="parameterAst"></param>
        /// <param name="withColon"></param>
        /// <returns></returns>
        private static List<CompletionResult> GetParameterCompletionResults(string parameterName, PseudoBindingInfo bindingInfo, CommandParameterAst parameterAst, bool withColon)
        {
            Diagnostics.Assert(bindingInfo.InfoType.Equals(PseudoBindingInfoType.PseudoBindingSucceed), "The pseudo binding should succeed");
            List<CompletionResult> result = new List<CompletionResult>();
            Assembly commandAssembly = null;
            if (bindingInfo.CommandInfo is CmdletInfo cmdletInfo)
            {
                commandAssembly = cmdletInfo.CommandMetadata.CommandType.Assembly;
            }

            if (parameterName == string.Empty)
            {
                result = GetParameterCompletionResults(
                    parameterName,
                    bindingInfo.ValidParameterSetsFlags,
                    bindingInfo.UnboundParameters,
                    withColon,
                    commandAssembly);