google / zoekt

Fast trigram based code search
1.67k stars 113 forks source link

Q: Show context #127

Open tlamr opened 3 years ago

tlamr commented 3 years ago

Hi guys,

is it possible to show search term context in browser? e.g. 3 lines before and 3 lines after match. Thanks a lot!

hanwen commented 3 years ago

I guess? It needs a bit of refactoring, because you have to coalesce the context lines for multiple consecutive matches.

hanwen commented 3 years ago

I think you are asking if context lines are supported out of the box. The answer is: no.

tlamr commented 3 years ago

Thanks @hanwen ! I believe that this would be a brilliant feature, I so far never worked with go, but I'll try to look into it.

Cheers, T

tlamr commented 3 years ago

So this change https://github.com/tlamr/zoekt/commit/65f2bb4fbc90faea9f32c0fc189bbf7bcff967be produces https://ibb.co/Ky2PtSZ which might be just good enough for us.

Would you @hanwen be willing to accept a patch that adds this as a parameter or would you prefer some more polished solution?

Thanks, Tomas

hanwen commented 3 years ago

no. This breaks the API contract: the segment you're returning contains a '\n'. I think it would also do the wrong thing if you have two matches on consecutive lines: you'd get some lines returned twice.

tlamr commented 3 years ago

ok, thanks!

Cheers, Tomas