This commit is contained in:
Benjamin Pasero
2018-01-24 09:59:29 +01:00
parent 3dd2035b13
commit 2d01d1c4b1
3 changed files with 18 additions and 14 deletions
+6 -1
View File
@@ -38,8 +38,13 @@ export function isEqual(first: uri, second: uri, ignoreCase?: boolean): boolean
}
export function dirname(resource: uri): uri {
const dirname = paths.dirname(resource.path);
if (resource.authority && dirname && !paths.isAbsolute(dirname)) {
return null; // If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character
}
return resource.with({
path: paths.dirname(resource.path)
path: dirname
});
}
+11 -1
View File
@@ -6,7 +6,7 @@
import * as assert from 'assert';
import URI from 'vs/base/common/uri';
import { distinctParents } from 'vs/base/common/resources';
import { distinctParents, dirname } from 'vs/base/common/resources';
suite('Resources', () => {
@@ -40,4 +40,14 @@ suite('Resources', () => {
assert.equal(distinct[1].toString(), resources[3].toString());
assert.equal(distinct[2].toString(), resources[4].toString());
});
test('dirname', (done) => {
const f = URI.file('/some/file/test.txt');
const d = dirname(f);
assert.equal(d.fsPath, '/some/file');
// does not explode (https://github.com/Microsoft/vscode/issues/41987)
URI.from({ scheme: 'file', authority: '/users/someone/portal.h' });
done();
});
});
@@ -55,7 +55,6 @@ import { FileKind, IFileService } from 'vs/platform/files/common/files';
import { scoreItem, ScorerCache, compareItemsByScore, prepareQuery } from 'vs/base/parts/quickopen/common/quickOpenScorer';
import { getBaseLabel } from 'vs/base/common/labels';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
import { dirname } from 'vs/base/common/paths';
const HELP_PREFIX = '?';
@@ -1260,7 +1259,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
const resourceInput = input as IResourceInput;
this.resource = resourceInput.resource;
this.label = getBaseLabel(resourceInput.resource);
this.description = labels.getPathLabel(this.safeDirname(this.resource), contextService, environmentService);
this.description = labels.getPathLabel(resources.dirname(this.resource), contextService, environmentService);
this.dirty = this.resource && this.textFileService.isDirty(this.resource);
if (this.dirty && this.textFileService.getAutoSaveMode() === AutoSaveMode.AFTER_SHORT_DELAY) {
@@ -1269,16 +1268,6 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
}
}
private safeDirname(resource: URI): string | URI {
try {
return resources.dirname(resource); // workaround for https://github.com/Microsoft/vscode/issues/41987
} catch (error) {
console.warn(`Unable to resolve to parent resource: ${resource.toString()}`, resource, error);
return dirname(resource.fsPath);
}
}
public getIcon(): string {
return this.dirty ? 'dirty' : '';
}