@opensumi/ide-file-search 2.21.13 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/node/file-search.service.d.ts.map +1 -1
- package/lib/node/file-search.service.js +14 -2
- package/lib/node/file-search.service.js.map +1 -1
- package/lib/node/index.js.map +1 -1
- package/package.json +10 -9
- package/src/common/file-search.ts +44 -0
- package/src/common/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/node/file-search.service.ts +174 -0
- package/src/node/index.ts +23 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-search.service.d.ts","sourceRoot":"","sources":["../../src/node/file-search.service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAiC,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAgB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAI/C,qBACa,iBAAkB,YAAW,kBAAkB;IAE1D,cAAc,EAAE,eAAe,CAAC;IAGhC,MAAM,EAAE,WAAW,CAAC;IAEd,IAAI,CACR,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,kBAAkB,CAAC,OAAO,EACnC,WAAW,CAAC,EAAE,iBAAiB,GAC9B,OAAO,CAAC,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"file-search.service.d.ts","sourceRoot":"","sources":["../../src/node/file-search.service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAiC,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAgB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAI/C,qBACa,iBAAkB,YAAW,kBAAkB;IAE1D,cAAc,EAAE,eAAe,CAAC;IAGhC,MAAM,EAAE,WAAW,CAAC;IAEd,IAAI,CACR,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,kBAAkB,CAAC,OAAO,EACnC,WAAW,CAAC,EAAE,iBAAiB,GAC9B,OAAO,CAAC,MAAM,EAAE,CAAC;IA4FpB,OAAO,CAAC,MAAM;IA+Bd,OAAO,CAAC,aAAa;CAwBtB"}
|
|
@@ -9,7 +9,7 @@ const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
|
9
9
|
const ide_core_node_1 = require("@opensumi/ide-core-node");
|
|
10
10
|
const ide_process_1 = require("@opensumi/ide-process");
|
|
11
11
|
const vscode_ripgrep_1 = require("@opensumi/vscode-ripgrep");
|
|
12
|
-
const { replaceAsarInPath } = ide_core_common_1.path;
|
|
12
|
+
const { replaceAsarInPath, Path, dirname } = ide_core_common_1.path;
|
|
13
13
|
let FileSearchService = class FileSearchService {
|
|
14
14
|
async find(searchPattern, options, clientToken) {
|
|
15
15
|
const cancellationSource = new ide_core_common_1.CancellationTokenSource();
|
|
@@ -74,7 +74,19 @@ let FileSearchService = class FileSearchService {
|
|
|
74
74
|
console.error('Failed to search:', root, e);
|
|
75
75
|
}
|
|
76
76
|
}));
|
|
77
|
-
|
|
77
|
+
const sortedExactMatches = Array.from(exactMatches).sort((a, b) => {
|
|
78
|
+
const depthA = Path.pathDepth(a);
|
|
79
|
+
const depthB = Path.pathDepth(a);
|
|
80
|
+
if (depthA === depthB) {
|
|
81
|
+
const dirA = dirname(a);
|
|
82
|
+
const dirB = dirname(b);
|
|
83
|
+
return dirB.localeCompare(dirA, 'en', { numeric: true });
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return depthB - depthA;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return [...sortedExactMatches, ...fuzzyMatches];
|
|
78
90
|
}
|
|
79
91
|
doFind(rootUri, options, accept, token) {
|
|
80
92
|
return new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-search.service.js","sourceRoot":"","sources":["../../src/node/file-search.service.ts"],"names":[],"mappings":";;;;AAAA,gEAAgC;AAEhC,0DAA0B;AAE1B,qCAAqD;AACrD,+DAA6F;AAC7F,2DAAoE;AACpE,uDAAwD;AACxD,6DAAkD;AAIlD,MAAM,EAAE,iBAAiB,EAAE,GAAG,sBAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"file-search.service.js","sourceRoot":"","sources":["../../src/node/file-search.service.ts"],"names":[],"mappings":";;;;AAAA,gEAAgC;AAEhC,0DAA0B;AAE1B,qCAAqD;AACrD,+DAA6F;AAC7F,2DAAoE;AACpE,uDAAwD;AACxD,6DAAkD;AAIlD,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,sBAAI,CAAC;AAG3C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAO5B,KAAK,CAAC,IAAI,CACR,aAAqB,EACrB,OAAmC,EACnC,WAA+B;QAE/B,MAAM,kBAAkB,GAAG,IAAI,yCAAuB,EAAE,CAAC;QACzD,IAAI,WAAW,EAAE;YACf,WAAW,CAAC,uBAAuB,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC;SACxE;QACD,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC;QACvC,MAAM,IAAI,mBACR,UAAU,EAAE,IAAI,EAChB,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAC9B,YAAY,EAAE,IAAI,IACf,OAAO,CACX,CAAC;QAEF,MAAM,KAAK,GAAmC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QACxE,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACtC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;oBACnB,KAAK,CAAC,OAAO,CAAC,GAAG,EA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ACnB;yBAAM;wBACL,MAAM,CAAC,IAAI,CAAC,CAAC;qBACd;gBACH,CAAC,CAAC,CAAC;aACJ;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,CAAC,CAAC,CAAC;aACX;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAAuC;QAC3D,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACzD,IAAI,OAAO,CAAC,eAAe,EAAE;YAC3B,KAAK,MAAM,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE;gBACpD,IAAI,cAAc,EAAE;oBAClB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;iBACrC;aACF;SACF;QACD,IAAI,OAAO,CAAC,eAAe,EAAE;YAC3B,KAAK,MAAM,cAAc,IAAI,OAAO,CAAC,eAAe,EAAE;gBACpD,IAAI,cAAc,EAAE;oBAClB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC;iBAC3C;aACF;SACF;QACD,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;YACzB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAClB;QACD,IAAI,OAAO,CAAC,cAAc,EAAE;YAC1B,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;SACjC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA7JC;IAAC,IAAA,cAAS,EAAC,6BAAe,CAAC;;yDACK;AAEhC;IAAC,IAAA,cAAS,EAAC,2BAAW,CAAC;;iDACH;AALT,iBAAiB;IAD7B,IAAA,eAAU,GAAE;GACA,iBAAiB,CA8J7B;AA9JY,8CAAiB"}
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;AAAA,qCAA0C;AAC1C,2DAAqD;AAErD,sCAAsE;AAEtE,+DAA0D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;AAAA,qCAA0C;AAC1C,2DAAqD;AAErD,sCAAsE;AAEtE,+DAA0D;AAGnD,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,0BAAU;IAAzC;;QACL,cAAS,GAAG;YACV;gBACE,KAAK,EAAE,2BAAkB;gBACzB,QAAQ,EAAE,uCAAiB;aAC5B;SACF,CAAC;QAEF,iBAAY,GAAG;YACb;gBACE,KAAK,EAAE,2BAAkB;gBACzB,WAAW,EAAE,8BAAqB;aACnC;SACF,CAAC;IACJ,CAAC;CAAA,CAAA;AAdY,gBAAgB;IAD5B,IAAA,eAAU,GAAE;GACA,gBAAgB,CAc5B;AAdY,4CAAgB"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-file-search",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"files": [
|
|
5
|
-
"lib"
|
|
5
|
+
"lib",
|
|
6
|
+
"src"
|
|
6
7
|
],
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"main": "lib/index.js",
|
|
9
10
|
"typings": "lib/index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"prepublishOnly": "
|
|
12
|
+
"prepublishOnly": "yarn run build",
|
|
12
13
|
"build": "tsc --build ../../configs/ts/references/tsconfig.file-search.json"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
@@ -16,15 +17,15 @@
|
|
|
16
17
|
"url": "git@github.com:opensumi/core.git"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@opensumi/ide-core-common": "2.
|
|
20
|
-
"@opensumi/ide-core-node": "2.
|
|
21
|
-
"@opensumi/ide-process": "2.
|
|
20
|
+
"@opensumi/ide-core-common": "2.22.0",
|
|
21
|
+
"@opensumi/ide-core-node": "2.22.0",
|
|
22
|
+
"@opensumi/ide-process": "2.22.0",
|
|
22
23
|
"@opensumi/vscode-ripgrep": "^1.4.0",
|
|
23
24
|
"fuzzy": "^0.1.3"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@opensumi/ide-core-browser": "2.
|
|
27
|
-
"@opensumi/ide-dev-tool": "
|
|
27
|
+
"@opensumi/ide-core-browser": "2.22.0",
|
|
28
|
+
"@opensumi/ide-dev-tool": "1.3.1"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "927717e1c60f9cf5f01622fd51085b318a175eeb"
|
|
30
31
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CancellationToken } from '@opensumi/ide-core-common';
|
|
2
|
+
|
|
3
|
+
export const FileSearchServicePath = 'FileSearchServicePath';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The JSON-RPC file search service interface.
|
|
7
|
+
*/
|
|
8
|
+
export interface IFileSearchService {
|
|
9
|
+
/**
|
|
10
|
+
* finds files by a given search pattern.
|
|
11
|
+
* @return the matching paths, relative to the given `options.rootUri`.
|
|
12
|
+
*/
|
|
13
|
+
find(
|
|
14
|
+
searchPattern: string,
|
|
15
|
+
options: IFileSearchService.Options,
|
|
16
|
+
cancellationToken?: CancellationToken,
|
|
17
|
+
): Promise<string[]>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const IFileSearchService = Symbol('FileSearchService');
|
|
21
|
+
|
|
22
|
+
export namespace IFileSearchService {
|
|
23
|
+
export interface BaseOptions {
|
|
24
|
+
useGitIgnore?: boolean;
|
|
25
|
+
noIgnoreParent?: boolean; // 是否忽略祖先目录的 gitIgnore
|
|
26
|
+
includePatterns?: string[];
|
|
27
|
+
excludePatterns?: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface RootOptions {
|
|
30
|
+
[rootUri: string]: BaseOptions;
|
|
31
|
+
}
|
|
32
|
+
export interface Options extends BaseOptions {
|
|
33
|
+
rootUris?: string[];
|
|
34
|
+
rootOptions?: RootOptions;
|
|
35
|
+
fuzzyMatch?: boolean;
|
|
36
|
+
limit?: number;
|
|
37
|
+
/**
|
|
38
|
+
* when `undefined`, no excludes will apply, when empty array, default excludes will apply
|
|
39
|
+
*
|
|
40
|
+
* @deprecated since 0.5.0 use `excludePatterns` instead
|
|
41
|
+
*/
|
|
42
|
+
defaultIgnorePatterns?: string[];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file-search';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common';
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import readline from 'readline';
|
|
2
|
+
|
|
3
|
+
import fuzzy from 'fuzzy';
|
|
4
|
+
|
|
5
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
6
|
+
import { CancellationToken, CancellationTokenSource, path } from '@opensumi/ide-core-common';
|
|
7
|
+
import { URI, FileUri, INodeLogger } from '@opensumi/ide-core-node';
|
|
8
|
+
import { IProcessFactory } from '@opensumi/ide-process';
|
|
9
|
+
import { rgPath } from '@opensumi/vscode-ripgrep';
|
|
10
|
+
|
|
11
|
+
import { IFileSearchService } from '../common';
|
|
12
|
+
|
|
13
|
+
const { replaceAsarInPath, Path, dirname } = path;
|
|
14
|
+
|
|
15
|
+
@Injectable()
|
|
16
|
+
export class FileSearchService implements IFileSearchService {
|
|
17
|
+
@Autowired(IProcessFactory)
|
|
18
|
+
processFactory: IProcessFactory;
|
|
19
|
+
|
|
20
|
+
@Autowired(INodeLogger)
|
|
21
|
+
logger: INodeLogger;
|
|
22
|
+
|
|
23
|
+
async find(
|
|
24
|
+
searchPattern: string,
|
|
25
|
+
options: IFileSearchService.Options,
|
|
26
|
+
clientToken?: CancellationToken,
|
|
27
|
+
): Promise<string[]> {
|
|
28
|
+
const cancellationSource = new CancellationTokenSource();
|
|
29
|
+
if (clientToken) {
|
|
30
|
+
clientToken.onCancellationRequested(() => cancellationSource.cancel());
|
|
31
|
+
}
|
|
32
|
+
const token = cancellationSource.token;
|
|
33
|
+
const opts = {
|
|
34
|
+
fuzzyMatch: true,
|
|
35
|
+
limit: Number.MAX_SAFE_INTEGER,
|
|
36
|
+
useGitIgnore: true,
|
|
37
|
+
...options,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const roots: IFileSearchService.RootOptions = options.rootOptions || {};
|
|
41
|
+
if (options.rootUris) {
|
|
42
|
+
for (const rootUri of options.rootUris) {
|
|
43
|
+
if (!roots[rootUri]) {
|
|
44
|
+
roots[rootUri] = {};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// eslint-disable-next-line guard-for-in
|
|
49
|
+
for (const rootUri in roots) {
|
|
50
|
+
const rootOptions = roots[rootUri];
|
|
51
|
+
if (opts.includePatterns) {
|
|
52
|
+
const includePatterns = rootOptions.includePatterns || [];
|
|
53
|
+
rootOptions.includePatterns = [...includePatterns, ...opts.includePatterns];
|
|
54
|
+
}
|
|
55
|
+
if (opts.excludePatterns) {
|
|
56
|
+
const excludePatterns = rootOptions.excludePatterns || [];
|
|
57
|
+
rootOptions.excludePatterns = [...excludePatterns, ...opts.excludePatterns];
|
|
58
|
+
}
|
|
59
|
+
if (rootOptions.useGitIgnore === undefined) {
|
|
60
|
+
rootOptions.useGitIgnore = opts.useGitIgnore;
|
|
61
|
+
}
|
|
62
|
+
if (rootOptions.noIgnoreParent === undefined) {
|
|
63
|
+
rootOptions.noIgnoreParent = opts.noIgnoreParent;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const exactMatches = new Set<string>();
|
|
68
|
+
const fuzzyMatches = new Set<string>();
|
|
69
|
+
const stringPattern = searchPattern.toLocaleLowerCase();
|
|
70
|
+
await Promise.all(
|
|
71
|
+
Object.keys(roots).map(async (root) => {
|
|
72
|
+
try {
|
|
73
|
+
const rootUri = new URI(root);
|
|
74
|
+
const rootOptions = roots[root];
|
|
75
|
+
await this.doFind(
|
|
76
|
+
rootUri,
|
|
77
|
+
rootOptions,
|
|
78
|
+
(candidate) => {
|
|
79
|
+
const fileUri = FileUri.create(path.join(rootUri.codeUri.fsPath, candidate)).toString();
|
|
80
|
+
if (exactMatches.has(fileUri) || fuzzyMatches.has(fileUri)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
!searchPattern ||
|
|
85
|
+
searchPattern === '*' ||
|
|
86
|
+
candidate.toLocaleLowerCase().indexOf(stringPattern) !== -1
|
|
87
|
+
) {
|
|
88
|
+
exactMatches.add(fileUri);
|
|
89
|
+
} else if (opts.fuzzyMatch && fuzzy.test(searchPattern, candidate)) {
|
|
90
|
+
fuzzyMatches.add(fileUri);
|
|
91
|
+
}
|
|
92
|
+
if (exactMatches.size + fuzzyMatches.size === opts.limit) {
|
|
93
|
+
cancellationSource.cancel();
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
token,
|
|
97
|
+
);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// eslint-disable-next-line no-console
|
|
100
|
+
console.error('Failed to search:', root, e);
|
|
101
|
+
}
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
const sortedExactMatches = Array.from(exactMatches).sort((a, b) => {
|
|
105
|
+
const depthA = Path.pathDepth(a);
|
|
106
|
+
const depthB = Path.pathDepth(a);
|
|
107
|
+
if (depthA === depthB) {
|
|
108
|
+
const dirA = dirname(a);
|
|
109
|
+
const dirB = dirname(b);
|
|
110
|
+
return dirB.localeCompare(dirA, 'en', { numeric: true });
|
|
111
|
+
} else {
|
|
112
|
+
return depthB - depthA;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return [...sortedExactMatches, ...fuzzyMatches];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private doFind(
|
|
120
|
+
rootUri: URI,
|
|
121
|
+
options: IFileSearchService.BaseOptions,
|
|
122
|
+
accept: (fileUri: string) => void,
|
|
123
|
+
token: CancellationToken,
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
try {
|
|
127
|
+
const cwd = FileUri.fsPath(rootUri);
|
|
128
|
+
const args = this.getSearchArgs(options);
|
|
129
|
+
const process = this.processFactory.create({ command: replaceAsarInPath(rgPath), args, options: { cwd } });
|
|
130
|
+
process.onError(reject);
|
|
131
|
+
process.outputStream.on('close', resolve);
|
|
132
|
+
|
|
133
|
+
const lineReader = readline.createInterface({
|
|
134
|
+
input: process.outputStream,
|
|
135
|
+
output: process.inputStream,
|
|
136
|
+
});
|
|
137
|
+
lineReader.on('line', (line) => {
|
|
138
|
+
if (token.isCancellationRequested) {
|
|
139
|
+
process.dispose();
|
|
140
|
+
} else {
|
|
141
|
+
accept(line);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} catch (e) {
|
|
145
|
+
reject(e);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private getSearchArgs(options: IFileSearchService.BaseOptions): string[] {
|
|
151
|
+
const args = ['--files', '--hidden', '--case-sensitive'];
|
|
152
|
+
if (options.includePatterns) {
|
|
153
|
+
for (const includePattern of options.includePatterns) {
|
|
154
|
+
if (includePattern) {
|
|
155
|
+
args.push('--glob', includePattern);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (options.excludePatterns) {
|
|
160
|
+
for (const excludePattern of options.excludePatterns) {
|
|
161
|
+
if (excludePattern) {
|
|
162
|
+
args.push('--glob', `!${excludePattern}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (!options.useGitIgnore) {
|
|
167
|
+
args.push('-uu');
|
|
168
|
+
}
|
|
169
|
+
if (options.noIgnoreParent) {
|
|
170
|
+
args.push('--no-ignore-parent');
|
|
171
|
+
}
|
|
172
|
+
return args;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Injectable } from '@opensumi/di';
|
|
2
|
+
import { NodeModule } from '@opensumi/ide-core-node';
|
|
3
|
+
|
|
4
|
+
import { IFileSearchService, FileSearchServicePath } from '../common';
|
|
5
|
+
|
|
6
|
+
import { FileSearchService } from './file-search.service';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class FileSearchModule extends NodeModule {
|
|
10
|
+
providers = [
|
|
11
|
+
{
|
|
12
|
+
token: IFileSearchService,
|
|
13
|
+
useClass: FileSearchService,
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
backServices = [
|
|
18
|
+
{
|
|
19
|
+
token: IFileSearchService,
|
|
20
|
+
servicePath: FileSearchServicePath,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|