diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java index c4a7ef1b98f5..a1bb5bdd48e2 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java @@ -193,5 +193,8 @@ void shrink() { this.compilationUnit.topLevelNodes.clear(); } this.content = null; + if (this.textDocument != null) { + this.textDocument.cleanUp(); + } } } diff --git a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/StringTextDocument.java b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/StringTextDocument.java index 6caf84ce82a7..d5f077b4b3fb 100644 --- a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/StringTextDocument.java +++ b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/StringTextDocument.java @@ -33,6 +33,11 @@ class StringTextDocument extends TextDocument { this.text = text; } + @Override + public void cleanUp() { + this.textLineMap = null; + } + @Override public TextDocument apply(TextDocumentChange textDocumentChange) { int startOffset = 0; diff --git a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/TextDocument.java b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/TextDocument.java index 99684f484e93..a5bfeca50a08 100644 --- a/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/TextDocument.java +++ b/compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/TextDocument.java @@ -27,6 +27,8 @@ public abstract class TextDocument { private LineMap lineMap; + public abstract void cleanUp(); + public abstract TextDocument apply(TextDocumentChange textDocumentChange); protected abstract LineMap populateTextLineMap();