3
3
import os
4
4
import re
5
5
import threading
6
+ import time
6
7
7
8
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 = []
10
11
css_folders = []
11
12
css_files = []
12
13
enabled = True
13
14
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
16
17
17
18
@staticmethod
18
19
def load_settings ():
19
20
settings = sublime .load_settings ("CSS-Intellisense.sublime-settings" )
20
21
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
+ )
22
32
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 )
24
34
CssIntellisense .css_folders = settings .get ("css_folders" , [])
25
35
CssIntellisense .css_files = settings .get ("css_files" , [])
26
36
27
37
@staticmethod
28
38
def update_sorted_completions ():
29
- """Update daftar autocomplete yang sudah diurutkan berdasarkan cache."""
30
39
CssIntellisense .sorted_completions = sorted (
31
40
[("{}\t {}" .format (cls_name , file_name ), cls_name )
32
41
for cls_name , file_name in CssIntellisense .css_classes .items ()],
@@ -99,6 +108,16 @@ def clear_cache():
99
108
CssIntellisense .css_files = []
100
109
sublime .status_message ("CSS Intellisense: Cache cleared" )
101
110
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
+
102
121
class AddCssFolderCommand (sublime_plugin .WindowCommand ):
103
122
def run (self , dirs ):
104
123
if dirs :
@@ -124,25 +143,30 @@ def on_query_completions(self, view, prefix, locations):
124
143
CssIntellisense .load_settings ()
125
144
if not CssIntellisense .enabled :
126
145
return None
127
-
146
+
128
147
for location in locations :
129
148
if any (view .match_selector (location , scope ) for scope in CssIntellisense .scopes ):
130
149
line_region = view .line (location )
131
150
line_text = view .substr (line_region )
132
151
133
- matches = re .finditer (r'class="([^"]*)"' , line_text )
152
+ matches = re .finditer (r'( class|className) ="([^"]*)"' , line_text )
134
153
135
154
for match in matches :
136
- start , end = match .span (1 )
155
+ start , end = match .span (2 )
137
156
class_attr_start = line_region .begin () + start
138
157
class_attr_end = line_region .begin () + end
139
158
140
159
if class_attr_start <= location <= class_attr_end :
141
- # Gunakan sorted_completions langsung tanpa sorting ulang
142
160
completions = [
143
161
completion for completion in CssIntellisense .sorted_completions
144
162
if prefix in completion [1 ]
145
163
]
146
164
return completions
147
165
148
166
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