Skip to content

Commit

Permalink
Fix short color box rendering bug after color presentation change (#2087
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jwortmann authored Oct 13, 2022
1 parent 18a533d commit 6aa77ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,14 +813,14 @@ def color_to_hex(color: Color) -> str:
return "#{:02x}{:02x}{:02x}".format(red, green, blue)


def lsp_color_to_html(view: sublime.View, color_info: ColorInformation) -> str:
def lsp_color_to_html(color_info: ColorInformation) -> str:
command = sublime.command_url('lsp_color_presentation', {'color_information': color_info})
return COLOR_BOX_HTML.format(command=command, color=color_to_hex(color_info['color']))


def lsp_color_to_phantom(view: sublime.View, color_info: ColorInformation) -> sublime.Phantom:
region = range_to_region(color_info['range'], view)
return sublime.Phantom(region, lsp_color_to_html(view, color_info), sublime.LAYOUT_INLINE)
return sublime.Phantom(region, lsp_color_to_html(color_info), sublime.LAYOUT_INLINE)


def document_color_params(view: sublime.View) -> Dict[str, Any]:
Expand Down
3 changes: 2 additions & 1 deletion plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def _on_color_boxes_async(self, view: sublime.View, response: List[ColorInformat
if response is None: # Guard against spec violation from certain language servers
self.color_phantoms.update([])
return
self.color_phantoms.update([lsp_color_to_phantom(view, color_info) for color_info in response])
phantoms = [lsp_color_to_phantom(view, color_info) for color_info in response]
sublime.set_timeout(lambda: self.color_phantoms.update(phantoms))

# --- textDocument/documentLink ------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_lsp_color_to_phantom(self) -> None:
}
]
phantom = lsp_color_to_phantom(self.view, response[0])
self.assertEqual(phantom.content, lsp_color_to_html(self.view, response[0]))
self.assertEqual(phantom.content, lsp_color_to_html(response[0]))
self.assertEqual(phantom.region, range_to_region(response[0]["range"], self.view))

def test_document_color_params(self) -> None:
Expand Down

0 comments on commit 6aa77ff

Please sign in to comment.