| Conditions | 10 | 
| Total Lines | 66 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 0 | 
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:
If many parameters/temporary variables are present:
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  | 
            ||
| 99 | def on_query_completions(self, view, prefix, locations):  | 
            ||
| 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  | 
            ||
| 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 | 
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.