diff --git a/src/apexguru/apex-guru-service.ts b/src/apexguru/apex-guru-service.ts index e4fb791..9696ef5 100644 --- a/src/apexguru/apex-guru-service.ts +++ b/src/apexguru/apex-guru-service.ts @@ -128,8 +128,8 @@ export function transformStringToRuleResult(fileName: string, jsonString: string }; reports.forEach(parsed => { - const encodedCodeBefore = parsed.properties.find((prop: ApexGuruProperty) => prop.name === 'code_before')?.value; - const encodedCodeAfter = parsed.properties.find((prop: ApexGuruProperty) => prop.name === 'code_after')?.value; + const encodedCodeBefore = parsed.properties.find((prop: ApexGuruProperty) => prop.name === 'code_before')?.value ?? ''; + const encodedCodeAfter = parsed.properties.find((prop: ApexGuruProperty) => prop.name === 'code_after')?.value ?? ''; const lineNumber = parseInt(parsed.properties.find((prop: ApexGuruProperty) => prop.name === 'line_number')?.value); const violation: ApexGuruViolation = { @@ -139,8 +139,9 @@ export function transformStringToRuleResult(fileName: string, jsonString: string category: parsed.type, // Replace with actual category if available line: lineNumber, column: 1, - currentCode: encodedCodeBefore ? Buffer.from(encodedCodeBefore, 'base64').toString('utf8') : encodedCodeBefore, - suggestedCode: encodedCodeAfter ? Buffer.from(encodedCodeAfter, 'base64').toString('utf8') : encodedCodeAfter, + currentCode: Buffer.from(encodedCodeBefore, 'base64').toString('utf8'), + suggestedCode: Buffer.from(encodedCodeAfter, 'base64').toString('utf8'), + url: fileName }; ruleResult.violations.push(violation); diff --git a/src/lib/diagnostics.ts b/src/lib/diagnostics.ts index ab033ff..6da9ae8 100644 --- a/src/lib/diagnostics.ts +++ b/src/lib/diagnostics.ts @@ -92,15 +92,15 @@ export class DiagnosticManager { if (engine === 'apexguru') { const apexGuruViolation = violation as ApexGuruViolation; - if (apexGuruViolation.suggestedCode !== undefined) { + if (apexGuruViolation.suggestedCode) { diagnostic.relatedInformation = [ new vscode.DiagnosticRelatedInformation( - new vscode.Location(vscode.Uri.parse('Current Code'), range), - `${apexGuruViolation.currentCode}` + new vscode.Location(vscode.Uri.parse(violation.url), range), + `Current Code: ${apexGuruViolation.currentCode}` ), new vscode.DiagnosticRelatedInformation( - new vscode.Location(vscode.Uri.parse('ApexGuru Suggestions'), range), - `${apexGuruViolation.suggestedCode}` + new vscode.Location(vscode.Uri.parse(violation.url), range), + `ApexGuru Suggestions: ${apexGuruViolation.suggestedCode}` ) ]; } diff --git a/src/test/suite/apexguru/apex-guru-service.test.ts b/src/test/suite/apexguru/apex-guru-service.test.ts index c83471b..f849de9 100644 --- a/src/test/suite/apexguru/apex-guru-service.test.ts +++ b/src/test/suite/apexguru/apex-guru-service.test.ts @@ -176,8 +176,9 @@ suite('Apex Guru Test Suite', () => { category: 'BestPractices', line: 10, column: 1, - currentCode: undefined, - suggestedCode: 'System.out.println("Hello World");' + currentCode: '', + suggestedCode: 'System.out.println("Hello World");', + url: "TestFile.cls" }] }); });