Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL tab completion for paths inside double quotes adds an extra double quote when expanding to a single match #54958

Open
dhanak opened this issue Jun 27, 2024 · 0 comments

Comments

@dhanak
Copy link

dhanak commented Jun 27, 2024

versioninfo()

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = emacsclient --no-wait
  JULIA_PKG_USE_CLI_GIT = true

Installation method

Via mise.

Description

In the REPL, hitting tab, among others, completes for file paths, which is a wonderful feature. It also adds the final double quote, if there is a single match only. Which is rad in a plain REPL, but not so great with, e.g., OhMyREPL, which inserts double qoutes in pairs. So the closing quote is already there, it shouldn't be inserted one more time.

julia> "/path/to/my/f{cursor, press TAB}"

julia> "/path/to/my/file"{cursor}"

As I dug into this issue, I noticed the following function in REPL/REPLCompletions.jl:

function close_path_completion(dir, paths, str, pos)
    length(paths) == 1 || return false  # Only close if there's a single choice...
    path = (paths[1]::PathCompletion).path
    path = unescape_string(replace(path, "\\\$"=>"\$"))
    path = joinpath(dir, path)
    # ...except if it's a directory...
    try
        isdir(path)
    catch e
        e isa Base.IOError || rethrow() # `path` cannot be determined to be a file
    end && return false
    # ...and except if there's already a " at the cursor.
    return lastindex(str) <= pos || str[nextind(str, pos)] != '"'
end

As the comment on the penultimate line suggests, the closing quote shouldn't be added to the input line if it's already there! So why doesn't it work? It appears that the enclosing quotes never make it as far as this function, they are already stripped earlier. So this condition (the very last) never triggers. I didn't look for the fix further up the call tree, but I'm pretty sure this is minor bug.

If I add the following to my startup.jl:

using REPL
@eval REPL.REPLCompletions close_path_completion(d, ps, s, p) = false

the issue disappears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant