Skip to content

Commit 747c01a

Browse files
committed
Rename api manager view and related components to chats
- rename 'api manager' view to 'chats', including folder name and ui - it's been reported that when searching for keywords in contents, for keyword "avif" we got images x.avif found - never show progress notification when searching in 'filename' (as these are very fast) - negative keywords should use "-" prefix - Don't require keywords to be comma separated, space should also do fine. Stop emphasizing the need to separate by commas. - in keyword search: implement 1) multi exact phrases "yellow banana" 2) Excluding Exact Phrases: If you want to exclude a specific multi-word phrase, wrap the phrase in quotation marks and place the minus sign directly in front of it.Example: marketing jobs -"entry level" - there are some repetitions e.g. [Fragment] - [Fragment] should accept params variable, don't destructure in body - in keywords searching placeholder give a perfect example showcasing a mix of: keyword, phrase, negated keyword and negated phrase. use fruit-oriented example that make logical sense.
1 parent 4650aea commit 747c01a

26 files changed

Lines changed: 284 additions & 200 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@
5353
"viewsContainers": {
5454
"activitybar": [
5555
{
56-
"id": "codeWebChat",
56+
"id": "activitybar",
5757
"title": "Code Web Chat",
5858
"icon": "resources/activity-bar-icon.svg"
5959
}
6060
],
6161
"secondarySidebar": [
6262
{
63-
"id": "apiManager",
64-
"title": "API Manager",
63+
"id": "secondarySidebar",
64+
"title": "Chats",
6565
"icon": "resources/activity-bar-icon.svg"
6666
}
6767
]
6868
},
6969
"views": {
70-
"codeWebChat": [
70+
"activitybar": [
7171
{
7272
"id": "codeWebChatViewOpenEditors",
7373
"name": "Open Editors",
@@ -95,10 +95,10 @@
9595
"initialSize": 5
9696
}
9797
],
98-
"apiManager": [
98+
"secondarySidebar": [
9999
{
100-
"id": "apiManagerView",
101-
"name": "API Manager",
100+
"id": "chatsView",
101+
"name": "Chats",
102102
"type": "webview",
103103
"icon": "resources/activity-bar-icon.svg",
104104
"initialSize": 1

‎apps/editor/src/constants/state-keys.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export const TEMPORARY_CHECKPOINT_STATE_KEY = 'temporary-checkpoint'
2828
export const CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY =
2929
'checkpoint-operation-in-progress'
3030

31-
export const API_MANAGER_VIEW_CHAT_HISTORY_STATE_KEY =
32-
'api-manager-chat-history'
31+
export const CHATS_VIEW_CHAT_HISTORY_STATE_KEY = 'chats-view-chat-history'
3332

3433
export const DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY =
3534
'duplicate-workspace-context'

‎apps/editor/src/extension.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode'
22
import { context_initialization } from './context/context-initialization'
33
import { PanelViewProvider } from './views/panel/backend/panel-view-provider'
44
import { WebSocketManager } from './services/websocket-manager'
5-
import { ApiManagerViewProvider } from './views/api-manager/backend/api-manager-view-provider'
5+
import { ChatsViewProvider } from './views/chats/backend/chats-view-provider'
66
import { ApiManager } from './services/api-manager'
77
import {
88
migrate_configurations_to_api_configurations,
@@ -75,17 +75,14 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
7575
shared_context_state
7676
})
7777

78-
const api_manager_view_provider = new ApiManagerViewProvider(
78+
const chats_view_provider = new ChatsViewProvider(
7979
extension_context.extensionUri,
8080
extension_context
8181
)
8282

83-
const api_manager = new ApiManager(
84-
panel_view_provider,
85-
api_manager_view_provider
86-
)
83+
const api_manager = new ApiManager(panel_view_provider, chats_view_provider)
8784

88-
api_manager_view_provider.set_api_manager(api_manager)
85+
chats_view_provider.set_api_manager(api_manager)
8986

9087
extension_context.subscriptions.push(
9188
vscode.window.registerWebviewViewProvider(
@@ -98,8 +95,8 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
9895
}
9996
),
10097
vscode.window.registerWebviewViewProvider(
101-
'apiManagerView',
102-
api_manager_view_provider,
98+
'chatsView',
99+
chats_view_provider,
103100
{
104101
webviewOptions: {
105102
retainContextWhenHidden: true

‎apps/editor/src/features/search-files/actions/search-files.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ export const search_files = async (params: {
213213
let is_cancelled = false
214214
let matched_files: string[] = []
215215

216-
const is_small_search =
217-
(search_mode == 'phrase' || search_mode == 'keywords') &&
218-
files.length < 1000
216+
const is_fast_search =
217+
(search_mode == 'keywords' && keywords_target == 'filenames') ||
218+
((search_mode == 'phrase' || search_mode == 'keywords') &&
219+
files.length < 100)
219220

220-
if (is_small_search) {
221+
if (is_fast_search) {
221222
matched_files = await search_files_by_term({
222223
files,
223224
search_term,

‎apps/editor/src/features/search-files/utils/analyze-files.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export const analyze_files = async (params: {
4040
const stats = await fs.promises.stat(file_path)
4141
if (stats.size > 1024 * 1024) continue
4242

43-
const content = await fs.promises.readFile(file_path, 'utf8')
43+
const buffer = await fs.promises.readFile(file_path)
44+
if (buffer.includes(0)) continue
45+
46+
const content = buffer.toString('utf8')
4447
const shrunk_content = shrink_file(content, path.extname(file_path))
4548

4649
const workspace_root =

‎apps/editor/src/features/search-files/utils/prompt-for-search-term.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const prompt_for_search_term = async (
3333
: mode == 'semantic'
3434
? t('feature.search-files.prompt.semantic')
3535
: t('feature.search-files.prompt')
36-
input_box.placeholder = t('feature.search-files.placeholder')
36+
input_box.placeholder =
37+
mode == 'keywords'
38+
? t('feature.search-files.placeholder.keywords')
39+
: t('feature.search-files.placeholder')
3740
input_box.value = initial_search_term
3841
input_box.ignoreFocusOut = true
3942
input_box.buttons = [vscode.QuickInputButtons.Back, close_button]

‎apps/editor/src/features/search-files/utils/search-files-by-term.ts‎

Lines changed: 78 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,40 @@ import { LIMIT_SEMANTIC_SEARCH_RESULTS } from '@/constants/values'
1010

1111
const exec_promise = promisify(exec)
1212

13+
const get_keyword_regexes = (search_term: string) => {
14+
const keywords = (
15+
search_term.match(/(?:-?"[^"]*")|(?:-?[^\s,]+)/g) || []
16+
).filter((k) => k.length > 0)
17+
18+
const positive_keywords = keywords.filter((k) => !k.startsWith('-'))
19+
const negative_keywords = keywords
20+
.filter((k) => k.startsWith('-'))
21+
.map((k) => k.slice(1))
22+
23+
return {
24+
positive_regexes: positive_keywords.map((k) => create_search_regex(k)),
25+
negative_regexes: negative_keywords.map((k) => create_search_regex(k))
26+
}
27+
}
28+
29+
const check_matches_condition = (params: {
30+
text: string
31+
positive_regexes: RegExp[]
32+
negative_regexes: RegExp[]
33+
match_mode?: 'all' | 'some'
34+
}) => {
35+
if (params.negative_regexes.some((r) => r.test(params.text))) {
36+
return false
37+
}
38+
if (params.positive_regexes.length == 0) {
39+
return true
40+
}
41+
if (params.match_mode == 'some') {
42+
return params.positive_regexes.some((r) => r.test(params.text))
43+
}
44+
return params.positive_regexes.every((r) => r.test(params.text))
45+
}
46+
1347
export const search_files_by_term = async (params: {
1448
files: string[]
1549
search_term: string
@@ -75,38 +109,12 @@ export const search_files_by_term = async (params: {
75109
params.search_mode == 'keywords' &&
76110
params.keywords_target == 'filenames'
77111
) {
78-
const keywords = params.search_term
79-
.split(',')
80-
.map((k) => k.trim())
81-
.filter((k) => k.length > 0)
82-
83-
const positive_keywords = keywords.filter((k) => !k.startsWith('!'))
84-
const negative_keywords = keywords
85-
.filter((k) => k.startsWith('!'))
86-
.map((k) => k.slice(1))
87-
88-
const positive_regexes = positive_keywords.map((k) =>
89-
create_search_regex(k)
90-
)
91-
const negative_regexes = negative_keywords.map((k) =>
92-
create_search_regex(k)
112+
const { positive_regexes, negative_regexes } = get_keyword_regexes(
113+
params.search_term
93114
)
94115

95116
if (positive_regexes.length == 0 && negative_regexes.length == 0) return []
96117

97-
const matches_condition = (text: string) => {
98-
if (negative_regexes.some((r) => r.test(text))) {
99-
return false
100-
}
101-
if (positive_regexes.length == 0) {
102-
return true
103-
}
104-
if (params.keywords_match_mode == 'some') {
105-
return positive_regexes.some((r) => r.test(text))
106-
}
107-
return positive_regexes.every((r) => r.test(text))
108-
}
109-
110118
for (const file_path of params.files) {
111119
if (params.token?.isCancellationRequested) break
112120

@@ -117,7 +125,14 @@ export const search_files_by_term = async (params: {
117125
continue
118126
}
119127

120-
if (matches_condition(file_name)) {
128+
if (
129+
check_matches_condition({
130+
text: file_name,
131+
positive_regexes,
132+
negative_regexes,
133+
match_mode: params.keywords_match_mode
134+
})
135+
) {
121136
matched_files.push(file_path)
122137
}
123138
} catch (error) {
@@ -136,39 +151,17 @@ export const search_files_by_term = async (params: {
136151
let negative_regexes: RegExp[] = []
137152

138153
if (params.search_mode == 'keywords') {
139-
const keywords = params.search_term
140-
.split(',')
141-
.map((k) => k.trim())
142-
.filter((k) => k.length > 0)
143-
144-
const positive_keywords = keywords.filter((k) => !k.startsWith('!'))
145-
const negative_keywords = keywords
146-
.filter((k) => k.startsWith('!'))
147-
.map((k) => k.slice(1))
148-
149-
positive_regexes = positive_keywords.map((k) => create_search_regex(k))
150-
negative_regexes = negative_keywords.map((k) => create_search_regex(k))
154+
const regexes = get_keyword_regexes(params.search_term)
155+
positive_regexes = regexes.positive_regexes
156+
negative_regexes = regexes.negative_regexes
151157
} else {
152158
positive_regexes = [create_search_regex(params.search_term)]
153159
}
154160

155161
if (positive_regexes.length == 0 && negative_regexes.length == 0) return []
156162

157-
const matches_condition = (text: string) => {
158-
if (negative_regexes.some((r) => r.test(text))) {
159-
return false
160-
}
161-
if (positive_regexes.length == 0) {
162-
return true
163-
}
164-
if (
165-
params.search_mode == 'keywords' &&
166-
params.keywords_match_mode == 'some'
167-
) {
168-
return positive_regexes.some((r) => r.test(text))
169-
}
170-
return positive_regexes.every((r) => r.test(text))
171-
}
163+
const match_mode =
164+
params.search_mode == 'keywords' ? params.keywords_match_mode : undefined
172165

173166
let processed = 0
174167
for (const file_path of params.files) {
@@ -200,18 +193,39 @@ export const search_files_by_term = async (params: {
200193
continue
201194
}
202195
} else {
203-
const content = await fs.promises.readFile(file_path, 'utf-8')
204-
if (
205-
params.search_mode == 'keywords' &&
206-
params.keywords_target == 'both'
207-
) {
208-
text_to_check = file_name + '\n' + content
196+
const buffer = await fs.promises.readFile(file_path)
197+
const is_binary = buffer.includes(0)
198+
199+
if (is_binary) {
200+
if (
201+
params.search_mode == 'keywords' &&
202+
params.keywords_target == 'both'
203+
) {
204+
text_to_check = file_name
205+
} else {
206+
continue
207+
}
209208
} else {
210-
text_to_check = content
209+
const content = buffer.toString('utf-8')
210+
if (
211+
params.search_mode == 'keywords' &&
212+
params.keywords_target == 'both'
213+
) {
214+
text_to_check = file_name + '\n' + content
215+
} else {
216+
text_to_check = content
217+
}
211218
}
212219
}
213220

214-
if (matches_condition(text_to_check)) {
221+
if (
222+
check_matches_condition({
223+
text: text_to_check,
224+
positive_regexes,
225+
negative_regexes,
226+
match_mode
227+
})
228+
) {
215229
matched_files.push(file_path)
216230
}
217231
} catch (error) {

0 commit comments

Comments
 (0)