forked from dotnet/vscode-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The code action provider and rename provider were expecting the server to apply the file changes, which then messes up incremental buffer changes. This sends for false for these parameters, and refactors the handling of code action responses to do the renames locally. As part of that, I also refactored the protocol to accurately reflect O#'s hierarchy, and share the edit building between the fixAllProvider and the runCodeAction provider. Fixes dotnet#4128.
- Loading branch information
Showing
5 changed files
with
94 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { Uri } from 'vscode'; | ||
import { LanguageMiddlewareFeature } from './LanguageMiddlewareFeature'; | ||
import { FileModificationType, FileOperationResponse, ModifiedFileResponse, RenamedFileResponse } from "./protocol"; | ||
import { toRange2 } from './typeConversion'; | ||
|
||
export async function buildEditForResponse(changes: FileOperationResponse[], languageMiddlewareFeature: LanguageMiddlewareFeature, token: vscode.CancellationToken): Promise<boolean> { | ||
let edit = new vscode.WorkspaceEdit(); | ||
|
||
let fileToOpen: Uri = null; | ||
|
||
if (!changes || !Array.isArray(changes) || !changes.length) { | ||
return true; | ||
} | ||
|
||
for (const change of changes) { | ||
if (change.ModificationType == FileModificationType.Opened) { | ||
// The CodeAction requested that we open a file. | ||
// Record that file name and keep processing CodeActions. | ||
// If a CodeAction requests that we open multiple files | ||
// we only open the last one (what would it mean to open multiple files?) | ||
fileToOpen = vscode.Uri.file(change.FileName); | ||
} | ||
|
||
if (change.ModificationType == FileModificationType.Modified) { | ||
const modifiedChange = <ModifiedFileResponse>change; | ||
const uri = vscode.Uri.file(modifiedChange.FileName); | ||
let edits: vscode.TextEdit[] = []; | ||
for (let textChange of modifiedChange.Changes) { | ||
edits.push(vscode.TextEdit.replace(toRange2(textChange), textChange.NewText)); | ||
} | ||
|
||
edit.set(uri, edits); | ||
} | ||
} | ||
|
||
for (const change of changes) { | ||
if (change.ModificationType == FileModificationType.Renamed) { | ||
const renamedChange = <RenamedFileResponse>change; | ||
edit.renameFile(vscode.Uri.file(renamedChange.FileName), vscode.Uri.file(renamedChange.NewFileName)); | ||
} | ||
} | ||
|
||
// Allow language middlewares to re-map its edits if necessary. | ||
edit = await languageMiddlewareFeature.remap("remapWorkspaceEdit", edit, token); | ||
|
||
const applyEditPromise = vscode.workspace.applyEdit(edit); | ||
|
||
// Unfortunately, the textEditor.Close() API has been deprecated | ||
// and replaced with a command that can only close the active editor. | ||
// If files were renamed that weren't the active editor, their tabs will | ||
// be left open and marked as "deleted" by VS Code | ||
return fileToOpen != null | ||
? applyEditPromise.then(_ => { | ||
return vscode.commands.executeCommand("vscode.open", fileToOpen); | ||
}) | ||
: applyEditPromise; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters