@@ -16,8 +16,9 @@ import { ExtHostContext, ExtHostDocumentsShape, IExtHostContext, MainThreadDocum
1616import { ITextEditorModel } from 'vs/workbench/common/editor' ;
1717import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
1818import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
19- import { toLocalResource , isEqualOrParent } from 'vs/base/common/resources' ;
19+ import { toLocalResource , isEqualOrParent , extUri } from 'vs/base/common/resources' ;
2020import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService' ;
21+ import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity' ;
2122
2223export class BoundModelReferenceCollection {
2324
@@ -78,6 +79,7 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
7879 private readonly _textFileService : ITextFileService ;
7980 private readonly _fileService : IFileService ;
8081 private readonly _environmentService : IWorkbenchEnvironmentService ;
82+ private readonly _uriIdentityService : IUriIdentityService ;
8183
8284 private readonly _toDispose = new DisposableStore ( ) ;
8385 private _modelToDisposeMap : { [ modelUrl : string ] : IDisposable ; } ;
@@ -93,13 +95,15 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
9395 @IFileService fileService : IFileService ,
9496 @ITextModelService textModelResolverService : ITextModelService ,
9597 @IWorkbenchEnvironmentService environmentService : IWorkbenchEnvironmentService ,
98+ @IUriIdentityService uriIdentityService : IUriIdentityService ,
9699 @IWorkingCopyFileService workingCopyFileService : IWorkingCopyFileService
97100 ) {
98101 this . _modelService = modelService ;
99102 this . _textModelResolverService = textModelResolverService ;
100103 this . _textFileService = textFileService ;
101104 this . _fileService = fileService ;
102105 this . _environmentService = environmentService ;
106+ this . _uriIdentityService = uriIdentityService ;
103107
104108 this . _proxy = extHostContext . getProxy ( ExtHostContext . ExtHostDocuments ) ;
105109
@@ -179,55 +183,58 @@ export class MainThreadDocuments implements MainThreadDocumentsShape {
179183 return this . _textFileService . save ( URI . revive ( uri ) ) . then ( target => ! ! target ) ;
180184 }
181185
182- $tryOpenDocument ( _uri : UriComponents ) : Promise < any > {
183- const uri = URI . revive ( _uri ) ;
184- if ( ! uri . scheme || ! ( uri . fsPath || uri . authority ) ) {
186+ $tryOpenDocument ( uriData : UriComponents ) : Promise < URI > {
187+ const inputUri = URI . revive ( uriData ) ;
188+ if ( ! inputUri . scheme || ! ( inputUri . fsPath || inputUri . authority ) ) {
185189 return Promise . reject ( new Error ( `Invalid uri. Scheme and authority or path must be set.` ) ) ;
186190 }
187191
188- let promise : Promise < boolean > ;
189- switch ( uri . scheme ) {
192+ const canonicalUri = this . _uriIdentityService . asCanonicalUri ( inputUri ) ;
193+
194+ let promise : Promise < URI > ;
195+ switch ( canonicalUri . scheme ) {
190196 case Schemas . untitled :
191- promise = this . _handleUntitledScheme ( uri ) ;
197+ promise = this . _handleUntitledScheme ( canonicalUri ) ;
192198 break ;
193199 case Schemas . file :
194200 default :
195- promise = this . _handleAsResourceInput ( uri ) ;
201+ promise = this . _handleAsResourceInput ( canonicalUri ) ;
196202 break ;
197203 }
198204
199- return promise . then ( success => {
200- if ( ! success ) {
201- return Promise . reject ( new Error ( 'cannot open ' + uri . toString ( ) ) ) ;
202- } else if ( ! this . _modelIsSynced . has ( uri . toString ( ) ) ) {
203- return Promise . reject ( new Error ( 'cannot open ' + uri . toString ( ) + '. Detail: Files above 50MB cannot be synchronized with extensions.' ) ) ;
205+ return promise . then ( documentUri => {
206+ if ( ! documentUri ) {
207+ return Promise . reject ( new Error ( `cannot open ${ canonicalUri . toString ( ) } ` ) ) ;
208+ } else if ( ! extUri . isEqual ( documentUri , canonicalUri ) ) {
209+ return Promise . reject ( new Error ( `cannot open ${ canonicalUri . toString ( ) } . Detail: Actual document opened as ${ documentUri . toString ( ) } ` ) ) ;
210+ } else if ( ! this . _modelIsSynced . has ( canonicalUri . toString ( ) ) ) {
211+ return Promise . reject ( new Error ( `cannot open ${ canonicalUri . toString ( ) } . Detail: Files above 50MB cannot be synchronized with extensions.` ) ) ;
204212 } else {
205- return undefined ;
213+ return canonicalUri ;
206214 }
207215 } , err => {
208- return Promise . reject ( new Error ( ' cannot open ' + uri . toString ( ) + ' . Detail: ' + toErrorMessage ( err ) ) ) ;
216+ return Promise . reject ( new Error ( ` cannot open ${ canonicalUri . toString ( ) } . Detail: ${ toErrorMessage ( err ) } ` ) ) ;
209217 } ) ;
210218 }
211219
212220 $tryCreateDocument ( options ?: { language ?: string , content ?: string } ) : Promise < URI > {
213221 return this . _doCreateUntitled ( undefined , options ? options . language : undefined , options ? options . content : undefined ) ;
214222 }
215223
216- private _handleAsResourceInput ( uri : URI ) : Promise < boolean > {
224+ private _handleAsResourceInput ( uri : URI ) : Promise < URI > {
217225 return this . _textModelResolverService . createModelReference ( uri ) . then ( ref => {
218226 this . _modelReferenceCollection . add ( uri , ref ) ;
219- const result = ! ! ref . object ;
220- return result ;
227+ return ref . object . textEditorModel . uri ;
221228 } ) ;
222229 }
223230
224- private _handleUntitledScheme ( uri : URI ) : Promise < boolean > {
231+ private _handleUntitledScheme ( uri : URI ) : Promise < URI > {
225232 const asLocalUri = toLocalResource ( uri , this . _environmentService . configuration . remoteAuthority ) ;
226233 return this . _fileService . resolve ( asLocalUri ) . then ( stats => {
227234 // don't create a new file ontop of an existing file
228235 return Promise . reject ( new Error ( 'file already exists' ) ) ;
229236 } , err => {
230- return this . _doCreateUntitled ( Boolean ( uri . path ) ? uri : undefined ) . then ( resource => ! ! resource ) ;
237+ return this . _doCreateUntitled ( Boolean ( uri . path ) ? uri : undefined ) ;
231238 } ) ;
232239 }
233240
0 commit comments