提交 e7acce5d 编写于 作者: R Rob Lourens

rg search - Properly anchor relative globs in text search

上级 b8c6ac61
......@@ -11,6 +11,7 @@ import * as vscode from 'vscode';
import { rgPath } from 'vscode-ripgrep';
import { normalizeNFC, normalizeNFD } from './normalization';
import { rgErrorMsgForDisplay } from './ripgrepTextSearch';
import { anchorGlob } from './ripgrepHelpers';
const isMac = process.platform === 'darwin';
......@@ -162,7 +163,7 @@ function getRgArgs(options: vscode.FileSearchOptions): string[] {
const args = ['--files', '--hidden', '--case-sensitive'];
options.includes.forEach(globArg => {
const inclusion = anchor(globArg);
const inclusion = anchorGlob(globArg);
args.push('-g', inclusion);
if (isMac) {
const normalized = normalizeNFD(inclusion);
......@@ -173,7 +174,7 @@ function getRgArgs(options: vscode.FileSearchOptions): string[] {
});
options.excludes.forEach(globArg => {
const exclusion = `!${anchor(globArg)}`;
const exclusion = `!${anchorGlob(globArg)}`;
args.push('-g', exclusion);
if (isMac) {
const normalized = normalizeNFD(exclusion);
......@@ -202,7 +203,3 @@ function getRgArgs(options: vscode.FileSearchOptions): string[] {
return args;
}
function anchor(glob: string) {
return glob.startsWith('**') || glob.startsWith('/') ? glob : `/${glob}`;
}
......@@ -16,8 +16,6 @@ export function fixDriveC(_path: string): string {
_path;
}
function trimTrailingSlash(str: string): string {
return str
.replace(/\/$/, '')
.replace(/\\$/, '');
export function anchorGlob(glob: string): string {
return glob.startsWith('**') || glob.startsWith('/') ? glob : `/${glob}`;
}
......@@ -14,6 +14,7 @@ import { StringDecoder, NodeStringDecoder } from 'string_decoder';
import * as cp from 'child_process';
import { rgPath } from 'vscode-ripgrep';
import { start } from 'repl';
import { anchorGlob } from './ripgrepHelpers';
// If vscode-ripgrep is in an .asar file, then the binary is unpacked.
const rgDiskPath = rgPath.replace(/\bnode_modules\.asar\b/, 'node_modules.asar.unpacked');
......@@ -314,11 +315,12 @@ function getRgArgs(query: vscode.TextSearchQuery, options: vscode.TextSearchOpti
const args = ['--hidden', '--heading', '--line-number', '--color', 'ansi', '--colors', 'path:none', '--colors', 'line:none', '--colors', 'match:fg:red', '--colors', 'match:style:nobold'];
args.push(query.isCaseSensitive ? '--case-sensitive' : '--ignore-case');
// TODO@roblou
options.includes
.map(anchorGlob)
.forEach(globArg => args.push('-g', globArg));
options.excludes
.map(anchorGlob)
.forEach(rgGlob => args.push('-g', `!${rgGlob}`));
if (options.maxFileSize) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册