Skip to content

Commit 03b58ea

Browse files
authored
Merge pull request #6325 from genlu/LogUriError
Make complexEdit command more robust
2 parents d23fda4 + 0954d5f commit 03b58ea

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

src/lsptoolshost/commands.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +149,29 @@ async function completionComplexEdit(
142149
}
143150

144151
if (!success) {
145-
throw new Error('Failed to make a complex text edit for completion.');
152+
const componentName = '[roslyn.client.completionComplexEdit]';
153+
const errorMessage = 'Failed to make a complex text edit for completion.';
154+
outputChannel.show();
155+
outputChannel.appendLine(`${componentName} ${errorMessage}`);
156+
157+
if (editor === undefined) {
158+
outputChannel.appendLine(
159+
`${componentName} Can't find visible document with uri.fsPath: '${uri.fsPath}' and uri.path: '${uri.path}'`
160+
);
161+
162+
outputChannel.appendLine(`${componentName} URIs of all visible documents:`);
163+
for (const visibleEditor of vscode.window.visibleTextEditors) {
164+
outputChannel.appendLine(
165+
`${componentName} - uri.fsPath: '${visibleEditor.document.uri.fsPath}' and uri.path: '${visibleEditor.document.uri.path}'`
166+
);
167+
}
168+
} else {
169+
outputChannel.appendLine(
170+
`${componentName} ${isSnippetString ? 'TextEditor.insertSnippet' : 'workspace.applyEdit'} failed.`
171+
);
172+
}
173+
174+
throw new Error(`${componentName} ${errorMessage}`);
146175
}
147176
}
148177

0 commit comments

Comments
 (0)