JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
266 stars 32 forks source link

Detect and tip when prompt is entered erroneously #427

Open IanButterworth opened 3 months ago

IanButterworth commented 3 months ago
julia> pkg> add Foo
ERROR: ParseError:
# Error @ REPL[3]:1:9
pkg> add Foo
#       └──┘ ── extra tokens after end of expression
Stacktrace:
 [1] top-level scope
   @ REPL:1

It'd be good if in this case we gave a tip.

This isn't the right approach, but some abandoned code from a cruder example had some suggested language.

function check_for_prompt_start(line::String)
    if startswith(line, JULIA_PROMPT)
        printstyled("Tip:"; color=info_color())
        println(" No need to type `$JULIA_PROMPT`; enter your commands directly.")
    elseif startswith(line, PKG_PROMPT)
        printstyled("Tip:"; color=info_color())
        println(" To switch to the `$PKG_PROMPT` prompt, press `]` rather than typing `$PKG_PROMPT`.")
    elseif startswith(line, SHELL_PROMPT)
        printstyled("Tip:"; color=info_color())
        println(" To switch to the `$SHELL_PROMPT` prompt, press `;` rather than typing `$SHELL_PROMPT`.")
    elseif startswith(line, HELP_PROMPT)
        printstyled("Tip:"; color=info_color())
        println(" To switch to the `$HELP_PROMPT` prompt, press `?` rather than typing `$HELP_PROMPT`.")
    end
end

Idea proposed in https://github.com/JuliaLang/julia/pull/53823