Skip to content

Commit

Permalink
Ensure commands triggered from minihtml run on correct view
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Dec 29, 2022
1 parent eff29c9 commit dcc7524
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions plugin/code_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -42,7 +42,7 @@ def to_lsp(self) -> CodeLensExtended:
def small_html(self) -> str:
return '<small style="font-family: system">{}</small>'.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')
Expand All @@ -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:
Expand All @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@ def _on_code_actions(self, responses: List[CodeActionsByConfigName]) -> None:
else:
title = all_actions[0]['title']
title = "<br>".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 = ["<div class=\"actions\" style=\"font-family:system\">{}</div>".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)
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions plugin/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit dcc7524

Please sign in to comment.