-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenFilesMentioningCurrent.py
More file actions
61 lines (50 loc) · 2.04 KB
/
OpenFilesMentioningCurrent.py
File metadata and controls
61 lines (50 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sublime
import sublime_plugin
import os
import fnmatch
EXCLUDED_FOLDERS = [
'node_modules', 'build', 'dist', '.git', 'coverage',
'.claude/worktrees', '.gemini/worktrees'
]
FILE_PATTERNS = ['*.js', '*.ts', '*.svelte']
class OpenFilesMentioningCurrentCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
if not view or not view.file_name():
sublime.status_message("No file open.")
return
filename = os.path.basename(view.file_name())
module_name = os.path.splitext(filename)[0]
folders = self.window.folders()
if not folders:
sublime.status_message("No project open.")
return
candidate_files = []
for folder in folders:
for root, dirs, filenames in os.walk(folder):
# Prune excluded folders
dirs[:] = [d for d in dirs if not any(ex in d for ex in EXCLUDED_FOLDERS)]
for pattern in FILE_PATTERNS:
for fname in fnmatch.filter(filenames, pattern):
fpath = os.path.join(root, fname)
candidate_files.append(fpath)
# Debug: Log candidates
print(f"Candidate files to search ({len(candidate_files)} total):")
for fpath in candidate_files:
print(fpath)
files_to_open = []
for fpath in candidate_files:
try:
with open(fpath, 'r', encoding='utf-8') as f:
content = f.read()
if module_name in content:
files_to_open.append(fpath)
except:
pass # Skip unreadable files
# Debug: Log results
print(f"\nFiles mentioning '{module_name}' ({len(files_to_open)} total):")
for fpath in files_to_open:
print(fpath)
for fpath in files_to_open:
self.window.open_file(fpath)
sublime.status_message(f"Opened {len(files_to_open)} files mentioning '{module_name}'.")