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 ( 04aa04...031d16 )
by thatsIch
01:00
created

ContextSensAutoCompletion.on_query_completions()   D

Complexity

Conditions 10

Size

Total Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 10
c 2
b 0
f 0
dl 0
loc 66
rs 4.4444

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like ContextSensAutoCompletion.on_query_completions() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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):
0 ignored issues
show
Coding Style introduced by
This class 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...
15
16
    # only show our completion list because nothing else makes sense in this context
17
    flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS
18
19
    section = None
20
    skin_rainmeter_section = None
21
    skin_metadata_section = None
22
23
    scope = "source.rainmeter"
24
25
    # comments are specified by ';'
26
    comment_exp = re.compile(r'^\s*;.*')
27
28
    # enable searching for [] in multiline environment
29
    bracket_expression = re.compile(r'^\s*\[.+\]\s*$', re.MULTILINE)
30
    section_expression = re.compile(r'^\s*\[(.+)\]\s*$', re.I)
31
    key_expression = re.compile(r'^\s*(.+)\s*\=?\s*(.*?)\s*$', re.MULTILINE)
32
    key_value_expression = re.compile(r'^\s*(.+?)\s*\=\s*(.*?)\s*$', re.MULTILINE)
33
34
    def __init__(self):
35
        self.section = SkinSectionAutoCompleter()
36
        self.skin_rainmeter_section = SkinRainmeterSectionAutoComplete()
37
        self.skin_metadata_section = SkinMetadataSectionAutoComplete()
38
39
    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...
40
        size = view.size()
41
        start_content = view.substr(sublime.Region(0, location))
42
        end_content = view.substr(sublime.Region(location, size))
43
44
        start_index = self.get_current_section_content_start_index(start_content)
45
        end_index = self.get_current_section_content_end_index(end_content, location, size)
46
47
        section = view.substr(sublime.Region(start_index, end_index))
48
        lines = section.splitlines()
49
50
        return lines
51
52
    def get_current_section_content_start_index(self, start_content):
0 ignored issues
show
Coding Style Naming introduced by
The name get_current_section_content_start_index does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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...
53
        matches = list(self.bracket_expression.finditer(start_content))
54
55
        if len(matches) > 0:
56
            last_match = matches[-1]
57
            return last_match.start()
58
59
        # no previous section found, hardly legal but who cares
60
        else:
61
            return 0
62
63
    def get_current_section_content_end_index(self, end_content, offset, end_index):
0 ignored issues
show
Coding Style Naming introduced by
The name get_current_section_content_end_index does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
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...
64
        matches = list(self.bracket_expression.finditer(end_content))
65
        if len(matches) > 0:
66
            first_match = matches[0]
67
            return first_match.start() + offset
68
69
        # no next section found
70
        else:
71
            return end_index
72
73
    def get_key_value(self, line_content):
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...
74
        key_value_match = self.key_value_expression.search(line_content)
75
        if key_value_match:
76
            key_match = key_value_match.group(1)
77
            value_match = key_value_match.group(2)
78
            logger.info(__file__, "on_query_completions", "key/value found in '" + line_content + "' with ('" + key_match + "', '" + value_match + "')")
79
80
            return key_match, value_match
81
82
        key_only_match = self.key_expression.search(line_content)
83
        if key_only_match:
84
            logger.info(__file__, "on_query_completions", "potential key found in '" + line_content + "'")
85
            return key_only_match.group(1), None
86
87
        return None, None
88
89
    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...
90
        key_values = []
91
92
        for line in lines:
93
            key, value = self.get_key_value(line)
94
            if key:
95
                key_values.append((key, value))
96
97
        return key_values
98
99
    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...
100
        for location in locations:
101
            # ignore non scope
102
            if not view.match_selector(location, self.scope):
103
                return None
104
105
            # ignore on comment lines
106
            cursor_line = view.line(location)
107
            line_content = view.substr(cursor_line)
108
            if self.comment_exp.search(line_content):
109
                logger.info(__file__, "on_query_completions", "found comment")
110
                return None
111
112
            # find last occurance of the [] to determine the ini sections
113
            lines = self.get_lines_of_section_on_cursor(view, location)
114
            # filter empty lines
115
            lines = list(filter(None, lines))
116
            # filter comments
117
            lines = list(filter(lambda l: not self.comment_exp.search(l), lines))
118
119
            if not lines:
120
                logger.info(__file__, "bootstrap.on_query_completions", "section is empty")
121
                size = view.size()
122
                content = view.substr(sublime.Region(0, size))
123
                sections = self.bracket_expression.findall(content)
124
125
                return self.section.get_key_context_completion(prefix, line_content, sections)
126
127
            # extract section
128
            first_line = lines[0]
129
            match = self.section_expression.search(first_line)
130
131
            # no section defined
132
            # TODO section suggestion
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
133
            # if not match:
134
            #     logger.info(__file__, "on_query_completions", "no section found")
135
            #     size = view.size()
136
            #     content = view.substr(sublime.Region(0, size))
137
            #     sections = self.bracket_expression.findall(content)
138
139
            #     return self.section.get_key_context_completion(prefix, line_content, sections)
140
            section = match.group(1)
141
142
            key_match, value_match = self.get_key_value(line_content)
143
            key_values = self.get_key_values(lines)
144
145
            if value_match == "":
146
                logger.info(__file__, "on_query_completions", "after equal trigger in '" + line_content + "'")
147
                # value trigger
148
                value_result = self.skin_rainmeter_section.get_value_context_completion(view, prefix, location, line_content, section, key_match, key_values)
149
                if value_result:
150
                    return value_result
151
152
            # only do key completion if we are in the key are
153
            # that means in front of the equal or no equal at all
154
            else:
155
                logger.info(__file__, "on_query_completions", "before equal trigger in '" + line_content + "'")
156
                key_result = self.skin_rainmeter_section.get_key_context_completion(view, prefix, location, line_content, section, key_values)
157
                if key_result:
158
                    return key_result
159
160
                key_result = self.skin_metadata_section.get_key_context_completion(prefix, line_content, section, key_values)
161
                if key_result:
162
                    return key_result
163
164
            return None
165