@theia/search-in-workspace 1.45.1 → 1.46.0-next.72

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.
Files changed (58) hide show
  1. package/README.md +40 -40
  2. package/lib/browser/components/search-in-workspace-input.d.ts +39 -39
  3. package/lib/browser/components/search-in-workspace-input.js +123 -123
  4. package/lib/browser/components/search-in-workspace-textarea.d.ts +39 -39
  5. package/lib/browser/components/search-in-workspace-textarea.js +130 -130
  6. package/lib/browser/search-in-workspace-context-key-service.d.ts +23 -23
  7. package/lib/browser/search-in-workspace-context-key-service.js +90 -90
  8. package/lib/browser/search-in-workspace-factory.d.ts +10 -10
  9. package/lib/browser/search-in-workspace-factory.js +68 -68
  10. package/lib/browser/search-in-workspace-frontend-contribution.d.ts +57 -55
  11. package/lib/browser/search-in-workspace-frontend-contribution.d.ts.map +1 -1
  12. package/lib/browser/search-in-workspace-frontend-contribution.js +516 -482
  13. package/lib/browser/search-in-workspace-frontend-contribution.js.map +1 -1
  14. package/lib/browser/search-in-workspace-frontend-module.d.ts +6 -6
  15. package/lib/browser/search-in-workspace-frontend-module.js +71 -71
  16. package/lib/browser/search-in-workspace-label-provider.d.ts +9 -9
  17. package/lib/browser/search-in-workspace-label-provider.js +57 -57
  18. package/lib/browser/search-in-workspace-preferences.d.ts +17 -17
  19. package/lib/browser/search-in-workspace-preferences.js +87 -87
  20. package/lib/browser/search-in-workspace-result-tree-widget.d.ts +259 -255
  21. package/lib/browser/search-in-workspace-result-tree-widget.d.ts.map +1 -1
  22. package/lib/browser/search-in-workspace-result-tree-widget.js +1172 -1099
  23. package/lib/browser/search-in-workspace-result-tree-widget.js.map +1 -1
  24. package/lib/browser/search-in-workspace-service.d.ts +35 -35
  25. package/lib/browser/search-in-workspace-service.js +158 -158
  26. package/lib/browser/search-in-workspace-widget.d.ts +121 -121
  27. package/lib/browser/search-in-workspace-widget.js +629 -629
  28. package/lib/browser/search-layout-migrations.d.ts +5 -5
  29. package/lib/browser/search-layout-migrations.js +64 -64
  30. package/lib/common/search-in-workspace-interface.d.ts +116 -116
  31. package/lib/common/search-in-workspace-interface.js +35 -35
  32. package/lib/node/ripgrep-search-in-workspace-server.d.ts +94 -94
  33. package/lib/node/ripgrep-search-in-workspace-server.js +430 -430
  34. package/lib/node/ripgrep-search-in-workspace-server.js.map +1 -1
  35. package/lib/node/ripgrep-search-in-workspace-server.slow-spec.d.ts +1 -1
  36. package/lib/node/ripgrep-search-in-workspace-server.slow-spec.js +899 -899
  37. package/lib/node/ripgrep-search-in-workspace-server.slow-spec.js.map +1 -1
  38. package/lib/node/search-in-workspace-backend-module.d.ts +3 -3
  39. package/lib/node/search-in-workspace-backend-module.js +32 -32
  40. package/package.json +9 -9
  41. package/src/browser/components/search-in-workspace-input.tsx +139 -139
  42. package/src/browser/components/search-in-workspace-textarea.tsx +153 -153
  43. package/src/browser/search-in-workspace-context-key-service.ts +93 -93
  44. package/src/browser/search-in-workspace-factory.ts +59 -59
  45. package/src/browser/search-in-workspace-frontend-contribution.ts +510 -474
  46. package/src/browser/search-in-workspace-frontend-module.ts +83 -83
  47. package/src/browser/search-in-workspace-label-provider.ts +48 -48
  48. package/src/browser/search-in-workspace-preferences.ts +96 -96
  49. package/src/browser/search-in-workspace-result-tree-widget.tsx +1318 -1245
  50. package/src/browser/search-in-workspace-service.ts +152 -152
  51. package/src/browser/search-in-workspace-widget.tsx +727 -727
  52. package/src/browser/search-layout-migrations.ts +53 -53
  53. package/src/browser/styles/index.css +400 -400
  54. package/src/browser/styles/search.svg +6 -6
  55. package/src/common/search-in-workspace-interface.ts +153 -153
  56. package/src/node/ripgrep-search-in-workspace-server.slow-spec.ts +1073 -1073
  57. package/src/node/ripgrep-search-in-workspace-server.ts +490 -490
  58. package/src/node/search-in-workspace-backend-module.ts +33 -33
