Fix language id computation for JDT URIs

This commit is contained in:
aboyko
2024-12-10 15:36:49 -05:00
parent 783bb4b32d
commit 8d2ba77fd0
3 changed files with 61 additions and 2 deletions

View File

@@ -367,7 +367,7 @@ public class BootLanguageServerBootApp {
@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 class BootLanguageServerBootApp {
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;

View File

@@ -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;

View File

@@ -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);
}
}