From 586fc3830aba2a3f57ad86e2364e810afdebac44 Mon Sep 17 00:00:00 2001 From: Markus Amshove Date: Fri, 6 Dec 2024 13:26:54 +0100 Subject: [PATCH 1/2] Fix open preview codelens position for INCLUDEd inputs --- .../InputPreviewCodeLensProvider.java | 2 +- .../codelens/InputPreviewCodelensTests.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/libs/natls/src/main/java/org/amshove/natls/codelens/InputPreviewCodeLensProvider.java b/libs/natls/src/main/java/org/amshove/natls/codelens/InputPreviewCodeLensProvider.java index 5f4d0f44d..37a942963 100644 --- a/libs/natls/src/main/java/org/amshove/natls/codelens/InputPreviewCodeLensProvider.java +++ b/libs/natls/src/main/java/org/amshove/natls/codelens/InputPreviewCodeLensProvider.java @@ -30,7 +30,7 @@ public List provideCodeLens(LanguageServerFile file) for (int i = 0; i < inputs.size(); i++) { var input = inputs.get(i); - var lens = codeLensWithoutCommand("Open Preview", LspUtil.toRange(input)); + var lens = codeLensWithoutCommand("Open Preview", LspUtil.toRange(input.diagnosticPosition())); var params = new InputStructureParams(); params.setUri(file.getUri()); params.setInputIndex(i); diff --git a/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java b/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java index 245add6c8..466be4f6e 100644 --- a/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java +++ b/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java @@ -63,4 +63,30 @@ void codeLensShouldNotBeShownWhenFeatureIsDisabledLater() configureLSConfig(newConfig); testCodeLens(document, lenses -> assertThat(lenses).noneMatch(l -> l.getCommand().getTitle().contains("Open Preview"))); } + + @Test + void codeLensShouldBeShownAtTheIncludeOfACopyCode() + { + var config = LSConfiguration.createDefault(); + config.getMaps().setEnablePreview(true); + configureLSConfig(config); + createOrSaveFile("LIBONE", "MYCC.NSC", """ + INPUT 'Hello + + INPUT 'Hello 2' + """); + var document = createOrSaveFile("LIBONE", "PROG.NSP", """ + DEFINE DATA LOCAL + END-DEFINE + INCLUDE MYCC + END + """); + + testCodeLens( + document, + // all on the line of the INCLUDE + lenses -> assertThat(lenses.stream().filter(l -> l.getCommand().getTitle().contains("Open Preview"))) + .allMatch(l -> l.getRange().getStart().getLine() == 2) + ); + } } From 67e56636d39f558e01ebb6954acb243a46b5f540 Mon Sep 17 00:00:00 2001 From: Markus Amshove Date: Fri, 6 Dec 2024 14:01:36 +0100 Subject: [PATCH 2/2] Check for emptiness --- .../org/amshove/natls/codelens/InputPreviewCodelensTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java b/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java index 466be4f6e..e98ef8ef6 100644 --- a/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java +++ b/libs/natls/src/test/java/org/amshove/natls/codelens/InputPreviewCodelensTests.java @@ -86,6 +86,7 @@ void codeLensShouldBeShownAtTheIncludeOfACopyCode() document, // all on the line of the INCLUDE lenses -> assertThat(lenses.stream().filter(l -> l.getCommand().getTitle().contains("Open Preview"))) + .isNotEmpty() .allMatch(l -> l.getRange().getStart().getLine() == 2) ); }