Skip to content

Commit

Permalink
Fix combining paths with empty uri (microsoft#7037)
Browse files Browse the repository at this point in the history
* Fix combining paths with empty uri

* Force empty to be case sensitive

* Remove unneeded code
  • Loading branch information
rchiodo committed Jan 18, 2024
1 parent c44673d commit 81e85d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
18 changes: 5 additions & 13 deletions packages/pyright-internal/src/common/uri/emptyUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* URI class that represents an empty URI.
*/

import { BaseUri } from './baseUri';
import { FileUri } from './fileUri';
import { Uri } from './uri';

const EmptyKey = '<empty>';

export class EmptyUri extends BaseUri {
export class EmptyUri extends FileUri {
private static _instance = new EmptyUri();
private constructor() {
super(EmptyKey);
super(EmptyKey, '', '', '', undefined, /* isCaseSensitive */ true);
}

static get instance() {
Expand All @@ -37,11 +37,7 @@ export class EmptyUri extends BaseUri {
return this;
}

get isCaseSensitive(): boolean {
return true;
}

get fragment(): string {
override get fragment(): string {
return '';
}

Expand Down Expand Up @@ -104,10 +100,6 @@ export class EmptyUri extends BaseUri {
return 0;
}

override combinePaths(...paths: string[]): Uri {
return this;
}

override getShortenedFileName(maxDirLength: number): string {
return '';
}
Expand All @@ -116,7 +108,7 @@ export class EmptyUri extends BaseUri {
return this;
}

withFragment(fragment: string): Uri {
override withFragment(fragment: string): Uri {
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/common/uri/fileUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Uri } from './uri';

export class FileUri extends BaseUri {
private _formattedString: string | undefined;
private constructor(
protected constructor(
key: string,
private readonly _filePath: string,
private readonly _query: string,
Expand Down
6 changes: 5 additions & 1 deletion packages/pyright-internal/src/tests/uri.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,17 @@ test('empty', () => {
assert.equal(empty4.isEmpty(), true);
assert.ok(empty4.equals(empty3));
assert.ok(empty3.equals(empty));
const combined = empty.combinePaths(normalizeSlashes('/d/e/f'));
assert.equal(combined.getFilePath(), normalizeSlashes('/d/e/f'));
});

test('file', () => {
const file1 = Uri.file(normalizeSlashes('/a/b/c')).getFilePath();
assert.equal(file1, normalizeSlashes('/a/b/c'));
const file2 = Uri.file('file:///a/b/c').getFilePath();
assert.equal(file2, normalizeSlashes('/a/b/c'));
const resolved = Uri.file(normalizeSlashes('/a/b/c')).combinePaths(normalizeSlashes('/d/e/f'));
assert.equal(resolved.getFilePath(), normalizeSlashes('/d/e/f'));
});

test('isUri', () => {
Expand Down Expand Up @@ -390,7 +394,7 @@ test('combinePaths', () => {
const uri10 = uri9.combinePaths('d', 'e');
assert.equal(uri10.toString(), 'foo:///d/e');
const uri11 = Uri.empty().combinePaths('d', 'e');
assert.equal(uri11.toString(), Uri.empty().toString());
assert.equal(uri11.toString(), Uri.file(normalizeSlashes('/d/e')).toString());
});

test('combinePaths non file', () => {
Expand Down

0 comments on commit 81e85d1

Please sign in to comment.