@@ -31,7 +31,11 @@ export function registerCommands(
3131 // so we don't accidentally pass them directly into vscode APIs.
3232 context . subscriptions . push ( vscode . commands . registerCommand ( 'roslyn.client.peekReferences' , peekReferencesCallback ) ) ;
3333 context . subscriptions . push (
34- vscode . commands . registerCommand ( 'roslyn.client.completionComplexEdit' , completionComplexEdit )
34+ vscode . commands . registerCommand (
35+ 'roslyn.client.completionComplexEdit' ,
36+ async ( uriStr , textEdit , isSnippetString , newOffset ) =>
37+ completionComplexEdit ( uriStr , textEdit , isSnippetString , newOffset , outputChannel )
38+ )
3539 ) ;
3640 context . subscriptions . push (
3741 vscode . commands . registerCommand ( 'dotnet.restartServer' , async ( ) => restartServer ( languageServer ) )
@@ -99,11 +103,14 @@ async function completionComplexEdit(
99103 uriStr : string ,
100104 textEdit : vscode . TextEdit ,
101105 isSnippetString : boolean ,
102- newOffset : number
106+ newOffset : number ,
107+ outputChannel : vscode . OutputChannel
103108) : Promise < void > {
104109 let success = false ;
105110 const uri = UriConverter . deserialize ( uriStr ) ;
106- const editor = vscode . window . visibleTextEditors . find ( ( editor ) => editor . document . uri . fsPath === uri . fsPath ) ;
111+ const editor = vscode . window . visibleTextEditors . find (
112+ ( editor ) => editor . document . uri . path === uri . path || editor . document . uri . fsPath === uri . fsPath
113+ ) ;
107114
108115 if ( editor !== undefined ) {
109116 const newRange = editor . document . validateRange (
@@ -142,6 +149,27 @@ async function completionComplexEdit(
142149 }
143150
144151 if ( ! success ) {
152+ const componentName = '[roslyn.client.completionComplexEdit]' ;
153+
154+ if ( editor === undefined ) {
155+ outputChannel . show ( ) ;
156+ outputChannel . appendLine ( `${ componentName } Failed to make a complex text edit for completion.` ) ;
157+ outputChannel . appendLine (
158+ `${ componentName } Can't find visible document with uri.fsPath: '${ uri . fsPath } ' and uri.path: '${ uri . path } '`
159+ ) ;
160+
161+ outputChannel . appendLine ( `${ componentName } URIs of all visible documents:` ) ;
162+ for ( const visibleEditor of vscode . window . visibleTextEditors ) {
163+ outputChannel . appendLine (
164+ `${ componentName } - uri.fsPath: '${ visibleEditor . document . uri . fsPath } ' and uri.path: '${ visibleEditor . document . uri . path } '`
165+ ) ;
166+ }
167+ } else {
168+ outputChannel . appendLine (
169+ `${ componentName } ${ isSnippetString ? 'TextEditor.insertSnippet' : 'workspace.applyEdit' } failed.`
170+ ) ;
171+ }
172+
145173 throw new Error ( 'Failed to make a complex text edit for completion.' ) ;
146174 }
147175}
0 commit comments