@theia/search-in-workspace 1.67.0-next.3 → 1.67.0-next.56
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/README.md +1 -1
- package/package.json +8 -8
- package/lib/browser/components/search-in-workspace-input.d.ts +0 -40
- package/lib/browser/components/search-in-workspace-input.d.ts.map +0 -1
- package/lib/browser/components/search-in-workspace-input.js +0 -124
- package/lib/browser/components/search-in-workspace-input.js.map +0 -1
- package/lib/browser/components/search-in-workspace-textarea.d.ts +0 -40
- package/lib/browser/components/search-in-workspace-textarea.d.ts.map +0 -1
- package/lib/browser/components/search-in-workspace-textarea.js +0 -136
- package/lib/browser/components/search-in-workspace-textarea.js.map +0 -1
- package/lib/browser/search-in-workspace-context-key-service.d.ts +0 -24
- package/lib/browser/search-in-workspace-context-key-service.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-context-key-service.js +0 -83
- package/lib/browser/search-in-workspace-context-key-service.js.map +0 -1
- package/lib/browser/search-in-workspace-factory.d.ts +0 -11
- package/lib/browser/search-in-workspace-factory.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-factory.js +0 -61
- package/lib/browser/search-in-workspace-factory.js.map +0 -1
- package/lib/browser/search-in-workspace-frontend-contribution.d.ts +0 -58
- package/lib/browser/search-in-workspace-frontend-contribution.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-frontend-contribution.js +0 -509
- package/lib/browser/search-in-workspace-frontend-contribution.js.map +0 -1
- package/lib/browser/search-in-workspace-frontend-module.d.ts +0 -7
- package/lib/browser/search-in-workspace-frontend-module.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-frontend-module.js +0 -73
- package/lib/browser/search-in-workspace-frontend-module.js.map +0 -1
- package/lib/browser/search-in-workspace-label-provider.d.ts +0 -10
- package/lib/browser/search-in-workspace-label-provider.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-label-provider.js +0 -50
- package/lib/browser/search-in-workspace-label-provider.js.map +0 -1
- package/lib/browser/search-in-workspace-result-tree-widget.d.ts +0 -262
- package/lib/browser/search-in-workspace-result-tree-widget.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-result-tree-widget.js +0 -1164
- package/lib/browser/search-in-workspace-result-tree-widget.js.map +0 -1
- package/lib/browser/search-in-workspace-service.d.ts +0 -36
- package/lib/browser/search-in-workspace-service.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-service.js +0 -151
- package/lib/browser/search-in-workspace-service.js.map +0 -1
- package/lib/browser/search-in-workspace-widget.d.ts +0 -123
- package/lib/browser/search-in-workspace-widget.d.ts.map +0 -1
- package/lib/browser/search-in-workspace-widget.js +0 -624
- package/lib/browser/search-in-workspace-widget.js.map +0 -1
- package/lib/browser/search-layout-migrations.d.ts +0 -6
- package/lib/browser/search-layout-migrations.d.ts.map +0 -1
- package/lib/browser/search-layout-migrations.js +0 -60
- package/lib/browser/search-layout-migrations.js.map +0 -1
- package/lib/browser-only/browser-only-search-in-workspace-service.d.ts +0 -5
- package/lib/browser-only/browser-only-search-in-workspace-service.d.ts.map +0 -1
- package/lib/browser-only/browser-only-search-in-workspace-service.js +0 -40
- package/lib/browser-only/browser-only-search-in-workspace-service.js.map +0 -1
- package/lib/browser-only/browser-search-in-workspace-server.d.ts +0 -80
- package/lib/browser-only/browser-search-in-workspace-server.d.ts.map +0 -1
- package/lib/browser-only/browser-search-in-workspace-server.js +0 -378
- package/lib/browser-only/browser-search-in-workspace-server.js.map +0 -1
- package/lib/browser-only/search-in-workspace-frontend-only-module.d.ts +0 -4
- package/lib/browser-only/search-in-workspace-frontend-only-module.d.ts.map +0 -1
- package/lib/browser-only/search-in-workspace-frontend-only-module.js +0 -37
- package/lib/browser-only/search-in-workspace-frontend-only-module.js.map +0 -1
- package/lib/common/search-in-workspace-interface.d.ts +0 -117
- package/lib/common/search-in-workspace-interface.d.ts.map +0 -1
- package/lib/common/search-in-workspace-interface.js +0 -36
- package/lib/common/search-in-workspace-interface.js.map +0 -1
- package/lib/common/search-in-workspace-preferences.d.ts +0 -19
- package/lib/common/search-in-workspace-preferences.d.ts.map +0 -1
- package/lib/common/search-in-workspace-preferences.js +0 -89
- package/lib/common/search-in-workspace-preferences.js.map +0 -1
- package/lib/node/ripgrep-search-in-workspace-server.d.ts +0 -95
- package/lib/node/ripgrep-search-in-workspace-server.d.ts.map +0 -1
- package/lib/node/ripgrep-search-in-workspace-server.js +0 -420
- package/lib/node/ripgrep-search-in-workspace-server.js.map +0 -1
- package/lib/node/ripgrep-search-in-workspace-server.slow-spec.d.ts +0 -2
- package/lib/node/ripgrep-search-in-workspace-server.slow-spec.d.ts.map +0 -1
- package/lib/node/ripgrep-search-in-workspace-server.slow-spec.js +0 -900
- package/lib/node/ripgrep-search-in-workspace-server.slow-spec.js.map +0 -1
- package/lib/node/search-in-workspace-backend-module.d.ts +0 -4
- package/lib/node/search-in-workspace-backend-module.d.ts.map +0 -1
- package/lib/node/search-in-workspace-backend-module.js +0 -35
- package/lib/node/search-in-workspace-backend-module.js.map +0 -1
|
@@ -1,900 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2017-2018 Ericsson and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
19
|
-
const core_1 = require("@theia/core");
|
|
20
|
-
const file_uri_1 = require("@theia/core/lib/common/file-uri");
|
|
21
|
-
const mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
|
|
22
|
-
const node_1 = require("@theia/process/lib/node");
|
|
23
|
-
const ripgrep_search_in_workspace_server_1 = require("./ripgrep-search-in-workspace-server");
|
|
24
|
-
const search_in_workspace_interface_1 = require("../common/search-in-workspace-interface");
|
|
25
|
-
const path = require("path");
|
|
26
|
-
const temp = require("temp");
|
|
27
|
-
const fs = require("fs");
|
|
28
|
-
const chai_1 = require("chai");
|
|
29
|
-
const ripgrep_1 = require("@vscode/ripgrep");
|
|
30
|
-
// Allow creating temporary files, but remove them when we are done.
|
|
31
|
-
const track = temp.track();
|
|
32
|
-
// The root dirs we'll use to test searching.
|
|
33
|
-
let rootDirA;
|
|
34
|
-
let rootDirB;
|
|
35
|
-
let rootSubdirA;
|
|
36
|
-
let rootDirAUri;
|
|
37
|
-
let rootDirBUri;
|
|
38
|
-
let rootSubdirAUri;
|
|
39
|
-
// Remember the content of the test files we create, to validate that the
|
|
40
|
-
// reported line text is right.
|
|
41
|
-
const fileLines = new Map();
|
|
42
|
-
// The class under test.
|
|
43
|
-
let ripgrepServer;
|
|
44
|
-
// Mock client that accumulates the returned results in a list.
|
|
45
|
-
class ResultAccumulator {
|
|
46
|
-
constructor(onDoneCallback) {
|
|
47
|
-
this.results = [];
|
|
48
|
-
this.onDoneCallback = onDoneCallback;
|
|
49
|
-
}
|
|
50
|
-
onResult(searchId, result) {
|
|
51
|
-
this.results.push(result);
|
|
52
|
-
}
|
|
53
|
-
onDone(searchId) {
|
|
54
|
-
// Sort the results, so that the order is predictable.
|
|
55
|
-
this.results.sort(search_in_workspace_interface_1.SearchInWorkspaceResult.compare);
|
|
56
|
-
this.onDoneCallback();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Create a test file relative to rootDir.
|
|
60
|
-
function createTestFile(filename, text) {
|
|
61
|
-
const dir = getRootPathFromName(filename);
|
|
62
|
-
fs.writeFileSync(path.join(dir, filename), text);
|
|
63
|
-
fileLines.set(filename, text.split('\n'));
|
|
64
|
-
}
|
|
65
|
-
// Returns the path of the root folder by the file name
|
|
66
|
-
const getRootPathFromName = (name) => {
|
|
67
|
-
const names = {
|
|
68
|
-
carrots: rootDirA,
|
|
69
|
-
potatoes: rootDirA,
|
|
70
|
-
pastas: rootDirA,
|
|
71
|
-
regexes: rootDirA,
|
|
72
|
-
'long-line': rootDirA,
|
|
73
|
-
small: `${rootDirA}/small`,
|
|
74
|
-
'file:with:some:colons': rootDirA,
|
|
75
|
-
'file with spaces': rootDirA,
|
|
76
|
-
'utf8-file': rootDirA,
|
|
77
|
-
'special shell characters': rootDirA,
|
|
78
|
-
'glob.txt': rootDirA,
|
|
79
|
-
glob: rootDirA,
|
|
80
|
-
'lots-of-matches': rootDirA,
|
|
81
|
-
orange: rootDirB,
|
|
82
|
-
folderSubfolder: rootSubdirA,
|
|
83
|
-
'orange/navel': `${rootDirA}`,
|
|
84
|
-
'orange/hamlin': `${rootDirA}`,
|
|
85
|
-
'test/test-spec.ts': `${rootDirA}`,
|
|
86
|
-
'small/test/test-spec.ts': `${rootDirA}`
|
|
87
|
-
};
|
|
88
|
-
return names[name];
|
|
89
|
-
};
|
|
90
|
-
before(() => {
|
|
91
|
-
rootDirA = track.mkdirSync();
|
|
92
|
-
rootDirB = track.mkdirSync();
|
|
93
|
-
rootSubdirA = track.mkdirSync({ dir: rootDirA });
|
|
94
|
-
rootDirAUri = file_uri_1.FileUri.create(rootDirA).toString();
|
|
95
|
-
rootDirBUri = file_uri_1.FileUri.create(rootDirB).toString();
|
|
96
|
-
rootSubdirAUri = file_uri_1.FileUri.create(rootSubdirA).toString();
|
|
97
|
-
let contents = '';
|
|
98
|
-
for (let x = 0; x < 10000; x++) {
|
|
99
|
-
const str = '' + x;
|
|
100
|
-
const pad = '00000';
|
|
101
|
-
contents += ('long-' + pad.substring(0, pad.length - str.length) + str);
|
|
102
|
-
}
|
|
103
|
-
createTestFile('long-line', contents);
|
|
104
|
-
createTestFile('carrots', `\
|
|
105
|
-
This is a carrot.
|
|
106
|
-
Most carrots are orange, but some carrots are not.
|
|
107
|
-
Once capitalized, the word carrot looks like this: CARROT.
|
|
108
|
-
Carrot is a funny word.
|
|
109
|
-
`);
|
|
110
|
-
createTestFile('potatoes', `\
|
|
111
|
-
Potatoes, unlike carrots, are generally not orange. But sweet potatoes are,
|
|
112
|
-
it's very confusing.
|
|
113
|
-
`);
|
|
114
|
-
createTestFile('pastas', 'pasta pasta');
|
|
115
|
-
createTestFile('regexes', `\
|
|
116
|
-
aaa hello. x h3lo y hell0h3lllo
|
|
117
|
-
hello1
|
|
118
|
-
`);
|
|
119
|
-
const smallDirPath = rootDirA + '/small';
|
|
120
|
-
fs.mkdirSync(smallDirPath);
|
|
121
|
-
createTestFile('small', 'A small file.\n');
|
|
122
|
-
const copyrightLine = '\
|
|
123
|
-
Copyright (C) 2021 <Company> and others.';
|
|
124
|
-
fs.mkdirSync(smallDirPath + '/test');
|
|
125
|
-
createTestFile('small/test/test-spec.ts', copyrightLine);
|
|
126
|
-
fs.mkdirSync(rootDirA + '/test');
|
|
127
|
-
createTestFile('test/test-spec.ts', copyrightLine);
|
|
128
|
-
fs.mkdirSync(rootDirA + '/orange');
|
|
129
|
-
createTestFile('orange/hamlin', '\
|
|
130
|
-
Hamlin orange is one of our most cold-hardy sweet oranges. Grown since 1885');
|
|
131
|
-
createTestFile('orange/navel', '\
|
|
132
|
-
Most well known orange type');
|
|
133
|
-
if (!core_1.isWindows) {
|
|
134
|
-
createTestFile('file:with:some:colons', `\
|
|
135
|
-
Are you looking for this: --foobar?
|
|
136
|
-
`);
|
|
137
|
-
}
|
|
138
|
-
createTestFile('file with spaces', `\
|
|
139
|
-
Are you looking for this: --foobar?
|
|
140
|
-
`);
|
|
141
|
-
createTestFile('utf8-file', `\
|
|
142
|
-
Var är jag? Varför är jag här?
|
|
143
|
-
`);
|
|
144
|
-
createTestFile('special shell characters', `\
|
|
145
|
-
If one uses \`salut";\' echo foo && echo bar; "\` as a search term it should not be a problem to find here.
|
|
146
|
-
`);
|
|
147
|
-
createTestFile('glob.txt', `\
|
|
148
|
-
test -glob patterns
|
|
149
|
-
`);
|
|
150
|
-
createTestFile('glob', `\
|
|
151
|
-
test --glob patterns
|
|
152
|
-
`);
|
|
153
|
-
let lotsOfMatchesText = '';
|
|
154
|
-
for (let i = 0; i < 100000; i++) {
|
|
155
|
-
lotsOfMatchesText += 'lots-of-matches\n';
|
|
156
|
-
}
|
|
157
|
-
createTestFile('lots-of-matches', lotsOfMatchesText);
|
|
158
|
-
createTestFile('orange', `\
|
|
159
|
-
the oranges' orange looks slightly different from carrots' orange.
|
|
160
|
-
`);
|
|
161
|
-
createTestFile('folderSubfolder', 'a file in the subfolder of a folder.');
|
|
162
|
-
});
|
|
163
|
-
// Create an instance of RipgrepSearchInWorkspaceServer which uses rgPath as
|
|
164
|
-
// the rg binary.
|
|
165
|
-
function createInstance(rgPath) {
|
|
166
|
-
const container = new inversify_1.Container();
|
|
167
|
-
container.bind(core_1.ILogger).to(mock_logger_1.MockLogger);
|
|
168
|
-
container.bind(ripgrep_search_in_workspace_server_1.RipgrepSearchInWorkspaceServer).toSelf();
|
|
169
|
-
container.bind(node_1.ProcessManager).toSelf().inSingletonScope();
|
|
170
|
-
container.bind(node_1.RawProcess).toSelf().inTransientScope();
|
|
171
|
-
container.bind(node_1.RawProcessFactory).toFactory(ctx => (options) => {
|
|
172
|
-
const child = new inversify_1.Container({ defaultScope: 'Singleton' });
|
|
173
|
-
child.parent = ctx.container;
|
|
174
|
-
child.bind(node_1.RawProcessOptions).toConstantValue(options);
|
|
175
|
-
return child.get(node_1.RawProcess);
|
|
176
|
-
});
|
|
177
|
-
container.bind(ripgrep_search_in_workspace_server_1.RgPath).toConstantValue(rgPath);
|
|
178
|
-
return container.get(ripgrep_search_in_workspace_server_1.RipgrepSearchInWorkspaceServer);
|
|
179
|
-
}
|
|
180
|
-
beforeEach(() => {
|
|
181
|
-
ripgrepServer = createInstance(ripgrep_1.rgPath);
|
|
182
|
-
});
|
|
183
|
-
after(() => {
|
|
184
|
-
try {
|
|
185
|
-
track.cleanupSync();
|
|
186
|
-
}
|
|
187
|
-
catch (ex) {
|
|
188
|
-
console.log("Couldn't cleanup search-in-workspace temp directory.", ex);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
// Compare expected and actual search results.
|
|
192
|
-
//
|
|
193
|
-
// For convenience, the expected entries do not have their lineText field set
|
|
194
|
-
// by individual tests. Using on the file and line fields, this function
|
|
195
|
-
// retrieves the expected line text based on what we have written to the test
|
|
196
|
-
// files.
|
|
197
|
-
//
|
|
198
|
-
// The expected entries should also have the file field set relatively to
|
|
199
|
-
// rootDir. This function will update the field to contain the absolute path.
|
|
200
|
-
function compareSearchResults(expected, actual) {
|
|
201
|
-
const allMatches = actual.reduceRight((p, v) => p + v.matches.length, 0);
|
|
202
|
-
(0, chai_1.expect)(allMatches).eq(expected.length, 'mismatching number of matches across results');
|
|
203
|
-
if (actual.length !== expected.length) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
for (let i = 0; i < actual.length; i++) {
|
|
207
|
-
const e = expected[i];
|
|
208
|
-
const lines = fileLines.get(e.fileUri);
|
|
209
|
-
if (lines) {
|
|
210
|
-
const line = lines[e.line - 1];
|
|
211
|
-
e.lineText = line;
|
|
212
|
-
e.fileUri = file_uri_1.FileUri.create(path.join(getRootPathFromName(e.fileUri), e.fileUri)).toString();
|
|
213
|
-
const a = actual.find(l => l.fileUri === e.fileUri);
|
|
214
|
-
const match = a.matches.find(m => m.line === e.line && m.character === e.character);
|
|
215
|
-
if (!match) {
|
|
216
|
-
console.log(a);
|
|
217
|
-
}
|
|
218
|
-
(0, chai_1.expect)(match.length).eq(e.length, `match[${i}].length != expected[${i}].length`);
|
|
219
|
-
if (typeof match.lineText === 'string') {
|
|
220
|
-
(0, chai_1.expect)(match.lineText).eq(e.lineText, `match[${i}].lineText != expected[${i}].lineText`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
// We don't know this file...
|
|
225
|
-
chai_1.expect.fail();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
describe('ripgrep-search-in-workspace-server', function () {
|
|
230
|
-
this.timeout(10000);
|
|
231
|
-
it('should return 1 result when searching for " pasta", respecting the leading whitespace', done => {
|
|
232
|
-
const pattern = ' pasta';
|
|
233
|
-
const client = new ResultAccumulator(() => {
|
|
234
|
-
const expected = [
|
|
235
|
-
{ root: rootDirAUri, fileUri: 'pastas', line: 1, character: 6, length: pattern.length, lineText: '' },
|
|
236
|
-
];
|
|
237
|
-
compareSearchResults(expected, client.results);
|
|
238
|
-
done();
|
|
239
|
-
});
|
|
240
|
-
ripgrepServer.setClient(client);
|
|
241
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
242
|
-
});
|
|
243
|
-
it('should return 1 result when searching for "pasta", respecting the trailing whitespace', done => {
|
|
244
|
-
const pattern = 'pasta ';
|
|
245
|
-
const client = new ResultAccumulator(() => {
|
|
246
|
-
const expected = [
|
|
247
|
-
{ root: rootDirAUri, fileUri: 'pastas', line: 1, character: 1, length: pattern.length, lineText: '' },
|
|
248
|
-
];
|
|
249
|
-
compareSearchResults(expected, client.results);
|
|
250
|
-
done();
|
|
251
|
-
});
|
|
252
|
-
ripgrepServer.setClient(client);
|
|
253
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
254
|
-
});
|
|
255
|
-
// Try some simple patterns with different case.
|
|
256
|
-
it('should return 7 results when searching for "carrot"', done => {
|
|
257
|
-
const pattern = 'carrot';
|
|
258
|
-
const client = new ResultAccumulator(() => {
|
|
259
|
-
const expected = [
|
|
260
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 1, character: 11, length: pattern.length, lineText: '' },
|
|
261
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 6, length: pattern.length, lineText: '' },
|
|
262
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 35, length: pattern.length, lineText: '' },
|
|
263
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 28, length: pattern.length, lineText: '' },
|
|
264
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 52, length: pattern.length, lineText: '' },
|
|
265
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 4, character: 1, length: pattern.length, lineText: '' },
|
|
266
|
-
{ root: rootDirAUri, fileUri: 'potatoes', line: 1, character: 18, length: pattern.length, lineText: '' }
|
|
267
|
-
];
|
|
268
|
-
compareSearchResults(expected, client.results);
|
|
269
|
-
done();
|
|
270
|
-
});
|
|
271
|
-
ripgrepServer.setClient(client);
|
|
272
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
273
|
-
});
|
|
274
|
-
it('should return 5 results when searching for "carrot" case sensitive', done => {
|
|
275
|
-
const pattern = 'carrot';
|
|
276
|
-
const client = new ResultAccumulator(() => {
|
|
277
|
-
const expected = [
|
|
278
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 1, character: 11, length: pattern.length, lineText: '' },
|
|
279
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 6, length: pattern.length, lineText: '' },
|
|
280
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 35, length: pattern.length, lineText: '' },
|
|
281
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 28, length: pattern.length, lineText: '' },
|
|
282
|
-
{ root: rootDirAUri, fileUri: 'potatoes', line: 1, character: 18, length: pattern.length, lineText: '' }
|
|
283
|
-
];
|
|
284
|
-
compareSearchResults(expected, client.results);
|
|
285
|
-
done();
|
|
286
|
-
});
|
|
287
|
-
ripgrepServer.setClient(client);
|
|
288
|
-
ripgrepServer.search(pattern, [rootDirAUri], {
|
|
289
|
-
matchCase: true
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
it('should return 4 results when searching for "carrot" matching whole words, case insensitive', done => {
|
|
293
|
-
const pattern = 'carrot';
|
|
294
|
-
const client = new ResultAccumulator(() => {
|
|
295
|
-
const expected = [
|
|
296
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 1, character: 11, length: pattern.length, lineText: '' },
|
|
297
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 28, length: pattern.length, lineText: '' },
|
|
298
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 52, length: pattern.length, lineText: '' },
|
|
299
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 4, character: 1, length: pattern.length, lineText: '' }
|
|
300
|
-
];
|
|
301
|
-
compareSearchResults(expected, client.results);
|
|
302
|
-
done();
|
|
303
|
-
});
|
|
304
|
-
ripgrepServer.setClient(client);
|
|
305
|
-
ripgrepServer.search(pattern, [rootDirAUri], {
|
|
306
|
-
matchWholeWord: true
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
it('should return 4 results when searching for "carrot" matching whole words, case sensitive', done => {
|
|
310
|
-
const pattern = 'carrot';
|
|
311
|
-
const client = new ResultAccumulator(() => {
|
|
312
|
-
const expected = [
|
|
313
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 1, character: 11, length: pattern.length, lineText: '' },
|
|
314
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 28, length: pattern.length, lineText: '' }
|
|
315
|
-
];
|
|
316
|
-
compareSearchResults(expected, client.results);
|
|
317
|
-
done();
|
|
318
|
-
});
|
|
319
|
-
ripgrepServer.setClient(client);
|
|
320
|
-
ripgrepServer.search(pattern, [rootDirAUri], {
|
|
321
|
-
matchWholeWord: true,
|
|
322
|
-
matchCase: true
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
it('should return 1 result when searching for "Carrot"', done => {
|
|
326
|
-
const client = new ResultAccumulator(() => {
|
|
327
|
-
const expected = [
|
|
328
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 4, character: 1, length: 6, lineText: '' },
|
|
329
|
-
];
|
|
330
|
-
compareSearchResults(expected, client.results);
|
|
331
|
-
done();
|
|
332
|
-
});
|
|
333
|
-
ripgrepServer.setClient(client);
|
|
334
|
-
ripgrepServer.search('Carrot', [rootDirAUri], { matchCase: true });
|
|
335
|
-
});
|
|
336
|
-
it('should return 0 result when searching for "CarroT"', done => {
|
|
337
|
-
const pattern = 'CarroT';
|
|
338
|
-
const client = new ResultAccumulator(() => {
|
|
339
|
-
compareSearchResults([], client.results);
|
|
340
|
-
done();
|
|
341
|
-
});
|
|
342
|
-
ripgrepServer.setClient(client);
|
|
343
|
-
ripgrepServer.search(pattern, [rootDirAUri], { matchCase: true });
|
|
344
|
-
});
|
|
345
|
-
// Try something that we know isn't there.
|
|
346
|
-
it('should find 0 result when searching for "PINEAPPLE"', done => {
|
|
347
|
-
const pattern = 'PINEAPPLE';
|
|
348
|
-
const client = new ResultAccumulator(() => {
|
|
349
|
-
compareSearchResults([], client.results);
|
|
350
|
-
done();
|
|
351
|
-
});
|
|
352
|
-
ripgrepServer.setClient(client);
|
|
353
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
354
|
-
});
|
|
355
|
-
// Try a pattern with a space.
|
|
356
|
-
it('should find 1 result when searching for "carrots are orange"', done => {
|
|
357
|
-
const pattern = 'carrots are orange';
|
|
358
|
-
const client = new ResultAccumulator(() => {
|
|
359
|
-
const expected = [
|
|
360
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 6, length: pattern.length, lineText: '' },
|
|
361
|
-
];
|
|
362
|
-
compareSearchResults(expected, client.results);
|
|
363
|
-
done();
|
|
364
|
-
});
|
|
365
|
-
ripgrepServer.setClient(client);
|
|
366
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
367
|
-
});
|
|
368
|
-
it('should deal with very long lines."', done => {
|
|
369
|
-
const pattern = 'long-00400';
|
|
370
|
-
const client = new ResultAccumulator(() => {
|
|
371
|
-
const expected = [
|
|
372
|
-
{ root: rootDirAUri, fileUri: 'long-line', line: 1, character: 4001, length: pattern.length, lineText: '' },
|
|
373
|
-
];
|
|
374
|
-
compareSearchResults(expected, client.results);
|
|
375
|
-
const match = client.results[0].matches[0];
|
|
376
|
-
if (typeof match.lineText === 'string') {
|
|
377
|
-
done(new Error('unexpected lineText'));
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
(0, chai_1.expect)(match.lineText.text.substring(match.lineText.character - 1, pattern.length + match.lineText.character - 1)).eq(pattern);
|
|
381
|
-
done();
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
ripgrepServer.setClient(client);
|
|
385
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
386
|
-
});
|
|
387
|
-
// Try with an output size that exceeds the default node buffer size
|
|
388
|
-
// (200 * 1024) when spawning a new process.
|
|
389
|
-
it('should work with a lot of results', done => {
|
|
390
|
-
// This can take a bit of time.
|
|
391
|
-
this.timeout(150000);
|
|
392
|
-
const pattern = 'lots-of-matches';
|
|
393
|
-
const client = new ResultAccumulator(() => {
|
|
394
|
-
const expected = [];
|
|
395
|
-
for (let i = 1; i <= 100000; i++) {
|
|
396
|
-
expected.push({
|
|
397
|
-
root: rootDirAUri,
|
|
398
|
-
fileUri: 'lots-of-matches',
|
|
399
|
-
line: i,
|
|
400
|
-
character: 1,
|
|
401
|
-
length: pattern.length,
|
|
402
|
-
lineText: '',
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
compareSearchResults(expected, client.results);
|
|
406
|
-
done();
|
|
407
|
-
});
|
|
408
|
-
ripgrepServer.setClient(client);
|
|
409
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
410
|
-
});
|
|
411
|
-
// Try limiting the number of returned results.
|
|
412
|
-
it('should limit the number of returned results', done => {
|
|
413
|
-
const pattern = 'lots-of-matches';
|
|
414
|
-
const client = new ResultAccumulator(() => {
|
|
415
|
-
const expected = [];
|
|
416
|
-
for (let i = 1; i <= 1000; i++) {
|
|
417
|
-
expected.push({
|
|
418
|
-
root: rootDirAUri,
|
|
419
|
-
fileUri: 'lots-of-matches',
|
|
420
|
-
line: i,
|
|
421
|
-
character: 1,
|
|
422
|
-
length: pattern.length,
|
|
423
|
-
lineText: '',
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
compareSearchResults(expected, client.results);
|
|
427
|
-
done();
|
|
428
|
-
});
|
|
429
|
-
ripgrepServer.setClient(client);
|
|
430
|
-
ripgrepServer.search(pattern, [rootDirAUri], {
|
|
431
|
-
maxResults: 1000,
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
// Try with regexes.
|
|
435
|
-
it('should search for regexes', done => {
|
|
436
|
-
const pattern = 'h[e3]l+[o0]';
|
|
437
|
-
const client = new ResultAccumulator(() => {
|
|
438
|
-
const expected = [
|
|
439
|
-
{ root: rootDirAUri, fileUri: 'regexes', line: 1, character: 5, length: 5, lineText: '' },
|
|
440
|
-
{ root: rootDirAUri, fileUri: 'regexes', line: 1, character: 14, length: 4, lineText: '' },
|
|
441
|
-
{ root: rootDirAUri, fileUri: 'regexes', line: 1, character: 21, length: 5, lineText: '' },
|
|
442
|
-
{ root: rootDirAUri, fileUri: 'regexes', line: 1, character: 26, length: 6, lineText: '' },
|
|
443
|
-
{ root: rootDirAUri, fileUri: 'regexes', line: 2, character: 1, length: 5, lineText: '' },
|
|
444
|
-
];
|
|
445
|
-
compareSearchResults(expected, client.results);
|
|
446
|
-
done();
|
|
447
|
-
});
|
|
448
|
-
ripgrepServer.setClient(client);
|
|
449
|
-
ripgrepServer.search(pattern, [rootDirAUri], {
|
|
450
|
-
useRegExp: true
|
|
451
|
-
});
|
|
452
|
-
});
|
|
453
|
-
// Try without regex
|
|
454
|
-
it('should search for fixed string', done => {
|
|
455
|
-
const pattern = 'hello.';
|
|
456
|
-
const client = new ResultAccumulator(() => {
|
|
457
|
-
const expected = [
|
|
458
|
-
{ root: rootDirAUri, fileUri: 'regexes', line: 1, character: 5, length: 6, lineText: '' }
|
|
459
|
-
];
|
|
460
|
-
compareSearchResults(expected, client.results);
|
|
461
|
-
done();
|
|
462
|
-
});
|
|
463
|
-
ripgrepServer.setClient(client);
|
|
464
|
-
ripgrepServer.search(pattern, [rootDirAUri], {
|
|
465
|
-
useRegExp: false
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
// Try with a pattern starting with -, and in filenames containing colons and spaces.
|
|
469
|
-
it('should search a pattern starting with -', done => {
|
|
470
|
-
const pattern = '-fo+bar';
|
|
471
|
-
const client = new ResultAccumulator(() => {
|
|
472
|
-
const expected = [
|
|
473
|
-
{ root: rootDirAUri, fileUri: 'file with spaces', line: 1, character: 28, length: 7, lineText: '' },
|
|
474
|
-
];
|
|
475
|
-
if (!core_1.isWindows) {
|
|
476
|
-
expected.push({ root: rootDirAUri, fileUri: 'file:with:some:colons', line: 1, character: 28, length: 7, lineText: '' });
|
|
477
|
-
}
|
|
478
|
-
compareSearchResults(expected, client.results);
|
|
479
|
-
done();
|
|
480
|
-
});
|
|
481
|
-
ripgrepServer.setClient(client);
|
|
482
|
-
ripgrepServer.search(pattern, [rootDirAUri], { useRegExp: true });
|
|
483
|
-
});
|
|
484
|
-
// Try with a pattern starting with --, and in filenames containing colons and spaces.
|
|
485
|
-
it('should search a pattern starting with --', done => {
|
|
486
|
-
const pattern = '--fo+bar';
|
|
487
|
-
const client = new ResultAccumulator(() => {
|
|
488
|
-
const expected = [
|
|
489
|
-
{ root: rootDirAUri, fileUri: 'file with spaces', line: 1, character: 27, length: 8, lineText: '' },
|
|
490
|
-
];
|
|
491
|
-
if (!core_1.isWindows) {
|
|
492
|
-
expected.push({ root: rootDirAUri, fileUri: 'file:with:some:colons', line: 1, character: 27, length: 8, lineText: '' });
|
|
493
|
-
}
|
|
494
|
-
compareSearchResults(expected, client.results);
|
|
495
|
-
done();
|
|
496
|
-
});
|
|
497
|
-
ripgrepServer.setClient(client);
|
|
498
|
-
ripgrepServer.search(pattern, [rootDirAUri], { useRegExp: true });
|
|
499
|
-
});
|
|
500
|
-
it('should search a pattern starting with a dash w/o regex', done => {
|
|
501
|
-
const pattern = '-foobar';
|
|
502
|
-
const client = new ResultAccumulator(() => {
|
|
503
|
-
const expected = [
|
|
504
|
-
{ root: rootDirAUri, fileUri: 'file with spaces', line: 1, character: 28, length: 7, lineText: '' },
|
|
505
|
-
];
|
|
506
|
-
if (!core_1.isWindows) {
|
|
507
|
-
expected.push({ root: rootDirAUri, fileUri: 'file:with:some:colons', line: 1, character: 28, length: 7, lineText: '' });
|
|
508
|
-
}
|
|
509
|
-
compareSearchResults(expected, client.results);
|
|
510
|
-
done();
|
|
511
|
-
});
|
|
512
|
-
ripgrepServer.setClient(client);
|
|
513
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
514
|
-
});
|
|
515
|
-
it('should search a pattern starting with two dashes w/o regex', done => {
|
|
516
|
-
const pattern = '--foobar';
|
|
517
|
-
const client = new ResultAccumulator(() => {
|
|
518
|
-
const expected = [
|
|
519
|
-
{ root: rootDirAUri, fileUri: 'file with spaces', line: 1, character: 27, length: 8, lineText: '' },
|
|
520
|
-
];
|
|
521
|
-
if (!core_1.isWindows) {
|
|
522
|
-
expected.push({ root: rootDirAUri, fileUri: 'file:with:some:colons', line: 1, character: 27, length: 8, lineText: '' });
|
|
523
|
-
}
|
|
524
|
-
compareSearchResults(expected, client.results);
|
|
525
|
-
done();
|
|
526
|
-
});
|
|
527
|
-
ripgrepServer.setClient(client);
|
|
528
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
529
|
-
});
|
|
530
|
-
it('should search a whole pattern starting with - w/o regex', done => {
|
|
531
|
-
const pattern = '-glob';
|
|
532
|
-
const client = new ResultAccumulator(() => {
|
|
533
|
-
const expected = [
|
|
534
|
-
{ root: rootDirAUri, fileUri: 'glob', line: 1, character: 7, length: 5, lineText: '' },
|
|
535
|
-
{ root: rootDirAUri, fileUri: 'glob.txt', line: 1, character: 6, length: 5, lineText: '' }
|
|
536
|
-
];
|
|
537
|
-
compareSearchResults(expected, client.results);
|
|
538
|
-
done();
|
|
539
|
-
});
|
|
540
|
-
ripgrepServer.setClient(client);
|
|
541
|
-
ripgrepServer.search(pattern, [rootDirAUri], { matchWholeWord: true });
|
|
542
|
-
});
|
|
543
|
-
it('should search a whole pattern starting with -- w/o regex', done => {
|
|
544
|
-
const pattern = '--glob';
|
|
545
|
-
const client = new ResultAccumulator(() => {
|
|
546
|
-
const expected = [
|
|
547
|
-
{ root: rootDirAUri, fileUri: 'glob', line: 1, character: 6, length: 6, lineText: '' }
|
|
548
|
-
];
|
|
549
|
-
compareSearchResults(expected, client.results);
|
|
550
|
-
done();
|
|
551
|
-
});
|
|
552
|
-
ripgrepServer.setClient(client);
|
|
553
|
-
ripgrepServer.search(pattern, [rootDirAUri], { matchWholeWord: true });
|
|
554
|
-
});
|
|
555
|
-
it('should search a pattern in .txt file', done => {
|
|
556
|
-
const pattern = '-glob';
|
|
557
|
-
const client = new ResultAccumulator(() => {
|
|
558
|
-
const expected = [
|
|
559
|
-
{ root: rootDirAUri, fileUri: 'glob.txt', line: 1, character: 6, length: 5, lineText: '' }
|
|
560
|
-
];
|
|
561
|
-
compareSearchResults(expected, client.results);
|
|
562
|
-
done();
|
|
563
|
-
});
|
|
564
|
-
ripgrepServer.setClient(client);
|
|
565
|
-
ripgrepServer.search(pattern, [rootDirAUri], { include: ['*.txt'] });
|
|
566
|
-
});
|
|
567
|
-
it('should search a whole pattern in .txt file', done => {
|
|
568
|
-
const pattern = '-glob';
|
|
569
|
-
const client = new ResultAccumulator(() => {
|
|
570
|
-
const expected = [
|
|
571
|
-
{ root: rootDirAUri, fileUri: 'glob.txt', line: 1, character: 6, length: 5, lineText: '' }
|
|
572
|
-
];
|
|
573
|
-
compareSearchResults(expected, client.results);
|
|
574
|
-
done();
|
|
575
|
-
});
|
|
576
|
-
ripgrepServer.setClient(client);
|
|
577
|
-
ripgrepServer.search(pattern, [rootDirAUri], { include: ['*.txt'], matchWholeWord: true });
|
|
578
|
-
});
|
|
579
|
-
it('should search in a given file by relative path', done => {
|
|
580
|
-
const pattern = 'carrots';
|
|
581
|
-
const client = new ResultAccumulator(() => {
|
|
582
|
-
const expected = [
|
|
583
|
-
{ root: rootDirAUri, fileUri: 'potatoes', line: 1, character: 18, length: pattern.length, lineText: '' }
|
|
584
|
-
];
|
|
585
|
-
compareSearchResults(expected, client.results);
|
|
586
|
-
done();
|
|
587
|
-
});
|
|
588
|
-
ripgrepServer.setClient(client);
|
|
589
|
-
ripgrepServer.search(pattern, [rootDirAUri], { include: ['./potatoes'], matchWholeWord: true });
|
|
590
|
-
});
|
|
591
|
-
it('should only apply to sub-folders of given include', done => {
|
|
592
|
-
const pattern = 'Copyright';
|
|
593
|
-
const client = new ResultAccumulator(() => {
|
|
594
|
-
const expected = [
|
|
595
|
-
{ root: rootDirAUri, fileUri: 'test/test-spec.ts', line: 1, character: 5, length: pattern.length, lineText: '' }
|
|
596
|
-
];
|
|
597
|
-
compareSearchResults(expected, client.results);
|
|
598
|
-
done();
|
|
599
|
-
});
|
|
600
|
-
ripgrepServer.setClient(client);
|
|
601
|
-
// Matching only the top 'test' folder and not any other 'test' subfolder
|
|
602
|
-
ripgrepServer.search(pattern, [rootDirAUri], { include: ['./test'], matchWholeWord: true });
|
|
603
|
-
});
|
|
604
|
-
it('should apply to all sub-folders of not relative pattern', done => {
|
|
605
|
-
const pattern = 'Copyright';
|
|
606
|
-
const client = new ResultAccumulator(() => {
|
|
607
|
-
const expected = [
|
|
608
|
-
{ root: rootDirAUri, fileUri: 'small/test/test-spec.ts', line: 1, character: 5, length: pattern.length, lineText: '' },
|
|
609
|
-
{ root: rootDirAUri, fileUri: 'test/test-spec.ts', line: 1, character: 5, length: pattern.length, lineText: '' }
|
|
610
|
-
];
|
|
611
|
-
compareSearchResults(expected, client.results);
|
|
612
|
-
done();
|
|
613
|
-
});
|
|
614
|
-
ripgrepServer.setClient(client);
|
|
615
|
-
// Matching only the top 'test' folder and not any other 'test' subfolder
|
|
616
|
-
ripgrepServer.search(pattern, [rootDirAUri], { include: ['test'], matchWholeWord: true });
|
|
617
|
-
});
|
|
618
|
-
it('should consider "include" string as a file', done => {
|
|
619
|
-
const pattern = 'slightly';
|
|
620
|
-
const client = new ResultAccumulator(() => {
|
|
621
|
-
const expected = [
|
|
622
|
-
{ root: rootDirAUri, fileUri: 'orange', line: 1, character: 27, length: pattern.length, lineText: '' }
|
|
623
|
-
];
|
|
624
|
-
compareSearchResults(expected, client.results);
|
|
625
|
-
done();
|
|
626
|
-
});
|
|
627
|
-
ripgrepServer.setClient(client);
|
|
628
|
-
ripgrepServer.search(pattern, [rootDirBUri], { include: ['orange'], matchWholeWord: true });
|
|
629
|
-
});
|
|
630
|
-
it('should consider "include" string as a folder', done => {
|
|
631
|
-
const pattern = 'Most';
|
|
632
|
-
const client = new ResultAccumulator(() => {
|
|
633
|
-
const expected = [
|
|
634
|
-
{ root: rootDirAUri, fileUri: 'orange/navel', line: 1, character: 5, length: pattern.length, lineText: '' },
|
|
635
|
-
{ root: rootDirAUri, fileUri: 'orange/hamlin', line: 1, character: 33, length: pattern.length, lineText: '' }
|
|
636
|
-
];
|
|
637
|
-
compareSearchResults(expected, client.results);
|
|
638
|
-
done();
|
|
639
|
-
});
|
|
640
|
-
ripgrepServer.setClient(client);
|
|
641
|
-
ripgrepServer.search(pattern, [rootDirAUri], { include: ['orange'], matchWholeWord: true });
|
|
642
|
-
});
|
|
643
|
-
it('should return 1 result when searching for "test" while ignoring all ".txt" files', done => {
|
|
644
|
-
const pattern = 'test';
|
|
645
|
-
const client = new ResultAccumulator(() => {
|
|
646
|
-
const expected = [
|
|
647
|
-
{ root: rootDirAUri, fileUri: 'glob', line: 1, character: 1, length: pattern.length, lineText: '' },
|
|
648
|
-
];
|
|
649
|
-
compareSearchResults(expected, client.results);
|
|
650
|
-
done();
|
|
651
|
-
});
|
|
652
|
-
ripgrepServer.setClient(client);
|
|
653
|
-
ripgrepServer.search(pattern, [rootDirAUri, rootDirBUri], { exclude: ['*.txt'] });
|
|
654
|
-
});
|
|
655
|
-
// Try searching in an UTF-8 file.
|
|
656
|
-
it('should search in a UTF-8 file', done => {
|
|
657
|
-
const pattern = ' jag';
|
|
658
|
-
const client = new ResultAccumulator(() => {
|
|
659
|
-
const expected = [
|
|
660
|
-
{ root: rootDirAUri, fileUri: 'utf8-file', line: 1, character: 7, length: 4, lineText: '' },
|
|
661
|
-
{ root: rootDirAUri, fileUri: 'utf8-file', line: 1, character: 23, length: 4, lineText: '' },
|
|
662
|
-
];
|
|
663
|
-
compareSearchResults(expected, client.results);
|
|
664
|
-
done();
|
|
665
|
-
});
|
|
666
|
-
ripgrepServer.setClient(client);
|
|
667
|
-
ripgrepServer.search(pattern, [rootDirAUri]);
|
|
668
|
-
});
|
|
669
|
-
// Try searching a pattern that contains unicode characters.
|
|
670
|
-
it('should search a UTF-8 pattern', done => {
|
|
671
|
-
const pattern = ' h?är';
|
|
672
|
-
const client = new ResultAccumulator(() => {
|
|
673
|
-
const expected = [
|
|
674
|
-
{ root: rootDirAUri, fileUri: 'utf8-file', line: 1, character: 4, length: 3, lineText: '' },
|
|
675
|
-
{ root: rootDirAUri, fileUri: 'utf8-file', line: 1, character: 20, length: 3, lineText: '' },
|
|
676
|
-
{ root: rootDirAUri, fileUri: 'utf8-file', line: 1, character: 27, length: 4, lineText: '' },
|
|
677
|
-
];
|
|
678
|
-
compareSearchResults(expected, client.results);
|
|
679
|
-
done();
|
|
680
|
-
});
|
|
681
|
-
ripgrepServer.setClient(client);
|
|
682
|
-
ripgrepServer.search(pattern, [rootDirAUri], { useRegExp: true });
|
|
683
|
-
});
|
|
684
|
-
// A regex that may match an empty string should not return zero-length
|
|
685
|
-
// results. Run the test in a directory without big files, because it
|
|
686
|
-
// makes rg print all searched lines, which can take a lot of time.
|
|
687
|
-
it('should not return zero-length matches', done => {
|
|
688
|
-
const pattern = '(hello)?';
|
|
689
|
-
const client = new ResultAccumulator(() => {
|
|
690
|
-
const expected = [];
|
|
691
|
-
compareSearchResults(expected, client.results);
|
|
692
|
-
done();
|
|
693
|
-
});
|
|
694
|
-
ripgrepServer.setClient(client);
|
|
695
|
-
ripgrepServer.search(pattern, [rootDirAUri + '/small']);
|
|
696
|
-
});
|
|
697
|
-
it('should search a pattern with special characters ', done => {
|
|
698
|
-
const pattern = 'salut";\' echo foo && echo bar; "';
|
|
699
|
-
const client = new ResultAccumulator(() => {
|
|
700
|
-
const expected = [
|
|
701
|
-
{ root: rootDirAUri, fileUri: 'special shell characters', line: 1, character: 14, length: 32, lineText: '' },
|
|
702
|
-
];
|
|
703
|
-
compareSearchResults(expected, client.results);
|
|
704
|
-
done();
|
|
705
|
-
});
|
|
706
|
-
ripgrepServer.setClient(client);
|
|
707
|
-
ripgrepServer.search(pattern, [rootDirAUri], { useRegExp: true });
|
|
708
|
-
});
|
|
709
|
-
it('should find patterns across all directories', done => {
|
|
710
|
-
const pattern = 'carrot';
|
|
711
|
-
const client = new ResultAccumulator(() => {
|
|
712
|
-
const expected = [
|
|
713
|
-
{ root: rootDirBUri, fileUri: 'orange', line: 1, character: 51, length: pattern.length, lineText: '' },
|
|
714
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 1, character: 11, length: pattern.length, lineText: '' },
|
|
715
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 6, length: pattern.length, lineText: '' },
|
|
716
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 2, character: 35, length: pattern.length, lineText: '' },
|
|
717
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 28, length: pattern.length, lineText: '' },
|
|
718
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 3, character: 52, length: pattern.length, lineText: '' },
|
|
719
|
-
{ root: rootDirAUri, fileUri: 'carrots', line: 4, character: 1, length: pattern.length, lineText: '' },
|
|
720
|
-
{ root: rootDirAUri, fileUri: 'potatoes', line: 1, character: 18, length: pattern.length, lineText: '' }
|
|
721
|
-
];
|
|
722
|
-
compareSearchResults(expected, client.results);
|
|
723
|
-
done();
|
|
724
|
-
});
|
|
725
|
-
ripgrepServer.setClient(client);
|
|
726
|
-
ripgrepServer.search(pattern, [rootDirAUri, rootDirBUri]);
|
|
727
|
-
});
|
|
728
|
-
it('should only find patterns from the folder closest to the file', done => {
|
|
729
|
-
const pattern = 'folder';
|
|
730
|
-
const client = new ResultAccumulator(() => {
|
|
731
|
-
const expected = [
|
|
732
|
-
{ root: rootSubdirAUri, fileUri: 'folderSubfolder', line: 1, character: 18, length: pattern.length, lineText: '' },
|
|
733
|
-
{ root: rootSubdirAUri, fileUri: 'folderSubfolder', line: 1, character: 30, length: pattern.length, lineText: '' },
|
|
734
|
-
{ root: rootSubdirAUri, fileUri: 'folderSubfolder', line: 1, character: 18, length: pattern.length, lineText: '' },
|
|
735
|
-
{ root: rootSubdirAUri, fileUri: 'folderSubfolder', line: 1, character: 30, length: pattern.length, lineText: '' }
|
|
736
|
-
];
|
|
737
|
-
compareSearchResults(expected, client.results);
|
|
738
|
-
done();
|
|
739
|
-
});
|
|
740
|
-
ripgrepServer.setClient(client);
|
|
741
|
-
ripgrepServer.search(pattern, [rootDirAUri, rootSubdirAUri]);
|
|
742
|
-
});
|
|
743
|
-
it('fails gracefully when rg isn\'t found', async function () {
|
|
744
|
-
const errorString = await new Promise((resolve, reject) => {
|
|
745
|
-
const rgServer = createInstance('/non-existent/rg');
|
|
746
|
-
rgServer.setClient({
|
|
747
|
-
onResult: (searchId, result) => {
|
|
748
|
-
reject();
|
|
749
|
-
},
|
|
750
|
-
onDone: (searchId, error) => {
|
|
751
|
-
if (typeof error === 'string') {
|
|
752
|
-
resolve(error);
|
|
753
|
-
}
|
|
754
|
-
else {
|
|
755
|
-
reject();
|
|
756
|
-
}
|
|
757
|
-
},
|
|
758
|
-
});
|
|
759
|
-
rgServer.search('pattern', [rootDirA]);
|
|
760
|
-
});
|
|
761
|
-
(0, chai_1.expect)(errorString).contains('could not find the ripgrep (rg) binary');
|
|
762
|
-
});
|
|
763
|
-
it('fails gracefully when rg isn\'t executable', async function () {
|
|
764
|
-
const errorString = await new Promise((resolve, reject) => {
|
|
765
|
-
// Create temporary file, ensure it is not executable.
|
|
766
|
-
const rg = temp.openSync();
|
|
767
|
-
let mode = fs.fstatSync(rg.fd).mode;
|
|
768
|
-
mode &= ~(fs.constants.S_IXUSR | fs.constants.S_IXGRP | fs.constants.S_IXOTH);
|
|
769
|
-
fs.fchmodSync(rg.fd, mode);
|
|
770
|
-
fs.closeSync(rg.fd);
|
|
771
|
-
const rgServer = createInstance(rg.path);
|
|
772
|
-
rgServer.setClient({
|
|
773
|
-
onResult: (searchId, result) => {
|
|
774
|
-
reject();
|
|
775
|
-
},
|
|
776
|
-
onDone: (searchId, error) => {
|
|
777
|
-
if (typeof error === 'string') {
|
|
778
|
-
resolve(error);
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
reject();
|
|
782
|
-
}
|
|
783
|
-
},
|
|
784
|
-
});
|
|
785
|
-
rgServer.search('pattern', [rootDirA]);
|
|
786
|
-
});
|
|
787
|
-
if (core_1.isWindows) {
|
|
788
|
-
(0, chai_1.expect)(errorString).contains('An error happened while searching');
|
|
789
|
-
}
|
|
790
|
-
else {
|
|
791
|
-
(0, chai_1.expect)(errorString).contains('could not execute the ripgrep (rg) binary');
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
});
|
|
795
|
-
describe('#extractSearchPathsFromIncludes', function () {
|
|
796
|
-
this.timeout(10000);
|
|
797
|
-
it('should not resolve paths from a not absolute / relative pattern', async () => {
|
|
798
|
-
const pattern = 'carrots';
|
|
799
|
-
const options = { include: [pattern] };
|
|
800
|
-
const searchPaths = await ripgrepServer['extractSearchPathsFromIncludes']([rootDirA], options);
|
|
801
|
-
// Same root directory
|
|
802
|
-
(0, chai_1.expect)(searchPaths.length).equal(1);
|
|
803
|
-
(0, chai_1.expect)(searchPaths[0]).equal(rootDirA);
|
|
804
|
-
// Pattern is unchanged
|
|
805
|
-
(0, chai_1.expect)(options.include.length).equal(1);
|
|
806
|
-
(0, chai_1.expect)(options.include[0]).equals(pattern);
|
|
807
|
-
});
|
|
808
|
-
it('should resolve pattern to path for relative filename', async () => {
|
|
809
|
-
const filename = 'carrots';
|
|
810
|
-
const pattern = `./${filename}`;
|
|
811
|
-
await checkResolvedPathForPattern(pattern, path.join(rootDirA, filename));
|
|
812
|
-
});
|
|
813
|
-
it('should resolve relative pattern with sub-folders glob', async () => {
|
|
814
|
-
const filename = 'carrots';
|
|
815
|
-
const pattern = `./${filename}/**`;
|
|
816
|
-
await checkResolvedPathForPattern(pattern, path.join(rootDirA, filename));
|
|
817
|
-
});
|
|
818
|
-
it('should resolve absolute path pattern', async () => {
|
|
819
|
-
const pattern = `${rootDirA}/carrots`;
|
|
820
|
-
await checkResolvedPathForPattern(pattern, pattern);
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
describe('#addGlobArgs', function () {
|
|
824
|
-
this.timeout(10000);
|
|
825
|
-
it('should resolve path to glob - filename', function () {
|
|
826
|
-
[true, false].forEach(excludeFlag => {
|
|
827
|
-
const excludePrefix = excludeFlag ? '!' : '';
|
|
828
|
-
const filename = 'carrots';
|
|
829
|
-
const expected = [
|
|
830
|
-
`--glob=${excludePrefix}**/${filename}`,
|
|
831
|
-
`--glob=${excludePrefix}**/${filename}/*`
|
|
832
|
-
];
|
|
833
|
-
const actual = new Set();
|
|
834
|
-
ripgrepServer['addGlobArgs'](actual, [filename], excludeFlag);
|
|
835
|
-
(0, chai_1.expect)(expected).to.have.deep.members([...actual]);
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
it('should resolve path to glob - glob prefixed folder', function () {
|
|
839
|
-
[true, false].forEach(excludeFlag => {
|
|
840
|
-
const excludePrefix = excludeFlag ? '!' : '';
|
|
841
|
-
const filename = 'carrots';
|
|
842
|
-
const inputPath = `**/${filename}/`;
|
|
843
|
-
const expected = [
|
|
844
|
-
`--glob=${excludePrefix}**/${filename}/`,
|
|
845
|
-
`--glob=${excludePrefix}**/${filename}/*`
|
|
846
|
-
];
|
|
847
|
-
const actual = new Set();
|
|
848
|
-
ripgrepServer['addGlobArgs'](actual, [inputPath], excludeFlag);
|
|
849
|
-
(0, chai_1.expect)(expected).to.have.deep.members([...actual]);
|
|
850
|
-
});
|
|
851
|
-
});
|
|
852
|
-
it('should resolve path to glob - path segment', function () {
|
|
853
|
-
[true, false].forEach(excludeFlag => {
|
|
854
|
-
const excludePrefix = excludeFlag ? '!' : '';
|
|
855
|
-
const filename = 'carrots';
|
|
856
|
-
const inputPath = `/${filename}`;
|
|
857
|
-
const expected = [
|
|
858
|
-
`--glob=${excludePrefix}**/${filename}`,
|
|
859
|
-
`--glob=${excludePrefix}**/${filename}/*`
|
|
860
|
-
];
|
|
861
|
-
const actual = new Set();
|
|
862
|
-
ripgrepServer['addGlobArgs'](actual, [inputPath], excludeFlag);
|
|
863
|
-
(0, chai_1.expect)(expected).to.have.deep.members([...actual]);
|
|
864
|
-
});
|
|
865
|
-
});
|
|
866
|
-
it('should resolve path to glob - already a glob', function () {
|
|
867
|
-
[true, false].forEach(excludeFlag => {
|
|
868
|
-
const excludePrefix = excludeFlag ? '!' : '';
|
|
869
|
-
const filename = 'carrots';
|
|
870
|
-
const inputPath = `${filename}/**/*`;
|
|
871
|
-
const expected = [
|
|
872
|
-
`--glob=${excludePrefix}**/${filename}/**/*`,
|
|
873
|
-
];
|
|
874
|
-
const actual = new Set();
|
|
875
|
-
ripgrepServer['addGlobArgs'](actual, [inputPath], excludeFlag);
|
|
876
|
-
(0, chai_1.expect)(expected).to.have.deep.members([...actual]);
|
|
877
|
-
});
|
|
878
|
-
});
|
|
879
|
-
it('should resolve path to glob - path segment glob suffixed', function () {
|
|
880
|
-
[true, false].forEach(excludeFlag => {
|
|
881
|
-
const excludePrefix = excludeFlag ? '!' : '';
|
|
882
|
-
const filename = 'carrots';
|
|
883
|
-
const inputPath = `/${filename}/**/*`;
|
|
884
|
-
const expected = [
|
|
885
|
-
`--glob=${excludePrefix}**/${filename}/**/*`,
|
|
886
|
-
];
|
|
887
|
-
const actual = new Set();
|
|
888
|
-
ripgrepServer['addGlobArgs'](actual, [inputPath], excludeFlag);
|
|
889
|
-
(0, chai_1.expect)(expected).to.have.deep.members([...actual]);
|
|
890
|
-
});
|
|
891
|
-
});
|
|
892
|
-
});
|
|
893
|
-
async function checkResolvedPathForPattern(pattern, expectedPath) {
|
|
894
|
-
const options = { include: [pattern] };
|
|
895
|
-
const searchPaths = await ripgrepServer['extractSearchPathsFromIncludes']([rootDirA], options);
|
|
896
|
-
(0, chai_1.expect)(searchPaths.length).equal(1, 'searchPath result should contain exactly one element');
|
|
897
|
-
(0, chai_1.expect)(options.include.length).equals(0, 'options.include should be empty');
|
|
898
|
-
(0, chai_1.expect)(searchPaths[0]).equal(path.normalize(expectedPath));
|
|
899
|
-
}
|
|
900
|
-
//# sourceMappingURL=ripgrep-search-in-workspace-server.slow-spec.js.map
|