Skip to content

Commit

Permalink
feat(robocop): with code descriptions in robocop diagnostics you ca…
Browse files Browse the repository at this point in the history
…n jump directly to the website where the rule is explained

closes  #152
  • Loading branch information
d-biehl committed Aug 26, 2023
1 parent 8f772ef commit 46125a5
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Position,
Range,
)
from robotcode.core.utils.version import create_version_from_str
from robotcode.core.utils.version import Version, create_version_from_str
from robotcode.language_server.common.decorators import language_id
from robotcode.language_server.common.parts.diagnostics import DiagnosticsResult
from robotcode.language_server.common.parts.workspace import WorkspaceFolder
Expand Down Expand Up @@ -172,11 +172,25 @@ async def run_check(self, ast_model, filename, source=None): # type: ignore
else DiagnosticSeverity.HINT,
source=self.source_name,
code=f"{issue.name}-{issue.severity.value}{issue.rule_id}",
code_description=CodeDescription(
href=f"https://robocop.readthedocs.io/en/stable/rules.html#{issue.name}-{issue.severity.value}{issue.rule_id}".lower()
),
code_description=self.get_code_description(robocop_version, issue),
)

result.append(d)

return result

def get_code_description(self, version: Version, issue: Any) -> Optional[CodeDescription]:
if version < (3, 0):
return None

base = f"https://robocop.readthedocs.io/en/{version.major}.{version.minor}.{version.patch}"

if version < (4, 0):
return CodeDescription(href=f"{base}/rules.html#{issue.name}".lower())

if version < (4, 1):
return CodeDescription(href=f"{base}/rules.html#{issue.name}-{issue.severity.value}{issue.rule_id}".lower())

return CodeDescription(
href=f"{base}/rules_list.html#{issue.name}-{issue.severity.value}{issue.rule_id}".lower()
)

0 comments on commit 46125a5

Please sign in to comment.