1- import re
21import sublime
32import sublime_plugin
3+
4+ import re
45import timeit
56
67from functools import cached_property , wraps
8+ from typing import List , Optional , Tuple
79
810from . import completions
911
@@ -29,41 +31,41 @@ def wrap(*args, **kw):
2931 return wrap
3032
3133
32- def match_selector (view , pt , scope ) :
34+ def match_selector (view : sublime . View , pt : int , scope : str ) -> bool :
3335 # This will catch scenarios like:
3436 # - .foo {font-style: |}
3537 # - <style type="text/css">.foo { font-weight: b|</style>
3638 return any (view .match_selector (p , scope ) for p in (pt , pt - 1 ))
3739
3840
39- def next_none_whitespace (view , pt ) :
41+ def next_none_whitespace (view : sublime . View , pt : int ) -> Optional [ str ] :
4042 for pt in range (pt , view .size ()):
4143 ch = view .substr (pt )
4244 if ch not in ' \t ' :
4345 return ch
46+ return None
4447
4548
4649class CSSCompletions (sublime_plugin .EventListener ):
4750
4851 @cached_property
49- def func_args (self ):
52+ def func_args (self ) -> dict :
5053 return completions .get_func_args ()
5154
5255 @cached_property
53- def props (self ):
56+ def props (self ) -> dict :
5457 return completions .get_properties ()
5558
5659 @cached_property
57- def re_name (self ):
60+ def re_name (self ) -> re . Pattern :
5861 return re .compile (r"([a-zA-Z-]+)\s*:[^:;{}]*$" )
5962
6063 @cached_property
61- def re_value (self ):
64+ def re_value (self ) -> re . Pattern :
6265 return re .compile (r"^(?:\s*(:)|([ \t]*))([^:]*)([;}])" )
6366
6467 @timing
65- def on_query_completions (self , view , prefix , locations ):
66-
68+ def on_query_completions (self , view : sublime .View , prefix : str , locations : List [int ]) -> Optional [sublime .CompletionList ]:
6769 settings = sublime .load_settings ('CSS.sublime-settings' )
6870 if settings .get ('disable_default_completions' ):
6971 return None
@@ -87,7 +89,7 @@ def on_query_completions(self, view, prefix, locations):
8789 return sublime .CompletionList (items )
8890 return None
8991
90- def complete_property_name (self , view , prefix , pt ) :
92+ def complete_property_name (self , view : sublime . View , prefix : str , pt : int ) -> List [ sublime . CompletionItem ] :
9193 text = view .substr (sublime .Region (pt , view .line (pt ).end ()))
9294 matches = self .re_value .search (text )
9395 if matches :
@@ -111,16 +113,16 @@ def complete_property_name(self, view, prefix, pt):
111113 if not value and not term and not match_selector (view , pt , "meta.group" ):
112114 suffix += ";"
113115
114- return (
116+ return [
115117 sublime .CompletionItem (
116118 trigger = prop ,
117119 completion = prop + suffix ,
118120 completion_format = sublime .COMPLETION_FORMAT_SNIPPET ,
119121 kind = KIND_CSS_PROPERTY
120122 ) for prop in self .props
121- )
123+ ]
122124
123- def complete_property_value (self , view , prefix , pt ) :
125+ def complete_property_value (self , view : sublime . View , prefix : str , pt : int ) -> List [ sublime . CompletionItem ] :
124126 completions = [
125127 sublime .CompletionItem (
126128 trigger = "!important" ,
@@ -161,7 +163,7 @@ def complete_property_value(self, view, prefix, pt):
161163
162164 return completions
163165
164- def complete_function_argument (self , view : sublime .View , prefix , pt ) :
166+ def complete_function_argument (self , view : sublime .View , prefix : str , pt : int ) -> List [ sublime . CompletionItem ] :
165167 func_name = ""
166168 nest_level = 1
167169 # Look for the beginning of the current function call's arguments list,
@@ -199,7 +201,7 @@ def complete_function_argument(self, view: sublime.View, prefix, pt):
199201
200202 args = self .func_args .get (func_name )
201203 if not args :
202- return None
204+ return []
203205
204206 completions = []
205207 details = f"{ func_name } () argument"
0 commit comments