use correct uri manipulation, #25539

This commit is contained in:
Johannes Rieken
2017-04-27 14:16:59 +02:00
parent 4679fef06e
commit 13b11919c6
3 changed files with 10 additions and 11 deletions
@@ -85,6 +85,13 @@ suite('workspace-namespace', () => {
});
});
test('openTextDocument, untitled with host', function () {
const uri = Uri.parse('untitled://localhost/c%24/Users/jrieken/code/samples/foobar.txt');
return workspace.openTextDocument(uri).then(doc => {
assert.equal(doc.uri.scheme, 'untitled');
});
});
test('openTextDocument, untitled without path', function () {
return workspace.openTextDocument().then(doc => {
assert.equal(doc.uri.scheme, 'untitled');
@@ -227,7 +227,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
}
private _handleUnititledScheme(uri: URI): TPromise<boolean> {
let asFileUri = URI.file(uri.fsPath);
let asFileUri = uri.with({ scheme: 'file' });
return this._fileService.resolveFile(asFileUri).then(stats => {
// don't create a new file ontop of an existing file
return TPromise.wrapError<boolean>('file already exists on disk');
@@ -161,7 +161,7 @@ export class UntitledEditorService implements IUntitledEditorService {
let hasAssociatedFilePath = false;
if (resource) {
hasAssociatedFilePath = (resource.scheme === 'file');
resource = this.resourceToUntitled(resource); // ensure we have the right scheme
resource = resource.with({ scheme: UntitledEditorInput.SCHEMA }); // ensure we have the right scheme
if (hasAssociatedFilePath) {
UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.set(resource, true); // remember for future lookups
@@ -231,14 +231,6 @@ export class UntitledEditorService implements IUntitledEditorService {
return input;
}
private resourceToUntitled(resource: URI): URI {
if (resource.scheme === UntitledEditorInput.SCHEMA) {
return resource;
}
return URI.from({ scheme: UntitledEditorInput.SCHEMA, path: resource.fsPath });
}
public hasAssociatedFilePath(resource: URI): boolean {
return UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.has(resource);
}
@@ -249,4 +241,4 @@ export class UntitledEditorService implements IUntitledEditorService {
this._onDidChangeEncoding.dispose();
this._onDidDisposeModel.dispose();
}
}
}