diff --git a/plugin/code_lens.py b/plugin/code_lens.py index 87fa8eddb..d3673a844 100644 --- a/plugin/code_lens.py +++ b/plugin/code_lens.py @@ -23,7 +23,7 @@ def __init__(self, data: CodeLens, view: sublime.View, session_name: str) -> Non self.region = range_to_region(data['range'], view) self.session_name = session_name self.annotation = '...' - self.resolve_annotation() + self.resolve_annotation(view.id()) self.is_resolve_error = False def __repr__(self) -> str: @@ -42,7 +42,7 @@ def to_lsp(self) -> CodeLensExtended: def small_html(self) -> str: return '{}'.format(self.annotation) - def resolve_annotation(self) -> None: + def resolve_annotation(self, view_id: int) -> None: command = self.data.get('command') if command is not None: command_name = command.get('command') @@ -51,7 +51,7 @@ def resolve_annotation(self) -> None: 'session_name': self.session_name, 'command_name': command_name, 'command_args': command.get('arguments', []), - }) + }, view_id=view_id) else: self.annotation = html_escape(command['title']) else: @@ -64,7 +64,7 @@ def resolve(self, view: sublime.View, code_lens_or_error: Union[CodeLens, Error] return self.data = code_lens_or_error self.region = range_to_region(code_lens_or_error['range'], view) - self.resolve_annotation() + self.resolve_annotation(view.id()) class CodeLensView: diff --git a/plugin/core/views.py b/plugin/core/views.py index 36f2a7478..03193057c 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -787,10 +787,10 @@ def make_link(href: str, text: Any, class_name: Optional[str] = None) -> str: def make_command_link(command: str, text: str, command_args: Optional[Dict[str, Any]] = None, - class_name: Optional[str] = None, view: Optional[sublime.View] = None) -> str: - if view: + class_name: Optional[str] = None, view_id: Optional[int] = None) -> str: + if view_id is not None: cmd = "lsp_run_text_command_helper" - args = {"view_id": view.id(), "command": command, "args": command_args} # type: Optional[Dict[str, Any]] + args = {"view_id": view_id, "command": command, "args": command_args} # type: Optional[Dict[str, Any]] else: cmd = command args = command_args @@ -1014,7 +1014,7 @@ def format_diagnostic_for_html( def format_completion( - item: CompletionItem, index: int, can_resolve_completion_items: bool, session_name: str + item: CompletionItem, index: int, can_resolve_completion_items: bool, session_name: str, view_id: int ) -> sublime.CompletionItem: # This is a hot function. Don't do heavy computations or IO in this function. @@ -1030,7 +1030,8 @@ def format_completion( details = [] # type: List[str] if can_resolve_completion_items or item.get('documentation'): - details.append(make_command_link('lsp_resolve_docs', "More", {'index': index, 'session_name': session_name})) + details.append(make_command_link( + 'lsp_resolve_docs', "More", {'index': index, 'session_name': session_name}, view_id=view_id)) if lsp_label_detail and (lsp_label + lsp_label_detail).startswith(lsp_filter_text): trigger = lsp_label + lsp_label_detail diff --git a/plugin/documents.py b/plugin/documents.py index cc3913c70..c2c6da897 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -640,7 +640,8 @@ def _on_code_actions(self, responses: List[CodeActionsByConfigName]) -> None: else: title = all_actions[0]['title'] title = "
".join(textwrap.wrap(title, width=30)) - code_actions_link = make_command_link('lsp_code_actions', title, {"code_actions_by_config": responses}) + code_actions_link = make_command_link( + 'lsp_code_actions', title, {"code_actions_by_config": responses}, view_id=self.view.id()) annotations = ["
{}
".format(code_actions_link)] annotation_color = self.view.style_for_scope("region.bluish markup.accent.codeaction.lsp")["foreground"] self.view.add_regions(SessionView.CODE_ACTIONS_KEY, regions, scope, icon, flags, annotations, annotation_color) @@ -809,8 +810,9 @@ def _on_all_settled( response_items = sorted(response_items, key=lambda item: item.get("sortText") or item["label"]) LspResolveDocsCommand.completions[session_name] = response_items can_resolve_completion_items = session.has_capability('completionProvider.resolveProvider') + config_name = session.config.name items.extend( - format_completion(response_item, index, can_resolve_completion_items, session.config.name) + format_completion(response_item, index, can_resolve_completion_items, config_name, self.view.id()) for index, response_item in enumerate(response_items) if include_snippets or response_item.get("kind") != CompletionItemKind.Snippet) if items: diff --git a/plugin/hover.py b/plugin/hover.py index 4de0e05d4..a86edabf9 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -64,10 +64,10 @@ def __init__(self, lsp_name: str, label: str, subl_cmd_name: str, supports_side_ def link(self, point: int, view: sublime.View) -> str: args = {'point': point} - link = make_command_link(self.subl_cmd_name, self.label, args, None, view) + link = make_command_link(self.subl_cmd_name, self.label, args, None, view.id()) if self.supports_side_by_side: args['side_by_side'] = True - link += ' ' + make_command_link(self.subl_cmd_name, '◨', args, 'icon', view) + link += ' ' + make_command_link(self.subl_cmd_name, '◨', args, 'icon', view.id()) return link