|
| 1 | +import dataclasses |
1 | 2 | from concurrent.futures import CancelledError |
2 | 3 | from itertools import chain |
3 | 4 | from typing import TYPE_CHECKING, Any, Final, List, Optional, Union, cast |
@@ -41,6 +42,7 @@ class CompletionProtocolPart(LanguageServerProtocolPart): |
41 | 42 |
|
42 | 43 | def __init__(self, parent: "LanguageServerProtocol") -> None: |
43 | 44 | super().__init__(parent) |
| 45 | + self.resolve_support = False |
44 | 46 |
|
45 | 47 | @event |
46 | 48 | def collect( |
@@ -74,6 +76,16 @@ def extend_capabilities(self, capabilities: ServerCapabilities) -> None: |
74 | 76 | ] |
75 | 77 | ) |
76 | 78 | ) |
| 79 | + if ( |
| 80 | + self.parent.client_capabilities is not None |
| 81 | + and self.parent.client_capabilities.text_document is not None |
| 82 | + and self.parent.client_capabilities.text_document.completion is not None |
| 83 | + and self.parent.client_capabilities.text_document.completion.completion_item is not None |
| 84 | + and self.parent.client_capabilities.text_document.completion.completion_item.resolve_support is not None |
| 85 | + and self.parent.client_capabilities.text_document.completion.completion_item.resolve_support.properties |
| 86 | + ): |
| 87 | + self.resolve_support = True |
| 88 | + |
77 | 89 | capabilities.completion_provider = CompletionOptions( |
78 | 90 | trigger_characters=trigger_chars if trigger_chars else None, |
79 | 91 | all_commit_characters=commit_chars if commit_chars else None, |
@@ -141,13 +153,20 @@ def _text_document_completion( |
141 | 153 | ) |
142 | 154 | if len(result.items) == 0: |
143 | 155 | return None |
144 | | - return result |
| 156 | + |
| 157 | + if self.resolve_support: |
| 158 | + return result |
| 159 | + |
| 160 | + return dataclasses.replace(result, items=[self._completion_item_resolve(e) for e in result.items]) |
145 | 161 |
|
146 | 162 | result = list(chain(*[k for k in results if isinstance(k, list)])) |
147 | 163 | if not result: |
148 | 164 | return None |
149 | 165 |
|
150 | | - return result |
| 166 | + if self.resolve_support: |
| 167 | + return result |
| 168 | + |
| 169 | + return [self._completion_item_resolve(e) for e in result] |
151 | 170 |
|
152 | 171 | def update_completion_item_to_utf16(self, document: TextDocument, item: CompletionItem) -> None: |
153 | 172 | if isinstance(item.text_edit, TextEdit): |
|
0 commit comments