From 004ca36864ceddeb2b2639bd8b4e8f6fd68a5ff3 Mon Sep 17 00:00:00 2001 From: TharmiganK Date: Tue, 13 Aug 2024 09:28:00 +0530 Subject: [PATCH] Fix location matching logic --- .../stdlib/http/compiler/HttpServiceValidator.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpServiceValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpServiceValidator.java index 2cacde8bbc..c54dcd2ead 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpServiceValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/HttpServiceValidator.java @@ -244,14 +244,19 @@ private static void checkForServiceImplementationErrors(SyntaxNodeAnalysisContex Location diagnosticLocation = diagnostic.location(); if (diagnostic.message().contains("no implementation found for the method 'resource function") - && diagnosticLocation.textRange().equals(location.textRange()) - && diagnosticLocation.lineRange().equals(location.lineRange())) { + && intersects(location, diagnosticLocation)) { enableImplementServiceContractCodeAction(context, serviceType, location); return; } } } + private static boolean intersects(Location targetLocation, Location diagnosticLocation) { + return targetLocation.lineRange().startLine().line() <= diagnosticLocation.lineRange().startLine().line() && + targetLocation.lineRange().endLine().line() >= diagnosticLocation.lineRange().endLine().line() && + targetLocation.textRange().intersectionExists(diagnosticLocation.textRange()); + } + private static void validateResourceLinks(SyntaxNodeAnalysisContext syntaxNodeAnalysisContext, LinksMetaData linksMetaData) { if (!linksMetaData.hasNameReferenceObjects()) {