Skip to content

Commit

Permalink
Merge pull request #535 from jakobandersen/issue_529
Browse files Browse the repository at this point in the history
Fix warning formatting for function lookup
  • Loading branch information
vermeeren authored May 25, 2020
2 parents 7ab6e4e + c5a2cac commit 50a830d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
21 changes: 11 additions & 10 deletions breathe/directive/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,42 @@
from docutils import nodes
from docutils.nodes import Node

from typing import List
from typing import Any, Dict, List, Optional, Sequence


class WarningHandler:
def __init__(self, state, context):
def __init__(self, state, context: Dict[str, Any]) -> None:
self.state = state
self.context = context

def warn(self, raw_text, rendered_nodes=None):
raw_text = self.format(raw_text)
def warn(self, raw_text: str, *, rendered_nodes: Sequence[nodes.Node] = None,
unformatted_suffix: str = '') -> List[nodes.Node]:
raw_text = self.format(raw_text) + unformatted_suffix
if rendered_nodes is None:
rendered_nodes = [nodes.paragraph("", "", nodes.Text(raw_text))]
return [
nodes.warning("", *rendered_nodes),
self.state.document.reporter.warning(raw_text, line=self.context['lineno'])
]
]

def format(self, text):
def format(self, text: str) -> str:
return text.format(**self.context)


def create_warning(project_info, state, lineno, **kwargs):
def create_warning(project_info: Optional[ProjectInfo], state, lineno: int,
**kwargs) -> WarningHandler:
tail = ''
if project_info:
tail = 'in doxygen xml output for project "{project}" from directory: {path}'.format(
project=project_info.name(),
path=project_info.project_path()
)
)

context = dict(
lineno=lineno,
tail=tail,
**kwargs
)

)
return WarningHandler(state, context)


Expand Down
9 changes: 5 additions & 4 deletions breathe/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,30 @@ def run(self) -> List[Node]:
'"{namespace}{function}" with arguments ({args}) {tail}.\n' \
'Potential matches:\n'

# We want to create a raw_text string for the console output and a set of docutils nodes
# We want to create a string for the console output and a set of docutils nodes
# for rendering into the final output. We handle the final output as a literal string
# with a txt based list of the options.
raw_text = message
literal_text = ''

# TODO: We're cheating here with the set() as signatures has repeating entries for some
# reason (failures in the matcher_stack code) so we consolidate them by shoving them in
# a set to remove duplicates. Should be fixed!
signatures = ''
for i, entry in enumerate(sorted(set(error.signatures))):
if i:
literal_text += '\n'
# Replace new lines with a new line & enough spacing to reach the appropriate
# alignment for our simple plain text list
literal_text += '- %s' % entry.replace('\n', '\n ')
raw_text += ' - %s\n' % entry.replace('\n', '\n ')
signatures += ' - %s\n' % entry.replace('\n', '\n ')
block = nodes.literal_block('', '', nodes.Text(literal_text))
formatted_message = warning.format(message)
warning_nodes = [
nodes.paragraph("", "", nodes.Text(formatted_message)),
block
]
result = warning.warn(raw_text, warning_nodes)
result = warning.warn(message, rendered_nodes=warning_nodes,
unformatted_suffix=signatures)
return result

target_handler = create_target_handler(self.options, project_info, self.state.document)
Expand Down

0 comments on commit 50a830d

Please sign in to comment.