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

get_key_context_completion()   B

Complexity

Conditions 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
cc 5
c 7
b 0
f 0
dl 0
loc 23
rs 8.2508
1
import yaml
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
3
import sublime
4
5
# import own libs
6
from ... import logger
0 ignored issues
show
Bug introduced by
The name logger does not seem to exist in module completion.
Loading history...
7
from ...completion.levenshtein import levenshtein
0 ignored issues
show
Bug introduced by
The name levenshtein does not seem to exist in module completion.completion.
Loading history...
8
from ...completion.yaml_content_reader import YamlContentReader
0 ignored issues
show
Bug introduced by
The name yaml_content_reader does not seem to exist in module completion.completion.
Loading history...
9
10
11
class SkinMetadataSectionAutoComplete(YamlContentReader):
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...
12
13
    def __get_completions(self):
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...
14
        try:
15
            skin_metadata_section_content = self._get_yaml_content("completion/skin/", "metadata_section.yaml")
16
            skin_metadata_section = yaml.load(skin_metadata_section_content)
17
18
            return skin_metadata_section
19
20
        except yaml.YAMLError as error:
21
            logger.error(__file__, "get_completions", error)
22
            return []
23
24
    def __get_compiled_key_completions(self, options):
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...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
25
        keys = []
26
        for option in options:
27
            title = option['title'] + "\t" + option['hint']
28
29
            if 'value' in option:
30
                result = option['value']
31
            else:
32
                result = option['title']
33
34
            pair = (title, result)
35
            keys.append(pair)
36
37
        return keys
38
39
    def __lazy_initialize_completions(self):
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
        # use lazy initialization because else the API is not available yet
41
        if not self.all_completions:
42
            self.all_completions = self.__get_completions()
43
            self.all_key_completions = self.__get_compiled_key_completions(self.all_completions)
44
45
    def __filter_completions_by_key_already_used(self, keyvalues):
0 ignored issues
show
Coding Style Naming introduced by
The name __filter_completions_by_key_already_used 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...
46
        """
47
        In Rainmeter a key can only be used once in a section statement.
48
        If you declare it twice this is a code smell.
49
        """
50
        # filter by already existing keys
51
        completions = []
52
53
        for completion in self.all_key_completions:
54
            # trigger is not used here
55
            _, content = completion
56
57
            contained = 0
58
            # value not used here
59
            for key, _ in keyvalues:
60
                if key.casefold() == content.casefold():
61
                    contained = 1
62
                    break
63
64
            if contained == 0:
65
                completions.append(completion)
66
67
        return completions
68
69
    # only show our completion list because nothing else makes sense in this context
70
    flags = sublime.INHIBIT_EXPLICIT_COMPLETIONS | sublime.INHIBIT_WORD_COMPLETIONS
71
72
    all_completions = None
73
    all_key_completions = None
74
75
    def get_key_context_completion(self, prefix, line_content, section, keyvalues):
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...
76
        if section.casefold() != "Metadata".casefold():
77
            return None
78
79
        self.__lazy_initialize_completions()
80
        completions = self.__filter_completions_by_key_already_used(keyvalues)
81
82
        # no results, means all keys are used up
83
        if not completions:
84
            logger.info(
85
                __file__,
86
                "get_key_context_completion",
87
                "no results, all keys are used up"
88
            )
89
            return None
90
91
        # only show sorted by distance if something was already typed because distance to empty string makes no sense
92
        if line_content != "":
93
            # sort by levenshtein distance
94
            sorted_completions = sorted(completions, key=lambda completion: levenshtein(completion[1], prefix))
95
            return sorted_completions, self.flags
96
        else:
97
            return completions, self.flags
98