arnaud-lb / vim-php-namespace

PHP namespace support for VIM. Types "use" statements for you
256 stars 29 forks source link

Trying to import multiple traits fails if they're on the same line #13

Open adamors opened 10 years ago

adamors commented 10 years ago

One small bug I noticed:

if I'm using multiple traits in a class like this:

class Foo {
    use BarTrait, FoobarTrait;
}

I cannot import the namespace for the second trait. It says that import already exists. The first one gets imported correctly, it doesn't matter if I try to import the first or the last trait's namespace.

If I have just one use statement per line, I can import all of them:

class Foo {
    use BarTrait;
    use FoobarTrait;
}

This second example works without any issues.

Thanks for doing this plugin, I use it daily. If I new VimL I'd contribute :(

arnaud-lb commented 10 years ago

Confirmed

feistiny commented 6 years ago

it's likely that the pattern to match namespace lines also match trait use line(more often just the cursor line), thus imports exists. I found that an easy solution is not to match the whole file, instead from the first line to the line above the current, just found the plugin/phpns.vim and change as following


function! s:searchCapture(pattern, nr)
    let s:capture = 0
    let str = join(getline(0, line('$')),"\n")
    let haha = substitute(str, a:pattern, '\=[submatch(0), s:saveCapture(submatch('.a:nr.'))][0]', 'e')
    return s:capture
endfunction```
    let str = join(getline(0, line('$')),"\n")
    let str = join(getline(0, line('.')-1),"\n")