forked from thatsIch/sublime-rainmeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart_completion.py
177 lines (148 loc) · 5.4 KB
/
smart_completion.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""
This plugin is the entry point to the smart completion module.
Basic functionalities are kontext detection and offer only meaningful auto completion options
instead of every of them.
"""
import re
import sublime
import sublime_plugin
from .completion.completion import ContextSensAutoCompletion
class MeterAutoComplete(sublime_plugin.EventListener):
# pylint: disable=R0903; Ignore too few methods because we have a super class.
"""
This class is an implementation of the sublime plugin EventListener.
This is a temporary solution for the completion module.
It provides some basic smart completions like:
* measures
* plugins
* meters
* some attributes
"""
# only show our completion list because nothing else makes sense in this context
flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS
scope = "source.rainmeter"
comment_exp = re.compile(r'^\s*;.*')
meter_exp = re.compile(r'^\s*')
completions = [
# measures
(re.compile(r'^\s*Measure\s*=\s*'), [
# key, value
["Calc", "Calc"],
["CPU", "CPU"],
["FreeDiskSpace", "FreeDiskSpace"],
["Loop", "Loop"],
["MediaKey", "MediaKey"],
# memory measure
["Memory", "Memory"],
["PhysicalMemory", "PhysicalMemory"],
["SwapMemory", "SwapMemory"],
# net measure
["NetIn", "NetIn"],
["NetOut", "NetOut"],
["NetTotal", "NetTotal"],
["NowPlaying", "NowPlaying"],
["Plugin", "Plugin"],
["RecycleManager", "RecycleManager"],
["Registry", "Registry"],
["Script", "Script"],
["String", "String"],
["Time", "Time"],
["Uptime", "Uptime"],
["WebParser", "WebParser"]
]),
# meters
(re.compile(r'^\s*Meter\s*=\s*'), [
# key, value
["Bar", "Bar"],
["Bitmap", "Bitmap"],
["Button", "Button"],
["Histogram", "Histogram"],
["Image", "Image"],
["Line", "Line"],
["Rotator", "Rotator"],
["Roundline", "Roundline"],
["Shape", "Shape"],
["String", "String"]
]),
# general options
# bar
# bar orientation
(re.compile(r'^\s*BarOrientation\s*=\s*'), [
# key, value
["Horizontal", "Horizontal"],
["Vertical\tDefault", "Vertical"]
]),
# bar flip
(re.compile(r'^\s*Flip\s*=\s*'), [
# key, value
["0\tDefault", "0"],
["1\tBar is flipped", "1"]
]),
# bitmap
# button
# histogram
# image
# line
# rotator
# roundline
# shape
# string
# plugins
(re.compile(r'^\s*Plugin\s*=\s*'), [
# key, value
["ActionTimer", "ActionTimer"],
["AdvancedCPU", "AdvancedCPU"],
["AudioLevel", "AudioLevel"],
["CoreTemp", "CoreTemp"],
["FileView", "FileView"],
["FolderInfo", "FolderInfo"],
["InputText", "InputText"],
["iTunes", "iTunesPlugin"],
["PerfMon", "PerfMon"],
["Ping", "PingPlugin"],
["Power", "PowerPlugin"],
["Process", "Process"],
["Quote", "QuotePlugin"],
["ResMon", "ResMon"],
["RunCommand", "RunCommand"],
["SpeedFan", "SpeedFanPlugin"],
["UsageMonitor", "UsageMonitor"],
["SysInfo", "SysInfo"],
["WiFiStatus", "WiFiStatus"],
["Win7Audio", "Win7AudioPlugin"],
["WindowMessage", "WindowMessagePlugin"]
]),
]
def on_query_completions(self, view, _, locations):
"""
Called upon auto completion request.
:param view: current view upon the text buffer
:param _: unused prefix
:param locations: selected regions
"""
for location in locations:
# checks if the current scope is correct
# so it is only called in the files with the correct scope
# here is scope only rainmeter files
if view.match_selector(location, self.scope):
# find last occurance of the [] to determine the ini sections
line = view.line(location)
line_contents = view.substr(line)
# starts with Measure, followed by an equal sign
for exp, elements in self.completions:
if exp.search(line_contents):
return elements, self.flags
return None
class CompletionProxy(sublime_plugin.EventListener):
# pylint: disable=R0903; Ignore too few methods because we have a super class.
"""
Proxy the sublime plugin EventListener to the internal completion module.
The module handles all the request and routes them to the correct submodules.
This prevents all the single modules from polluting the root directory.
"""
def __init__(self):
"""Initialize the proxy."""
self.proxied_completion = ContextSensAutoCompletion()
def on_query_completions(self, view, prefix, locations):
"""Pass query completion to proxy."""
return self.proxied_completion.on_query_completions(view, prefix, locations)