mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
Use canonical uri for openTextDocument api, #93368
This commit is contained in:
@@ -48,9 +48,12 @@ class Directory implements vscode.FileStat {
|
||||
|
||||
export type Entry = File | Directory;
|
||||
|
||||
export class MemFS implements vscode.FileSystemProvider {
|
||||
export class TestFS implements vscode.FileSystemProvider {
|
||||
|
||||
readonly scheme = 'fake-fs';
|
||||
constructor(
|
||||
readonly scheme: string,
|
||||
readonly isCaseSensitive: boolean
|
||||
) { }
|
||||
|
||||
readonly root = new Directory('');
|
||||
|
||||
@@ -161,12 +164,22 @@ export class MemFS implements vscode.FileSystemProvider {
|
||||
let parts = uri.path.split('/');
|
||||
let entry: Entry = this.root;
|
||||
for (const part of parts) {
|
||||
const partLow = part.toLowerCase();
|
||||
if (!part) {
|
||||
continue;
|
||||
}
|
||||
let child: Entry | undefined;
|
||||
if (entry instanceof Directory) {
|
||||
child = entry.entries.get(part);
|
||||
if (this.isCaseSensitive) {
|
||||
child = entry.entries.get(part);
|
||||
} else {
|
||||
for (let [key, value] of entry.entries) {
|
||||
if (key.toLowerCase() === partLow) {
|
||||
child = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!child) {
|
||||
if (!silent) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
|
||||
import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, disposeAll, testFs, delay, withLogDisabled } from '../utils';
|
||||
import { join, posix, basename } from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { TestFS } from '../memfs';
|
||||
|
||||
suite('vscode API - workspace', () => {
|
||||
|
||||
@@ -163,6 +164,40 @@ suite('vscode API - workspace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('openTextDocument, actual casing first', async function () {
|
||||
|
||||
const fs = new TestFS('this-fs', false);
|
||||
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs, { isCaseSensitive: fs.isCaseSensitive });
|
||||
|
||||
let uriOne = vscode.Uri.parse('this-fs:/one');
|
||||
let uriTwo = vscode.Uri.parse('this-fs:/two');
|
||||
let uriONE = vscode.Uri.parse('this-fs:/ONE'); // same resource, different uri
|
||||
let uriTWO = vscode.Uri.parse('this-fs:/TWO');
|
||||
|
||||
fs.writeFile(uriOne, Buffer.from('one'), { create: true, overwrite: true });
|
||||
fs.writeFile(uriTwo, Buffer.from('two'), { create: true, overwrite: true });
|
||||
|
||||
// lower case (actual case) comes first
|
||||
let docOne = await vscode.workspace.openTextDocument(uriOne);
|
||||
assert.equal(docOne.uri.toString(), uriOne.toString());
|
||||
|
||||
let docONE = await vscode.workspace.openTextDocument(uriONE);
|
||||
assert.equal(docONE === docOne, true);
|
||||
assert.equal(docONE.uri.toString(), uriOne.toString());
|
||||
assert.equal(docONE.uri.toString() !== uriONE.toString(), true); // yep
|
||||
|
||||
// upper case (NOT the actual case) comes first
|
||||
let docTWO = await vscode.workspace.openTextDocument(uriTWO);
|
||||
assert.equal(docTWO.uri.toString(), uriTWO.toString());
|
||||
|
||||
let docTwo = await vscode.workspace.openTextDocument(uriTwo);
|
||||
assert.equal(docTWO === docTwo, true);
|
||||
assert.equal(docTwo.uri.toString(), uriTWO.toString());
|
||||
assert.equal(docTwo.uri.toString() !== uriTwo.toString(), true); // yep
|
||||
|
||||
reg.dispose();
|
||||
});
|
||||
|
||||
test('eol, read', () => {
|
||||
const a = createRandomFile('foo\nbar\nbar').then(file => {
|
||||
return vscode.workspace.openTextDocument(file).then(doc => {
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { MemFS } from './memfs';
|
||||
import { TestFS } from './memfs';
|
||||
import * as assert from 'assert';
|
||||
|
||||
export function rndName() {
|
||||
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
|
||||
}
|
||||
|
||||
export const testFs = new MemFS();
|
||||
vscode.workspace.registerFileSystemProvider(testFs.scheme, testFs);
|
||||
export const testFs = new TestFS('fake-fs', true);
|
||||
vscode.workspace.registerFileSystemProvider(testFs.scheme, testFs, { isCaseSensitive: testFs.isCaseSensitive });
|
||||
|
||||
export async function createRandomFile(contents = '', dir: vscode.Uri | undefined = undefined, ext = ''): Promise<vscode.Uri> {
|
||||
let fakeFile: vscode.Uri;
|
||||
|
||||
Reference in New Issue
Block a user