Skip to content

Commit accad00

Browse files
committed
Normalize colons in Windows paths
1 parent fa23d8f commit accad00

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from 'chai';
2+
3+
import { uris_equal } from './utils';
4+
5+
describe('uris_equal', () => {
6+
it('should workaround Windows paths/Pyright issues', () => {
7+
const result = uris_equal(
8+
'file:///d%3A/a/jupyterlab-lsp/jupyterlab-lsp/atest/output/windows_39_4/home/n%C3%B6te%20b%C3%B2%C3%B3ks/example.py',
9+
'file:///d:/a/jupyterlab-lsp/jupyterlab-lsp/atest/output/windows_39_4/home/n%C3%B6te%20b%C3%B2%C3%B3ks/example.py'
10+
);
11+
expect(result).to.equal(true);
12+
});
13+
});

packages/jupyterlab-lsp/src/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PageConfig } from '@jupyterlab/coreutils';
22
import { ReadonlyJSONObject, ReadonlyJSONValue } from '@lumino/coreutils';
33
import mergeWith from 'lodash.mergewith';
44

5-
const RE_PATH_ANCHOR = /^file:\/\/([^\/]+|\/[A-Z]:)/;
5+
const RE_PATH_ANCHOR = /^file:\/\/([^\/]+|\/[a-zA-Z](?::|%3A))/;
66

77
export async function sleep(timeout: number) {
88
return new Promise<void>(resolve => {
@@ -142,7 +142,11 @@ export function is_win_path(uri: string) {
142142
* lowercase the drive component of a URI
143143
*/
144144
export function normalize_win_path(uri: string) {
145-
return uri.replace(RE_PATH_ANCHOR, it => it.toLowerCase());
145+
// Pyright encodes colon on Windows, see:
146+
// https://github.com/krassowski/jupyterlab-lsp/pull/587#issuecomment-844225253
147+
return uri.replace(RE_PATH_ANCHOR, it =>
148+
it.replace('%3A', ':').toLowerCase()
149+
);
146150
}
147151

148152
export function uri_to_contents_path(child: string, parent?: string) {

0 commit comments

Comments
 (0)