Skip to content

Commit df3a036

Browse files
authored
Update CSS-Intellisense.py
Add Support JSX
1 parent 77db1e9 commit df3a036

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

CSS-Intellisense.py

+35-11
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,39 @@
33
import os
44
import re
55
import threading
6+
import time
67

78
class CssIntellisense:
8-
css_classes = {} # Dictionary untuk menyimpan kelas dan nama file
9-
sorted_completions = [] # Daftar kelas yang sudah diurutkan
9+
css_classes = {}
10+
sorted_completions = []
1011
css_folders = []
1112
css_files = []
1213
enabled = True
1314
auto_search = False
14-
scopes = ["text.html", "text.html.php"]
15-
auto_refresh_interval = None
15+
scopes = ["string.quoted.double.html", "text.html", "text.html.php", "source.jsx", "source.tsx", "text.html.blade"]
16+
auto_refresh_interval = False # Default false
1617

1718
@staticmethod
1819
def load_settings():
1920
settings = sublime.load_settings("CSS-Intellisense.sublime-settings")
2021
CssIntellisense.enabled = settings.get("enabled", True)
21-
CssIntellisense.scopes = settings.get("scopes", ["text.html", "text.html.php"])
22+
CssIntellisense.scopes = settings.get(
23+
"scopes", [
24+
"string.quoted.double.html",
25+
"text.html",
26+
"text.html.php",
27+
"source.jsx",
28+
"source.tsx",
29+
"text.html.blade"
30+
]
31+
)
2232
CssIntellisense.auto_search = settings.get("auto_search", True)
23-
CssIntellisense.auto_refresh_interval = settings.get("auto_refresh_interval", None)
33+
CssIntellisense.auto_refresh_interval = settings.get("auto_refresh_interval", False)
2434
CssIntellisense.css_folders = settings.get("css_folders", [])
2535
CssIntellisense.css_files = settings.get("css_files", [])
2636

2737
@staticmethod
2838
def update_sorted_completions():
29-
"""Update daftar autocomplete yang sudah diurutkan berdasarkan cache."""
3039
CssIntellisense.sorted_completions = sorted(
3140
[("{}\t{}".format(cls_name, file_name), cls_name)
3241
for cls_name, file_name in CssIntellisense.css_classes.items()],
@@ -99,6 +108,16 @@ def clear_cache():
99108
CssIntellisense.css_files = []
100109
sublime.status_message("CSS Intellisense: Cache cleared")
101110

111+
@staticmethod
112+
def start_auto_refresh():
113+
"""Memulai proses auto-refresh jika interval diatur."""
114+
if isinstance(CssIntellisense.auto_refresh_interval, (int, float)) and CssIntellisense.auto_refresh_interval > 0:
115+
def auto_refresh():
116+
while True:
117+
time.sleep(CssIntellisense.auto_refresh_interval)
118+
CssIntellisense.refresh_cache()
119+
threading.Thread(target=auto_refresh, daemon=True).start()
120+
102121
class AddCssFolderCommand(sublime_plugin.WindowCommand):
103122
def run(self, dirs):
104123
if dirs:
@@ -124,25 +143,30 @@ def on_query_completions(self, view, prefix, locations):
124143
CssIntellisense.load_settings()
125144
if not CssIntellisense.enabled:
126145
return None
127-
146+
128147
for location in locations:
129148
if any(view.match_selector(location, scope) for scope in CssIntellisense.scopes):
130149
line_region = view.line(location)
131150
line_text = view.substr(line_region)
132151

133-
matches = re.finditer(r'class="([^"]*)"', line_text)
152+
matches = re.finditer(r'(class|className)="([^"]*)"', line_text)
134153

135154
for match in matches:
136-
start, end = match.span(1)
155+
start, end = match.span(2)
137156
class_attr_start = line_region.begin() + start
138157
class_attr_end = line_region.begin() + end
139158

140159
if class_attr_start <= location <= class_attr_end:
141-
# Gunakan sorted_completions langsung tanpa sorting ulang
142160
completions = [
143161
completion for completion in CssIntellisense.sorted_completions
144162
if prefix in completion[1]
145163
]
146164
return completions
147165

148166
return None
167+
168+
169+
def plugin_loaded():
170+
CssIntellisense.load_settings()
171+
CssIntellisense.search_css_in_project()
172+
CssIntellisense.start_auto_refresh()

0 commit comments

Comments
 (0)