Skip to content

Commit 8d2ba77

Browse files
committed
Fix language id computation for JDT URIs
1 parent 783bb4b commit 8d2ba77

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootLanguageServerBootApp.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ LanguageComputer languageComputer() {
367367

368368
@Override
369369
public LanguageId computeLanguage(URI uri) {
370-
Path path = Paths.get(uri);
370+
Path path = Paths.get(uri.getPath());
371371
String fileName = path.getFileName().toString();
372372
switch (Files.getFileExtension(fileName)) {
373373
case "properties":
@@ -379,7 +379,9 @@ public LanguageId computeLanguage(URI uri) {
379379
return LanguageId.BOOT_PROPERTIES_YAML;
380380
case "java":
381381
return LanguageId.JAVA;
382-
case "xml":
382+
case "class":
383+
return LanguageId.CLASS;
384+
case "xml":
383385
return LanguageId.XML;
384386
case "factories":
385387
return LanguageId.SPRING_FACTORIES;

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/cron/CronReconcilerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
111
package org.springframework.ide.vscode.boot.java.cron;
212

313
import static org.junit.Assert.assertEquals;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.boot.test;
12+
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
import java.net.URI;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.extension.ExtendWith;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.context.annotation.Import;
22+
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
23+
import org.springframework.ide.vscode.boot.bootiful.HoverTestConf;
24+
import org.springframework.ide.vscode.commons.languageserver.util.LanguageComputer;
25+
import org.springframework.ide.vscode.commons.util.text.LanguageId;
26+
import org.springframework.test.context.junit.jupiter.SpringExtension;
27+
28+
@ExtendWith(SpringExtension.class)
29+
@BootLanguageServerTest
30+
@Import(HoverTestConf.class)
31+
public class LanguageComputerTest {
32+
33+
@Autowired
34+
LanguageComputer languageComputer;
35+
36+
@Test
37+
void jdtUri() {
38+
assertThat(languageComputer).isNotNull();
39+
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");
40+
assertThat(languageComputer.computeLanguage(uri)).isEqualTo(LanguageId.CLASS);
41+
42+
uri = URI.create("file:///project/org.springframework.data.mapping.model/PropertyNameFieldNamingStrategy.java");
43+
assertThat(languageComputer.computeLanguage(uri)).isEqualTo(LanguageId.JAVA);
44+
45+
}
46+
47+
}

0 commit comments

Comments
 (0)