diff options
| author | Paul Buetow <paul@buetow.org> | 2025-07-02 21:23:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-07-02 21:23:00 +0300 |
| commit | 17ee5e62c2b1037c21cb36f2677d2c538e2542cb (patch) | |
| tree | 8fbed16de9d7ae13307216551cbdafcd34127bf9 /internal/server | |
| parent | e7a64c7e338e0d8818425e67650e673240d9b853 (diff) | |
feat: add server info message for literal grep mode
- Add IsLiteral() and Pattern() methods to regex.Regex struct
- Log info message when grep uses optimized literal string matching
- Fix bug where grep commands were processed as cat commands
- Add comprehensive integration tests to verify literal mode messages
This gives users visibility when the performance-optimized literal
string matching is being used instead of regex matching.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/server')
| -rw-r--r-- | internal/server/handlers/readcommand.go | 28 | ||||
| -rw-r--r-- | internal/server/handlers/serverhandler.go | 8 |
2 files changed, 35 insertions, 1 deletions
diff --git a/internal/server/handlers/readcommand.go b/internal/server/handlers/readcommand.go index 8a9d0aa..1f46498 100644 --- a/internal/server/handlers/readcommand.go +++ b/internal/server/handlers/readcommand.go @@ -198,6 +198,16 @@ func (r *readCommand) read(ctx context.Context, ltx lcontext.LContext, path, globID string, re regex.Regex) { dlog.Server.Info(r.server.user, "Start reading", path, globID) + + // Log if grep is using literal mode optimization + if r.mode == omode.GrepClient { + if re.IsLiteral() { + dlog.Server.Info(r.server.user, "Using optimized literal string matching for pattern:", re.Pattern()) + } else { + dlog.Server.Info(r.server.user, "Using regex matching for pattern:", re.Pattern()) + } + } + var reader fs.FileReader var limiter chan struct{} @@ -284,6 +294,15 @@ func (r *readCommand) readWithProcessor(ctx context.Context, ltx lcontext.LConte path, globID string, re regex.Regex, reader fs.FileReader) { dlog.Server.Info(r.server.user, "Using channel-less grep implementation", path, globID) + + // Log if grep is using literal mode optimization + if r.mode == omode.GrepClient { + if re.IsLiteral() { + dlog.Server.Info(r.server.user, "Using optimized literal string matching for pattern:", re.Pattern()) + } else { + dlog.Server.Info(r.server.user, "Using regex matching for pattern:", re.Pattern()) + } + } // Use the existing lines channel but with the processor-based reader lines := r.server.lines @@ -337,6 +356,15 @@ func (r *readCommand) readWithTurboProcessor(ctx context.Context, ltx lcontext.L path, globID string, re regex.Regex, reader fs.FileReader) { dlog.Server.Info(r.server.user, "Using turbo channel-less implementation", path, globID) + + // Log if grep is using literal mode optimization + if r.mode == omode.GrepClient { + if re.IsLiteral() { + dlog.Server.Info(r.server.user, "Using optimized literal string matching for pattern:", re.Pattern()) + } else { + dlog.Server.Info(r.server.user, "Using regex matching for pattern:", re.Pattern()) + } + } // Enable turbo mode if not already enabled if !r.server.IsTurboMode() { diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go index 9163447..da27066 100644 --- a/internal/server/handlers/serverhandler.go +++ b/internal/server/handlers/serverhandler.go @@ -74,7 +74,13 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, ltx lcontext.LCon } switch commandName { - case "grep", "cat": + case "grep": + command := newReadCommand(h, omode.GrepClient) + go func() { + command.Start(ctx, ltx, argc, args, 1) + commandFinished() + }() + case "cat": command := newReadCommand(h, omode.CatClient) go func() { command.Start(ctx, ltx, argc, args, 1) |
