Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests for language server bundle (Incubation)
Bundle-SymbolicName: org.eclipse.lsp4e.test;singleton:=true
Bundle-Version: 0.16.10.qualifier
Bundle-Version: 0.16.11.qualifier
Fragment-Host: org.eclipse.lsp4e
Bundle-Vendor: Eclipse LSP4E
Bundle-RequiredExecutionEnvironment: JavaSE-21
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.lsp4e.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</parent>
<artifactId>org.eclipse.lsp4e.test</artifactId>
<packaging>eclipse-test-plugin</packaging>
<version>0.16.10-SNAPSHOT</version>
<version>0.16.11-SNAPSHOT</version>

<properties>
<os-jvm-flags /> <!-- for the default case -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.lsp4e.test.edit;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down Expand Up @@ -81,6 +82,7 @@
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;

public class LSPEclipseUtilsTest extends AbstractTestWithProject {
Expand Down Expand Up @@ -637,5 +639,18 @@ public static Stream<Arguments> getHtmlDocString() {
void getHtmlDocString(Either<@Nullable String, MarkupContent> arg, String expected) throws Exception {
assertEquals(expected, LSPEclipseUtils.getHtmlDocString(arg));
}

@ParameterizedTest
@CsvSource({
"file:///C:/Users/username/path/to/SomeDir/SomeType.hpp, SomeType.hpp",
"file:///home/username/path/to/SomeDir/SomeType.hpp, SomeType.hpp",
"file:///,"
})
void testReadingFileNameFromUri(String uriText, String expectedFileName) {
URI uri = URI.create(uriText);

String actualFileName = assertDoesNotThrow(() -> LSPEclipseUtils.getFileName(uri));
assertEquals(expectedFileName, actualFileName);
}

}
9 changes: 9 additions & 0 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,15 @@ public static CallHierarchyPrepareParams toCallHierarchyPrepareParams(int offset
return toPath(toBuffer(document));
}

public static @Nullable String getFileName(URI uri) {
try {
return java.nio.file.Path.of(uri).getFileName().toString();
} catch (Exception e) {
LanguageServerPlugin.logWarning("Failed to parse file name from URI " + uri, e); //$NON-NLS-1$
}
return null;
}

public static int toEclipseMarkerSeverity(@Nullable DiagnosticSeverity lspSeverity) {
if (lspSeverity == null) {
// if severity is empty it is up to the client to interpret diagnostics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package org.eclipse.lsp4e.operations.symbols.internal;

import java.net.URI;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -22,6 +21,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4e.LSPEclipseUtils;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.outline.SymbolsModel.DocumentSymbolWithURI;
import org.eclipse.lsp4e.ui.SymbolIconProvider;
Expand Down Expand Up @@ -106,11 +106,8 @@ private SymbolIconProvider getIconProvider(Object symbol) {
return defaultIconProvider;
}

String fileName = null;
try {
fileName = Path.of(uri.getPath()).getFileName().toString();
} catch (Exception e) {
LanguageServerPlugin.logWarning("Failed to parse file name from URI " + uri, e); //$NON-NLS-1$
String fileName = LSPEclipseUtils.getFileName(uri);
if (fileName == null) {
return defaultIconProvider;
}

Expand Down Expand Up @@ -146,8 +143,8 @@ private SymbolIconProvider getIconProvider(Object symbol) {
}

try {
return URI.create(uri);
} catch (IllegalArgumentException e) {
return LSPEclipseUtils.toUri(uri);
} catch (Exception e) {
LanguageServerPlugin.logWarning("Failed to parse URI " + uri, e); //$NON-NLS-1$
return null;
}
Expand Down
Loading