|
31 | 31 | import java.io.OutputStream; |
32 | 32 | import java.lang.reflect.Method; |
33 | 33 | import java.net.URI; |
34 | | -import java.net.URISyntaxException; |
35 | 34 | import java.nio.file.Paths; |
36 | 35 | import java.util.ArrayList; |
37 | 36 | import java.util.Arrays; |
@@ -1354,21 +1353,8 @@ public static URI toUri(IPath absolutePath) { |
1354 | 1353 | } |
1355 | 1354 |
|
1356 | 1355 | public static URI toUri(File file) { |
1357 | | - // URI scheme specified by language server protocol and LSP |
1358 | | - try { |
1359 | | - final var path = file.getAbsoluteFile().toURI().getPath(); |
1360 | | - if (path.startsWith("//")) { // UNC path like //localhost/c$/Windows/ //$NON-NLS-1$ |
1361 | | - // split: authority = "localhost", absPath = "/c$/Windows/" |
1362 | | - final int slash = path.indexOf('/', 2); |
1363 | | - final String authority = slash > 2 ? path.substring(2, slash) : path.substring(2); |
1364 | | - final String absPath = slash > 2 ? path.substring(slash) : "/"; //$NON-NLS-1$ |
1365 | | - return new URI(FILE_SCHEME, authority, absPath, null); |
1366 | | - } |
1367 | | - return new URI(FILE_SCHEME, "", path, null); //$NON-NLS-1$ |
1368 | | - } catch (URISyntaxException e) { |
1369 | | - LanguageServerPlugin.logError(e); |
1370 | | - return file.getAbsoluteFile().toURI(); |
1371 | | - } |
| 1356 | + // Perform one round-trip to make sure all non-ASCII characters are properly encoded. |
| 1357 | + return URI.create((file.toPath().toUri()).toASCIIString()); |
1372 | 1358 | } |
1373 | 1359 |
|
1374 | 1360 | public static @Nullable IFile getFile(@Nullable IDocument document) { |
|
0 commit comments