I've solved this.
The trick was to use compopt -o filename
and then slice off the portion of the path being completed that is a sub-directory of the directory being completed.
Here's the code
# Do completion from a passed list of paths
#
# Accepts 2 arguments
# 1. The list of paths to complete from
# 2. The current word being completed
__dots_path_comp()
{
# This forces readline to only display the last item separated by a slash
compopt -o filenames
local IFS=$'\n'
local k="${#COMPREPLY[@]}"
for path in $(compgen -W "$1" -- $2)
do
local trailing_trim
# Determine what to trim from the end
trailing_trim="${path#${2%/*}/}/"
trailing_trim="${trailing_trim#*/}"
trailing_trim="${trailing_trim%/}"
# Don't add a space if there is more to complete
[[ "$trailing_trim" != "" ]] && compopt -o nospace
# Remove the slash if mark-directories is off
if ! _rl_enabled mark-directories
then
# If The current typed path doesnt have a slash in it yet check if
# it is the full first portion of a path and ignore everything after
# if it is. We don't have to do this once the typed path has a slash
# in it as the logic above will pick up on it
[[ "$2" != */* && "$path" == ${2}/* ]] && path="$2/$trailing_trim"
trailing_trim="/$trailing_trim"
fi
COMPREPLY[k++]="${path%%${trailing_trim}}"
done
}