提交 13b11919 编写于 作者: J Johannes Rieken

use correct uri manipulation, #25539

上级 4679fef0
...@@ -85,6 +85,13 @@ suite('workspace-namespace', () => { ...@@ -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 () { test('openTextDocument, untitled without path', function () {
return workspace.openTextDocument().then(doc => { return workspace.openTextDocument().then(doc => {
assert.equal(doc.uri.scheme, 'untitled'); assert.equal(doc.uri.scheme, 'untitled');
......
...@@ -227,7 +227,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape { ...@@ -227,7 +227,7 @@ export class MainThreadDocuments extends MainThreadDocumentsShape {
} }
private _handleUnititledScheme(uri: URI): TPromise<boolean> { 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 => { return this._fileService.resolveFile(asFileUri).then(stats => {
// don't create a new file ontop of an existing file // don't create a new file ontop of an existing file
return TPromise.wrapError<boolean>('file already exists on disk'); return TPromise.wrapError<boolean>('file already exists on disk');
......
...@@ -161,7 +161,7 @@ export class UntitledEditorService implements IUntitledEditorService { ...@@ -161,7 +161,7 @@ export class UntitledEditorService implements IUntitledEditorService {
let hasAssociatedFilePath = false; let hasAssociatedFilePath = false;
if (resource) { if (resource) {
hasAssociatedFilePath = (resource.scheme === 'file'); 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) { if (hasAssociatedFilePath) {
UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.set(resource, true); // remember for future lookups UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.set(resource, true); // remember for future lookups
...@@ -231,14 +231,6 @@ export class UntitledEditorService implements IUntitledEditorService { ...@@ -231,14 +231,6 @@ export class UntitledEditorService implements IUntitledEditorService {
return input; 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 { public hasAssociatedFilePath(resource: URI): boolean {
return UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.has(resource); return UntitledEditorService.KNOWN_ASSOCIATED_FILE_PATHS.has(resource);
} }
...@@ -249,4 +241,4 @@ export class UntitledEditorService implements IUntitledEditorService { ...@@ -249,4 +241,4 @@ export class UntitledEditorService implements IUntitledEditorService {
this._onDidChangeEncoding.dispose(); this._onDidChangeEncoding.dispose();
this._onDidDisposeModel.dispose(); this._onDidDisposeModel.dispose();
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册