GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 93f9bb...69a674 )
by thatsIch
59s
created

get_start_index_of_section()   A

Complexity

Conditions 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
# python libs
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import re
3
4
# st libs
5
import sublime
6
7
# own libs
8
from .. import logger
0 ignored issues
show
Bug introduced by
The name logger does not seem to exist in module completion.
Loading history...
9
from ..completion.skin.rainmeter_section import SkinRainmeterSectionAutoComplete
0 ignored issues
show
Bug introduced by
The name skin does not seem to exist in module completion.completion.
Loading history...
10
from ..completion.skin.metadata_section import SkinMetadataSectionAutoComplete
0 ignored issues
show
Bug introduced by
The name skin does not seem to exist in module completion.completion.
Loading history...
11
from ..completion.section import SkinSectionAutoCompleter
0 ignored issues
show
Bug introduced by
The name section does not seem to exist in module completion.completion.
Loading history...
12
13
14
class ContextSensAutoCompletion(object):
15
    """
16
    This represents the internal implementation for the contextual auto completion.
17
    It uses smart environmental information like section, key, values etc
18
    to provide smarter auto completion suggestions.
19
    """
20
21
    # only show our completion list because nothing else makes sense in this context
22
    flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS
23
24
    section = None
25
    skin_rainmeter_section = None
26
    skin_metadata_section = None
27
28
    scope = "source.rainmeter"
29
30
    # comments are specified by ';'
31
    comment_exp = re.compile(r'^\s*;.*')
32
33
    # enable searching for [] in multiline environment
34
    bracket_expression = re.compile(r'^\s*\[.+\]\s*$', re.MULTILINE)
35
    section_expression = re.compile(r'^\s*\[(.+)\]\s*$', re.I)
36
    key_expression = re.compile(r'^\s*(.+)\s*\=?\s*(.*?)\s*$', re.MULTILINE)
37
    key_value_expression = re.compile(r'^\s*(.+?)\s*\=\s*(.*?)\s*$', re.MULTILINE)
38
39
    def __init__(self):
40
        self.section = SkinSectionAutoCompleter()
41
        self.skin_rainmeter_section = SkinRainmeterSectionAutoComplete()
42
        self.skin_metadata_section = SkinMetadataSectionAutoComplete()
43
44
    def get_lines_of_section_on_cursor(self, view, location):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
45
        size = view.size()
46
        start_content = view.substr(sublime.Region(0, location))
47
        end_content = view.substr(sublime.Region(location, size))
48
49
        start_index = self.get_start_index_of_section(start_content)
50
        end_index = self.get_end_index_of_section(end_content, location, size)
51
52
        section = view.substr(sublime.Region(start_index, end_index))
53
        lines = section.splitlines()
54
55
        return lines
56
57
    def get_start_index_of_section(self, start_content):
58
        """
59
        This returns the index of the section.
60
        If no section is found the first index (0) is returned
61
        """
62
63
        matches = list(self.bracket_expression.finditer(start_content))
64
65
        if len(matches) > 0:
66
            last_match = matches[-1]
67
            return last_match.start()
68
69
        # no previous section found, hardly legal but who cares
70
        else:
71
            return 0
72
73
    def get_end_index_of_section(self, end_content, offset, end_index):
74
        """
75
        This returns the index of the next section.
76
        If no next section is found the last index is returned given through the param end_index
77
        """
78
79
        matches = list(self.bracket_expression.finditer(end_content))
80
        if len(matches) > 0:
81
            first_match = matches[0]
82
            return first_match.start() + offset
83
84
        # no next section found
85
        else:
86
            return end_index
87
88
    def get_key_value(self, line_content):
89
        """
90
        Extract the key and/or value in a line if existing.
91
        This is used if a specific completion is only shown
92
        on special conditions like only show X on measures.
93
94
        If nothing is given return (None, None)
95
        """
96
        key_value_match = self.key_value_expression.search(line_content)
97
        if key_value_match:
98
            key_match = key_value_match.group(1)
99
            value_match = key_value_match.group(2)
100
            logger.info(__file__, "on_query_completions", "key/value found in '" + line_content + "' with ('" + key_match + "', '" + value_match + "')")
101
102
            return key_match, value_match
103
104
        key_only_match = self.key_expression.search(line_content)
105
        if key_only_match:
106
            logger.info(__file__, "on_query_completions", "potential key found in '" + line_content + "'")
107
            return key_only_match.group(1), None
108
109
        return None, None
110
111
    def get_key_values(self, lines):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
112
        key_values = []
113
114
        for line in lines:
115
            key, value = self.get_key_value(line)
116
            if key:
117
                key_values.append((key, value))
118
119
        return key_values
120
121
    def on_query_completions(self, view, prefix, locations):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
122
        for location in locations:
123
            # ignore non scope
124
            if not view.match_selector(location, self.scope):
125
                return None
126
127
            # ignore on comment lines
128
            cursor_line = view.line(location)
129
            line_content = view.substr(cursor_line)
130
            if self.comment_exp.search(line_content):
131
                logger.info(__file__, "on_query_completions", "found comment")
132
                return None
133
134
            # find last occurance of the [] to determine the ini sections
135
            lines = self.get_lines_of_section_on_cursor(view, location)
136
            # filter empty lines
137
            lines = list(filter(None, lines))
138
            # filter comments
139
            lines = list(filter(lambda l: not self.comment_exp.search(l), lines))
140
141
            if not lines:
142
                logger.info(__file__, "bootstrap.on_query_completions", "section is empty")
143
                size = view.size()
144
                content = view.substr(sublime.Region(0, size))
145
                sections = self.bracket_expression.findall(content)
146
147
                return self.section.get_key_context_completion(prefix, line_content, sections)
148
149
            # extract section
150
            first_line = lines[0]
151
            match = self.section_expression.search(first_line)
152
153
            # no section defined
154
            # TODO section suggestion
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
155
            # if not match:
156
            #     logger.info(__file__, "on_query_completions", "no section found")
157
            #     size = view.size()
158
            #     content = view.substr(sublime.Region(0, size))
159
            #     sections = self.bracket_expression.findall(content)
160
161
            #     return self.section.get_key_context_completion(prefix, line_content, sections)
162
            section = match.group(1)
163
164
            key_match, value_match = self.get_key_value(line_content)
165
            key_values = self.get_key_values(lines)
166
167
            if value_match == "":
168
                logger.info(__file__, "on_query_completions", "after equal trigger in '" + line_content + "'")
169
                # value trigger
170
                value_result = self.skin_rainmeter_section.get_value_context_completion(view, prefix, location, line_content, section, key_match, key_values)
171
                if value_result:
172
                    return value_result
173
174
            # only do key completion if we are in the key are
175
            # that means in front of the equal or no equal at all
176
            else:
177
                logger.info(__file__, "on_query_completions", "before equal trigger in '" + line_content + "'")
178
                key_result = self.skin_rainmeter_section.get_key_context_completion(view, prefix, location, line_content, section, key_values)
179
                if key_result:
180
                    return key_result
181
182
                key_result = self.skin_metadata_section.get_key_context_completion(prefix, line_content, section, key_values)
183
                if key_result:
184
                    return key_result
185
186
            return None
187