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()) {