@@ -1,152 +1,152 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017-2018 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
- import {
19
- SearchInWorkspaceServer,
20
- SearchInWorkspaceClient,
21
- SearchInWorkspaceResult,
22
- SearchInWorkspaceOptions
23
- } from '../common/search-in-workspace-interface';
24
- import { WorkspaceService } from '@theia/workspace/lib/browser';
25
- import { ILogger } from '@theia/core';
26
-
27
- /**
28
- * Class that will receive the search results from the server. This is separate
29
- * from the SearchInWorkspaceService class only to avoid a cycle in the
30
- * dependency injection.
31
- */
32
-
33
- @injectable()
34
- export class SearchInWorkspaceClientImpl implements SearchInWorkspaceClient {
35
- private service: SearchInWorkspaceClient;
36
-
37
- onResult(searchId: number, result: SearchInWorkspaceResult): void {
38
- this.service.onResult(searchId, result);
39
- }
40
- onDone(searchId: number, error?: string): void {
41
- this.service.onDone(searchId, error);
42
- }
43
-
44
- setService(service: SearchInWorkspaceClient): void {
45
- this.service = service;
46
- }
47
- }
48
-
49
- export type SearchInWorkspaceCallbacks = SearchInWorkspaceClient;
50
-
51
- /**
52
- * Service to search text in the workspace files.
53
- */
54
- @injectable()
55
- export class SearchInWorkspaceService implements SearchInWorkspaceClient {
56
-
57
- // All the searches that we have started, that are not done yet (onDone
58
- // with that searchId has not been called).
59
- private pendingSearches = new Map<number, SearchInWorkspaceCallbacks>();
60
-
61
- // Due to the asynchronicity of the node backend, it's possible that we
62
- // start a search, receive an event for that search, and then receive
63
- // the search id for that search.We therefore need to keep those
64
- // events until we get the search id and return it to the caller.
65
- // Otherwise the caller would discard the event because it doesn't know
66
- // the search id yet.
67
- private pendingOnDones: Map<number, string | undefined> = new Map();
68
-
69
- private lastKnownSearchId: number = -1;
70
-
71
- @inject(SearchInWorkspaceServer) protected readonly searchServer: SearchInWorkspaceServer;
72
- @inject(SearchInWorkspaceClientImpl) protected readonly client: SearchInWorkspaceClientImpl;
73
- @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
74
- @inject(ILogger) protected readonly logger: ILogger;
75
-
76
- @postConstruct()
77
- protected init(): void {
78
- this.client.setService(this);
79
- }
80
-
81
- isEnabled(): boolean {
82
- return this.workspaceService.opened;
83
- }
84
-
85
- onResult(searchId: number, result: SearchInWorkspaceResult): void {
86
- const callbacks = this.pendingSearches.get(searchId);
87
-
88
- if (callbacks) {
89
- callbacks.onResult(searchId, result);
90
- }
91
- }
92
-
93
- onDone(searchId: number, error?: string): void {
94
- const callbacks = this.pendingSearches.get(searchId);
95
-
96
- if (callbacks) {
97
- this.pendingSearches.delete(searchId);
98
- callbacks.onDone(searchId, error);
99
- } else {
100
- if (searchId > this.lastKnownSearchId) {
101
- this.logger.debug(`Got an onDone for a searchId we don't know about (${searchId}), stashing it for later with error = `, error);
102
- this.pendingOnDones.set(searchId, error);
103
- } else {
104
- // It's possible to receive an onDone for a search we have cancelled. Just ignore it.
105
- this.logger.debug(`Got an onDone for a searchId we don't know about (${searchId}), but it's probably an old one, error = `, error);
106
- }
107
- }
108
- }
109
-
110
- // Start a search of the string "what" in the workspace.
111
- async search(what: string, callbacks: SearchInWorkspaceCallbacks, opts?: SearchInWorkspaceOptions): Promise<number> {
112
- if (!this.workspaceService.opened) {
113
- throw new Error('Search failed: no workspace root.');
114
- }
115
-
116
- const roots = await this.workspaceService.roots;
117
- return this.doSearch(what, roots.map(r => r.resource.toString()), callbacks, opts);
118
- }
119
-
120
- protected async doSearch(what: string, rootsUris: string[], callbacks: SearchInWorkspaceCallbacks, opts?: SearchInWorkspaceOptions): Promise<number> {
121
- const searchId = await this.searchServer.search(what, rootsUris, opts);
122
- this.pendingSearches.set(searchId, callbacks);
123
- this.lastKnownSearchId = searchId;
124
-
125
- this.logger.debug('Service launched search ' + searchId);
126
-
127
- // Check if we received an onDone before search() returned.
128
- if (this.pendingOnDones.has(searchId)) {
129
- this.logger.debug('Ohh, we have a stashed onDone for that searchId');
130
- const error = this.pendingOnDones.get(searchId);
131
- this.pendingOnDones.delete(searchId);
132
-
133
- // Call the client's searchId, but first give it a
134
- // chance to record the returned searchId.
135
- setTimeout(() => {
136
- this.onDone(searchId, error);
137
- }, 0);
138
- }
139
-
140
- return searchId;
141
- }
142
-
143
- async searchWithCallback(what: string, rootsUris: string[], callbacks: SearchInWorkspaceClient, opts?: SearchInWorkspaceOptions | undefined): Promise<number> {
144
- return this.doSearch(what, rootsUris, callbacks, opts);
145
- }
146
-
147
- // Cancel an ongoing search.
148
- cancel(searchId: number): void {
149
- this.pendingSearches.delete(searchId);
150
- this.searchServer.cancel(searchId);
151
- }
152
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017-2018 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
+ import {
19
+ SearchInWorkspaceServer,
20
+ SearchInWorkspaceClient,
21
+ SearchInWorkspaceResult,
22
+ SearchInWorkspaceOptions
23
+ } from '../common/search-in-workspace-interface';
24
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
25
+ import { ILogger } from '@theia/core';
26
+
27
+ /**
28
+ * Class that will receive the search results from the server. This is separate
29
+ * from the SearchInWorkspaceService class only to avoid a cycle in the
30
+ * dependency injection.
31
+ */
32
+
33
+ @injectable()
34
+ export class SearchInWorkspaceClientImpl implements SearchInWorkspaceClient {
35
+ private service: SearchInWorkspaceClient;
36
+
37
+ onResult(searchId: number, result: SearchInWorkspaceResult): void {
38
+ this.service.onResult(searchId, result);
39
+ }
40
+ onDone(searchId: number, error?: string): void {
41
+ this.service.onDone(searchId, error);
42
+ }
43
+
44
+ setService(service: SearchInWorkspaceClient): void {
45
+ this.service = service;
46
+ }
47
+ }
48
+
49
+ export type SearchInWorkspaceCallbacks = SearchInWorkspaceClient;
50
+
51
+ /**
52
+ * Service to search text in the workspace files.
53
+ */
54
+ @injectable()
55
+ export class SearchInWorkspaceService implements SearchInWorkspaceClient {
56
+
57
+ // All the searches that we have started, that are not done yet (onDone
58
+ // with that searchId has not been called).
59
+ private pendingSearches = new Map<number, SearchInWorkspaceCallbacks>();
60
+
61
+ // Due to the asynchronicity of the node backend, it's possible that we
62
+ // start a search, receive an event for that search, and then receive
63
+ // the search id for that search.We therefore need to keep those
64
+ // events until we get the search id and return it to the caller.
65
+ // Otherwise the caller would discard the event because it doesn't know
66
+ // the search id yet.
67
+ private pendingOnDones: Map<number, string | undefined> = new Map();
68
+
69
+ private lastKnownSearchId: number = -1;
70
+
71
+ @inject(SearchInWorkspaceServer) protected readonly searchServer: SearchInWorkspaceServer;
72
+ @inject(SearchInWorkspaceClientImpl) protected readonly client: SearchInWorkspaceClientImpl;
73
+ @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
74
+ @inject(ILogger) protected readonly logger: ILogger;
75
+
76
+ @postConstruct()
77
+ protected init(): void {
78
+ this.client.setService(this);
79
+ }
80
+
81
+ isEnabled(): boolean {
82
+ return this.workspaceService.opened;
83
+ }
84
+
85
+ onResult(searchId: number, result: SearchInWorkspaceResult): void {
86
+ const callbacks = this.pendingSearches.get(searchId);
87
+
88
+ if (callbacks) {
89
+ callbacks.onResult(searchId, result);
90
+ }
91
+ }
92
+
93
+ onDone(searchId: number, error?: string): void {
94
+ const callbacks = this.pendingSearches.get(searchId);
95
+
96
+ if (callbacks) {
97
+ this.pendingSearches.delete(searchId);
98
+ callbacks.onDone(searchId, error);
99
+ } else {
100
+ if (searchId > this.lastKnownSearchId) {
101
+ this.logger.debug(`Got an onDone for a searchId we don't know about (${searchId}), stashing it for later with error = `, error);
102
+ this.pendingOnDones.set(searchId, error);
103
+ } else {
104
+ // It's possible to receive an onDone for a search we have cancelled. Just ignore it.
105
+ this.logger.debug(`Got an onDone for a searchId we don't know about (${searchId}), but it's probably an old one, error = `, error);
106
+ }
107
+ }
108
+ }
109
+
110
+ // Start a search of the string "what" in the workspace.
111
+ async search(what: string, callbacks: SearchInWorkspaceCallbacks, opts?: SearchInWorkspaceOptions): Promise<number> {
112
+ if (!this.workspaceService.opened) {
113
+ throw new Error('Search failed: no workspace root.');
114
+ }
115
+
116
+ const roots = await this.workspaceService.roots;
117
+ return this.doSearch(what, roots.map(r => r.resource.toString()), callbacks, opts);
118
+ }
119
+
120
+ protected async doSearch(what: string, rootsUris: string[], callbacks: SearchInWorkspaceCallbacks, opts?: SearchInWorkspaceOptions): Promise<number> {
121
+ const searchId = await this.searchServer.search(what, rootsUris, opts);
122
+ this.pendingSearches.set(searchId, callbacks);
123
+ this.lastKnownSearchId = searchId;
124
+
125
+ this.logger.debug('Service launched search ' + searchId);
126
+
127
+ // Check if we received an onDone before search() returned.
128
+ if (this.pendingOnDones.has(searchId)) {
129
+ this.logger.debug('Ohh, we have a stashed onDone for that searchId');
130
+ const error = this.pendingOnDones.get(searchId);
131
+ this.pendingOnDones.delete(searchId);
132
+
133
+ // Call the client's searchId, but first give it a
134
+ // chance to record the returned searchId.
135
+ setTimeout(() => {
136
+ this.onDone(searchId, error);
137
+ }, 0);
138
+ }
139
+
140
+ return searchId;
141
+ }
142
+
143
+ async searchWithCallback(what: string, rootsUris: string[], callbacks: SearchInWorkspaceClient, opts?: SearchInWorkspaceOptions | undefined): Promise<number> {
144
+ return this.doSearch(what, rootsUris, callbacks, opts);
145
+ }
146
+
147
+ // Cancel an ongoing search.
148
+ cancel(searchId: number): void {
149
+ this.pendingSearches.delete(searchId);
150
+ this.searchServer.cancel(searchId);
151
+ }
152
+ }