Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/tools/grep/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ function parseOutput(output: string, filesOnly = false): GrepMatch[] {
const matches: GrepMatch[] = []
const lines = output.split("\n")

for (const line of lines) {
for (let line of lines) {
line = line.replace(/\r$/, "")
if (!line.trim()) continue

if (filesOnly) {
Expand All @@ -115,7 +116,8 @@ function parseOutput(output: string, filesOnly = false): GrepMatch[] {
continue
}

const match = line.match(/^(.+?):(\d+):(.*)$/)
// Handle Windows drive-letter paths (e.g. C:\path\file.ts:42:content)
const match = line.match(/^([A-Za-z]:[\\\/].*?|.+?):(\d+):(.*)$/)
if (match) {
matches.push({
file: match[1],
Expand All @@ -134,10 +136,11 @@ function parseCountOutput(output: string): CountResult[] {
const results: CountResult[] = []
const lines = output.split("\n")

for (const line of lines) {
for (let line of lines) {
line = line.replace(/\r$/, "")
if (!line.trim()) continue

const match = line.match(/^(.+?):(\d+)$/)
const match = line.match(/^([A-Za-z]:[\\\/].*?|.+?):(\d+)$/)
if (match) {
results.push({
file: match[1],
Expand Down
Loading