From 8d2ba77fd044b9d4e83e453984cc100cdcd20d13 Mon Sep 17 00:00:00 2001 From: aboyko Date: Tue, 10 Dec 2024 15:36:49 -0500 Subject: [PATCH] Fix language id computation for JDT URIs --- .../boot/app/BootLanguageServerBootApp.java | 6 ++- .../boot/java/cron/CronReconcilerTest.java | 10 ++++ .../boot/test/LanguageComputerTest.java | 47 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/LanguageComputerTest.java diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootLanguageServerBootApp.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootLanguageServerBootApp.java index 82a258777b..e6705f9ab0 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootLanguageServerBootApp.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootLanguageServerBootApp.java @@ -367,7 +367,7 @@ LanguageComputer languageComputer() { @Override public LanguageId computeLanguage(URI uri) { - Path path = Paths.get(uri); + Path path = Paths.get(uri.getPath()); String fileName = path.getFileName().toString(); switch (Files.getFileExtension(fileName)) { case "properties": @@ -379,7 +379,9 @@ public LanguageId computeLanguage(URI uri) { return LanguageId.BOOT_PROPERTIES_YAML; case "java": return LanguageId.JAVA; - case "xml": + case "class": + return LanguageId.CLASS; + case "xml": return LanguageId.XML; case "factories": return LanguageId.SPRING_FACTORIES; diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/CronReconcilerTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/CronReconcilerTest.java index eb5fb3329d..25091ae526 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/CronReconcilerTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/CronReconcilerTest.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2024 Broadcom, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Broadcom, Inc. - initial API and implementation + *******************************************************************************/ package org.springframework.ide.vscode.boot.java.cron; import static org.junit.Assert.assertEquals; diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/LanguageComputerTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/LanguageComputerTest.java new file mode 100644 index 0000000000..13c904e91f --- /dev/null +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/test/LanguageComputerTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2024 Broadcom, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Broadcom, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.boot.test; + + +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URI; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; +import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest; +import org.springframework.ide.vscode.boot.bootiful.HoverTestConf; +import org.springframework.ide.vscode.commons.languageserver.util.LanguageComputer; +import org.springframework.ide.vscode.commons.util.text.LanguageId; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@BootLanguageServerTest +@Import(HoverTestConf.class) +public class LanguageComputerTest { + + @Autowired + LanguageComputer languageComputer; + + @Test + void jdtUri() { + assertThat(languageComputer).isNotNull(); + URI uri = URI.create("jdt://contents/spring-data-commons-1.11.4.RELEASE.jar/org.springframework.data.mapping.model/PropertyNameFieldNamingStrategy.class?%3Dboot13_with_mongo%2F%5C%2FUsers%5C%2Faboyko%5C%2F.m2%5C%2Frepository%5C%2Forg%5C%2Fspringframework%5C%2Fdata%5C%2Fspring-data-commons%5C%2F1.11.4.RELEASE%5C%2Fspring-data-commons-1.11.4.RELEASE.jar%3Corg.springframework.data.mapping.model%28PropertyNameFieldNamingStrategy.class"); + assertThat(languageComputer.computeLanguage(uri)).isEqualTo(LanguageId.CLASS); + + uri = URI.create("file:///project/org.springframework.data.mapping.model/PropertyNameFieldNamingStrategy.java"); + assertThat(languageComputer.computeLanguage(uri)).isEqualTo(LanguageId.JAVA); + + } + +}