def show_phantoms(self, view):
"""Show phantoms for compilation errors.
Args:
view (sublime.View): current view
"""
view.erase_phantoms(PopupErrorVis._TAG)
if view.buffer_id() not in self.phantom_sets:
phantom_set = sublime.PhantomSet(view, PopupErrorVis._TAG)
self.phantom_sets[view.buffer_id()] = phantom_set
else:
phantom_set = self.phantom_sets[view.buffer_id()]
phantoms = []
current_error_dict = self.err_regions[view.buffer_id()]
for err in current_error_dict:
errors_dict = current_error_dict[err]
errors_html = PhantomErrorVis._as_html(errors_dict)
pt = view.text_point(err - 1, 1)
phantoms.append(sublime.Phantom(
sublime.Region(pt, view.line(pt).b),
errors_html,
sublime.LAYOUT_BELOW,
on_navigate=self._on_phantom_navigate))
phantom_set.update(phantoms)
python类LAYOUT_BELOW的实例源码
def create_phantom(view: sublime.View, diagnostic: Diagnostic) -> sublime.Phantom:
region = diagnostic.range.to_region(view)
# TODO: hook up hide phantom (if keeping them)
content = create_phantom_html(diagnostic.message)
return sublime.Phantom(
region,
'<p>' + content + '</p>',
sublime.LAYOUT_BELOW,
lambda href: on_phantom_navigate(view, href, region.begin())
)
def build_phantoms(view, errs, formatter):
phantoms = []
show_focus_links = len(errs) > 1
for tbck in errs:
line = tbck['line']
text = tbck['text']
testcase = tbck.get('testcase')
if text == '':
continue
pt = view.text_point(line - 1, 0)
indentation = get_indentation_at(view, pt)
text = formatter.format_text(text, indentation)
if show_focus_links and testcase:
focus_link = (
' <a href="focus:{}">focus test</a>'.format(testcase))
lines = text.split('<br />')
text = '<br />'.join([lines[0] + focus_link] + lines[1:])
phantoms.append(sublime.Phantom(
sublime.Region(pt, view.line(pt).b),
('<body id=inline-error>' + STYLESHEET +
'<div class="error">' +
'<span class="message">' + text + '</span>' +
'</div>' +
'</body>'),
sublime.LAYOUT_BELOW, _on_navigate))
return phantoms
def createPhantom(self, doc, view):
xref_data = self.data[view.window().id()];
loc = sublime.Region(0,0);
return sublime.Phantom(loc, doc, sublime.LAYOUT_BELOW, lambda link: self.processLink(link, self.callers, view));
def highlight(self, file_path, row, col, message):
view = self.window.find_open_file(file_path)
if view:
view.add_phantom(
self.name,
sublime.Region(row, col),
PHANTOM_TEMPLATE.format(message),
sublime.LAYOUT_BELOW,
)