Construct a full list of possibly completions for imports.
(self, cursor_offset: int, line: str)
| 131 | return self.attr_matches(name, only_modules=True) |
| 132 | |
| 133 | def complete(self, cursor_offset: int, line: str) -> set[str] | None: |
| 134 | """Construct a full list of possibly completions for imports.""" |
| 135 | tokens = line.split() |
| 136 | if "from" not in tokens and "import" not in tokens: |
| 137 | return None |
| 138 | |
| 139 | result = current_word(cursor_offset, line) |
| 140 | if result is None: |
| 141 | return None |
| 142 | |
| 143 | from_import_from = current_from_import_from(cursor_offset, line) |
| 144 | if from_import_from is not None: |
| 145 | import_import = current_from_import_import(cursor_offset, line) |
| 146 | if import_import is not None: |
| 147 | # `from a import <b|>` completion |
| 148 | matches = self.module_matches( |
| 149 | import_import.word, from_import_from.word |
| 150 | ) |
| 151 | matches.update( |
| 152 | self.attr_matches(import_import.word, from_import_from.word) |
| 153 | ) |
| 154 | else: |
| 155 | # `from <a|>` completion |
| 156 | matches = self.module_attr_matches(from_import_from.word) |
| 157 | matches.update(self.module_matches(from_import_from.word)) |
| 158 | return matches |
| 159 | |
| 160 | cur_import = current_import(cursor_offset, line) |
| 161 | if cur_import is not None: |
| 162 | # `import <a|>` completion |
| 163 | matches = self.module_matches(cur_import.word) |
| 164 | matches.update(self.module_attr_matches(cur_import.word)) |
| 165 | return matches |
| 166 | else: |
| 167 | return None |
| 168 | |
| 169 | def find_modules(self, path: Path) -> Generator[str | None, None, None]: |
| 170 | """Find all modules (and packages) for a given directory.""" |