Skip to content

Commit

Permalink
Handle new doctor json format (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoub-benali authored Jun 4, 2023
1 parent 7693163 commit 80c9bb4
Showing 1 changed file with 106 additions and 66 deletions.
172 changes: 106 additions & 66 deletions core/handle_execute_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,86 +41,126 @@ def show_stacktrace(session: Session, args: Any) -> None:


def run_doctor(session: Session, args: Any) -> None:
if isinstance(args, list) and args:

content = json.loads(args[0])
def parse_build_target(targets, doctor_version) -> str:
default_target_labels = OrderedDict([
('targetType', 'Target Type'),
('compilationStatus', 'Compilation status'),
('diagnostics', 'Diagnostics'),
('interactive', 'Interactive'),
('semanticdb', 'SemanticDB'),
('debugging', 'Debugging'),
('java', 'Java Support'),
('recommendation', 'Recommendation')
])

legacy_target_labels = OrderedDict([
('scalaVersion', 'Scala Version'),
('diagnostics', 'Diagnostics'),
('gotoDefinition', 'Goto Definition'),
('completions', 'Completions'),
('findReferences', 'Find References')
])

target_labels = default_target_labels if doctor_version > 0 else legacy_target_labels

if not targets:
return ''

lines = []
markdown = "## Build Targets\n"
for target in targets:
lines.append('#### {}'.format(target.get('buildTarget')))
lines.append('```')

for field, label in target_labels.items():
if target.get(field):
lines.append('* {0:<20}: {1}'.format(label, target.get(field)))

lines.append("```")

markdown += "{}\n\n".format('\n'.join(lines))

return markdown

def parse_explanations(explanations) -> str:
if explanations:
markdown = "## Explanations\n"
for explanation in explanations:
markdown += '{}\n\n'.format(explanation.get('title'))
for deep_explanation in explanation.get('explanations'):
markdown += '* {}\n'.format(deep_explanation)
markdown += '\n\n'
return markdown
else:
return ''


if isinstance(args, list) and args:
content = json.loads(args[0])
doctor_version = 0 if content.get('version') is None else int(content.get('version'))

header = content.get('header')
messages = content.get('messages')
targets = content.get('targets')
explanations = content.get('explanations')

markdown = "# {} \n\n".format(content.get('title'))

if doctor_version >= 3:
fields = [
'buildTool',
'buildServer',
'importBuildStatus',
'jdkInfo',
'serverInfo'
if doctor_version == 4:
header_fields = [
'buildTargetDescription',
'serverInfo',
'jdkInfo'
]

for field in fields:
if header.get(field):
markdown += "{} \n\n".format(header.get(field))

markdown += "{} \n\n".format(header.get('buildTargetDescription'))
else:
markdown += "{} \n\n".format(content.get('headerText'))

if messages:
for message in messages:
markdown += "### {} \n".format(message.get('title'))
for recommendation in message.get('recommendations'):
markdown += '* {}\n'.format(recommendation)
markdown += '\n\n'
elif targets:
markdown += "## Build Targets\n"

default_target_labels = OrderedDict([
('targetType', 'Target Type'),
('compilationStatus', 'Compilation status'),
('diagnostics', 'Diagnostics'),
('interactive', 'Interactive'),
('semanticdb', 'SemanticDB'),
('debugging', 'Debugging'),
('java', 'Java Support'),
('recommendation', 'Recommendation')
])

legacy_target_labels = OrderedDict([
('scalaVersion', 'Scala Version'),
('diagnostics', 'Diagnostics'),
('gotoDefinition', 'Goto Definition'),
('completions', 'Completions'),
('findReferences', 'Find References')
folder_header_fields = OrderedDict([
('buildTool', 'Build tool'),
('buildServer', 'Build Server'),
('importBuildStatus', 'Import Build Status')
])

target_labels = default_target_labels if doctor_version > 0 else legacy_target_labels
for field in header_fields:
value = header.get(field)
if value:
markdown += "{} \n\n".format(value)

lines = []
for target in targets:
lines.append('#### {}'.format(target.get('buildTarget')))
lines.append('```')
folders = content.get('folders')
for folder in folders:
header = folder.get('header')
for field, label in folder_header_fields.items():
if header.get(field):
markdown += "{}: {} \n\n".format(label, header.get(field))

for field, label in target_labels.items():
if target.get(field):
lines.append('* {0:<20}: {1}'.format(label, target.get(field)))

lines.append("```")

markdown += "{}\n\n".format('\n'.join(lines))

if explanations:
markdown += "## Explanations\n"
for explanation in explanations:
markdown += '{}\n\n'.format(explanation.get('title'))
for deep_explanation in explanation.get('explanations'):
markdown += '* {}\n'.format(deep_explanation)
markdown += parse_build_target(folder.get('targets'), doctor_version)
markdown += parse_explanations(folder.get('explanations'))
else:
messages = content.get('messages')
targets = content.get('targets')
explanations = content.get('explanations')

if doctor_version == 3:
fields = [
'buildTool',
'buildServer',
'importBuildStatus',
'jdkInfo',
'serverInfo'
]

for field in fields:
if header.get(field):
markdown += "{} \n\n".format(header.get(field))

markdown += "{} \n\n".format(header.get('buildTargetDescription'))
else:
markdown += "{} \n\n".format(content.get('headerText'))

if messages:
for message in messages:
markdown += "### {} \n".format(message.get('title'))
for recommendation in message.get('recommendations'):
markdown += '* {}\n'.format(recommendation)
markdown += '\n\n'
elif targets:
markdown += parse_build_target(targets, doctor_version)
markdown += parse_explanations(explanations)

custom_css = """
.metals-doctor { padding: 1.5rem }
Expand Down

0 comments on commit 80c9bb4

Please sign in to comment.