Skip to content

Commit e9abd01

Browse files
committed
Normalize extracted paths and improve workspace file matching in extract paths from text
- such file is not listed [Pasted text] ├── apps │ └── editor │ └── src │ ├── commands │ │ └── select-clipboard-paths-command.ts │ ├── context │ │ ├── helpers │ │ │ └── get-all-workspace-files.ts │ │ └── providers │ │ └── workspace │ │ └── workspace-provider.ts │ ├── features │ │ └── search-files │ │ ├── index.ts │ │ └── search-files.ts │ ├── i18n │ │ └── index.ts │ ├── services │ │ └── websocket-manager.ts │ └── utils │ ├── extract-paths-from-text │ │ ├── extract-paths-from-text.ts │ │ └── index.ts │ └── get-error-message.ts └── packages └── shared └── src └── utils ├── display-token-count.ts └── logger.ts
1 parent f7a4862 commit e9abd01

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎apps/editor/src/utils/extract-paths-from-text/extract-paths-from-text.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ export const extract_paths_from_text = (params: {
4242

4343
for (const original_p of found_paths) {
4444
let p = original_p
45+
46+
p = p.replace(/\\/g, '/')
47+
48+
if (p.startsWith('file://')) {
49+
p = p.substring(7)
50+
}
51+
52+
const hash_idx = p.indexOf('#')
53+
if (hash_idx != -1) {
54+
p = p.substring(0, hash_idx)
55+
}
56+
57+
const query_idx = p.indexOf('?')
58+
if (query_idx != -1) {
59+
p = p.substring(0, query_idx)
60+
}
61+
62+
p = p.replace(/:[0-9]+(:[0-9]+)?$/, '')
63+
4564
if (p.startsWith('./')) {
4665
p = p.substring(2)
4766
} else if (p.startsWith('/')) {
@@ -51,7 +70,7 @@ export const extract_paths_from_text = (params: {
5170
p = p.substring(1)
5271
}
5372

54-
if (!p || p === '.' || p === '..') continue
73+
if (!p || p == '.' || p == '..') continue
5574

5675
let idx = params.text.indexOf(original_p)
5776
if (idx == -1) {
@@ -60,7 +79,7 @@ export const extract_paths_from_text = (params: {
6079
const safe_idx = idx != -1 ? idx : Infinity
6180

6281
for (const file of params.workspace_files) {
63-
if (file === p || file.endsWith('/' + p)) {
82+
if (file == p || file.endsWith('/' + p) || p.endsWith('/' + file)) {
6483
const current_idx = matched_files_with_index.get(file) ?? Infinity
6584
matched_files_with_index.set(file, Math.min(current_idx, safe_idx))
6685
}

0 commit comments

Comments
 (0)