Skip to content

Commit 596797a

Browse files
committed
Fix nested gitignore path matching by supporting negations and unanchored patterns
- the second gitignore rule is not respected [Pasted text] - excluding paths should work [Accuracy boost] ├── apps │ └── editor │ ├── package.json │ └── src │ ├── commands │ │ └── select-workspace-file-command.ts │ ├── constants │ │ ├── ignored-lock-files.ts │ │ └── state-keys.ts │ ├── context │ │ ├── context-initialization.ts │ │ ├── helpers │ │ │ ├── get-all-workspace-files.ts │ │ │ └── get-selected-files.ts │ │ ├── providers │ │ │ ├── open-editors │ │ │ │ └── open-editors-provider.ts │ │ │ ├── selected-files │ │ │ │ └── selected-files-provider.ts │ │ │ └── workspace │ │ │ ├── modules │ │ │ │ ├── index.ts │ │ │ │ └── token-calculator.ts │ │ │ └── workspace-provider.ts │ │ └── shared-context-state.ts │ ├── extension.ts │ ├── utils │ │ ├── is-binary.ts │ │ ├── natural-sort.ts │ │ └── normalize-path.ts │ └── views │ └── prompt │ └── backend │ └── message-handlers │ └── handle-at-sign-quick-pick.ts └── packages └── shared └── src └── utils ├── display-token-count.ts └── logger.ts
1 parent 7a1aeea commit 596797a

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,13 +1424,28 @@ export class WorkspaceProvider
14241424
.split('\n')
14251425
.map((rule) => rule.trim())
14261426
.filter((rule) => rule && !rule.startsWith('#'))
1427-
.map((rule) =>
1428-
relative_gitignore_path === ''
1429-
? rule
1430-
: `${relative_gitignore_path}${
1431-
rule.startsWith('/') ? rule : `/${rule}`
1432-
}`
1433-
)
1427+
.map((rule) => {
1428+
if (relative_gitignore_path === '') {
1429+
return rule
1430+
}
1431+
1432+
const is_negated = rule.startsWith('!')
1433+
let actual_rule = is_negated ? rule.substring(1) : rule
1434+
1435+
const is_anchored =
1436+
actual_rule.indexOf('/') !== -1 &&
1437+
actual_rule.indexOf('/') !== actual_rule.length - 1
1438+
1439+
if (!is_anchored && !actual_rule.startsWith('**')) {
1440+
actual_rule = `**/${actual_rule}`
1441+
}
1442+
1443+
if (actual_rule.startsWith('/')) {
1444+
actual_rule = actual_rule.substring(1)
1445+
}
1446+
1447+
return `${is_negated ? '!' : ''}${relative_gitignore_path}/${actual_rule}`
1448+
})
14341449

14351450
this._combined_gitignore.add(rules_with_prefix)
14361451
} catch (error) {

0 commit comments

Comments
 (0)