Giter Site home page Giter Site logo

Comments (9)

maxomatic458 avatar maxomatic458 commented on August 23, 2024 2

turns out each suggestion already includes the range in question.
so a base implementation does the trick

from reedline.

fdncred avatar fdncred commented on August 23, 2024 1

I'm up for whatever. BTW - I've never really liked Levenstein completions. I always thought alphabetical was better.

from reedline.

fdncred avatar fdncred commented on August 23, 2024

Seems plausible but sounds like it would be a breaking api change. Not that we're against that but seems like it may be tricky to retrofit in nushell. Maybe I'm wrong?

from reedline.

maxomatic458 avatar maxomatic458 commented on August 23, 2024

i guess we could make a seperate function for this then, but i feel like this just makes things unnecessarily complicated

But if we would do that, then there wont be any breaking changes

Edit: actually i think having a seperate function would probably be the better way to go

from reedline.

fdncred avatar fdncred commented on August 23, 2024

Separate function sounds great. If you put a //TODO in there around the function, to sometime consolidate functions, we can decide at a later point how important it is and if it's worth a breaking change. Thanks for bringing up this topic.

from reedline.

maxomatic458 avatar maxomatic458 commented on August 23, 2024

to make this function "optional" then
should i have a default implementation that panics or returns default values, when its not explicitly implemented?

something like this

pub trait Completer: Send {
    /// the action that will take the line and position and convert it to a vector of completions, which include the
    /// span to replace and the contents of that replacement
    fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion>;
    
    /// complete, but also return the index of the start of the string being completed
    fn complete_with_start(&mut self, line: &str, pos: usize) -> (Vec<Suggestion>, usize) {
        panic!("Not implemented")
    }
    ...
}

from reedline.

fdncred avatar fdncred commented on August 23, 2024

Is it possible to have complete_with_start call complete if complete_with_start isn't implemented? Kind of uses the default implementation of complete if complete_with_start isn't implemented.

from reedline.

maxomatic458 avatar maxomatic458 commented on August 23, 2024

@fdncred that would only work if we can assume that the suggestions starts with the last part of the line. then the start position can be calculated from that. otherwise (if the completer uses a different way, like levensthein distance of the last word or so)
then this will return a wrong value

but you could also return a default position like 0, but i think it would be better to panic then returning something potentially wrong

from reedline.

maxomatic458 avatar maxomatic458 commented on August 23, 2024

all of the current menus that support this can just do this

impl Completer for DefaultCompleter {
    fn complete(&mut self, line: &str, pos: usize) -> Vec<Suggestion> {
        complete_with_start(&mut self, line: &str, pos: usize).0
    }
    
    fn complete_with_start(&mut self, line: &str, pos: usize) -> (Vec<Suggestion>, usize) {
        ...
    }
    ...
}

from reedline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.