Skip to content

Commit

Permalink
[siw-enhancements] Addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Sanchez-Leon <alvaro.sanchez-leon@ericsson.com>
  • Loading branch information
alvsan09 committed Apr 19, 2021
1 parent 3132c25 commit 20e14e9
Showing 2 changed files with 17 additions and 20 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,8 +5,6 @@

<a name="breaking_changes_1.13.0">[Breaking Changes:](#breaking_changes_1.13.0)</a>

- [search-in-workspace] `RipgrepSearchInWorkspaceServer.getArgs` added new parameter `rootPaths: string[]` [#9307](https://github.com/eclipse-theia/theia/pull/9307)

## v1.12.0 - 3/25/2020

[1.12.0 Milestone](https://github.com/eclipse-theia/theia/milestone/17)
Original file line number Diff line number Diff line change
@@ -39,22 +39,18 @@ function bytesOrTextToString(obj: IRgBytesOrText): string {
}

/**
* Attempts to build an validate an absolute path from a given pattern and a root folder
* If a first pass is not successful a second pass will consider finding it by removing
* a glob suffix '/**', if a valid path is successfully built the suffix can be appended
* back to the result string i.e. depending on the keepSuffix flag.
* Attempts to build a valid absolute path from the given pattern and root folder.
* - If the first attempt is unsuccessful, retry without the glob suffix `/**`.
*/
function findPathInSuffixedPattern(root: string, pattern: string, keepSuffix: boolean): string | undefined {
let suffix = undefined;
let searchPath = findPathInPattern(root, pattern);

if (searchPath) {
return searchPath;
}

// Attempt to find a path in provided pattern but without a glob suffix.
let patternBase = undefined;
({ patternBase, suffix } = stripPatternGlobSuffix(pattern));
// Retry without the glob suffix.
const { patternBase, suffix } = stripPatternGlobSuffix(pattern);
if (suffix) {
searchPath = findPathInPattern(root, patternBase);
searchPath = keepSuffix && searchPath ? searchPath.concat(suffix) : searchPath;
@@ -76,13 +72,11 @@ function findPathInPattern(root: string, pattern: string): string | undefined {
* Attempts to translate a pattern string prefixed with glob stars (e.g. /a/b/c/**)
* to a file system path (/a/b/c).
*
* Returns the original pattern if not successful.
*
* Returns the pattern with out the glob stars prefix '/**' or without '\\**'
* @returns the new pattern without the glob prefix, else returns the original pattern if unsuccessful.
*/
function stripPatternGlobSuffix(pattern: string): { patternBase: string, suffix: string | undefined } {
let patternBase: string = pattern;
const globAllSize: number = 3;
let patternBase = pattern;
const globAllSize = 3;

const suffix: string | undefined = pattern.length > globAllSize
? pattern.substr(pattern.length - globAllSize, globAllSize) : undefined;
@@ -151,7 +145,7 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
this.client = client;
}

protected getArgs(rootPaths: string[], options?: SearchInWorkspaceOptions): string[] {
protected getArgs(options?: SearchInWorkspaceOptions): string[] {
const args = new Set<string>();

const appendGlobArgs = (rawPatterns: string[], exclude: boolean) => {
@@ -166,7 +160,12 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
args.add('--hidden');
args.add('--json');

args.add(options && options.matchCase ? '--case-sensitive' : '--ignore-case');
if (options && options.matchCase) {
args.add('--case-sensitive');
} else {
args.add('--ignore-case');
}

if (options && options.includeIgnored) {
args.add('--no-ignore');
}
@@ -242,7 +241,7 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
const rootPaths = rootUris.map(root => FileUri.fsPath(root));
const searchPaths: string[] = this.resolveSearchPathsFromIncludes(rootPaths, opts);
this.adjustExcludePaths(rootPaths, opts);
const rgArgs = this.getArgs(searchPaths, opts);
const rgArgs = this.getArgs(opts);
// if we use matchWholeWord we use regExp internally,
// so, we need to escape regexp characters if we actually not set regexp true in UI.
if (opts && opts.matchWholeWord && !opts.useRegExp) {
@@ -412,7 +411,7 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
const updatedExcludes: string[] = [];
opts.exclude.forEach(pattern => {
const maybePath = patternToPathsMap.get(pattern);
const adjustedPatterns = maybePath ? maybePath : [pattern];
const adjustedPatterns = maybePath ?? [pattern];
updatedExcludes.push(...adjustedPatterns);
});
opts.exclude = updatedExcludes;
@@ -438,7 +437,7 @@ export class RipgrepSearchInWorkspaceServer implements SearchInWorkspaceServer {
const includesAsPaths = this.resolvePatternToPathsMap(opts.include, rootPaths);
const patternPaths = Array.from(includesAsPaths.keys());

// Exclude include file patters that were successfully translated to search paths
// Remove file patterns that were successfully translated to search paths.
opts.include = opts.include.filter(item => !patternPaths.includes(item));

return includesAsPaths.size > 0 ? [].concat.apply([], Array.from(includesAsPaths.values())) : rootPaths;

0 comments on commit 20e14e9

Please sign in to comment.