Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WorkspaceEdit: applying edits before and after rename duplicates resource #42633

Closed
aeschli opened this issue Jan 31, 2018 · 2 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded workspace-edit
Milestone

Comments

@aeschli
Copy link
Contributor

aeschli commented Jan 31, 2018

Testing #42334

Run the extension below.

  • it does some edits to the document in the current editor
  • renames the document (adds a _ to the name)
  • it does some edits to the renamed document

You end up with 2 files.
image

'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import * as path from 'path';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
        let editor = vscode.window.activeTextEditor;
        if (editor) {
            let doc = editor.document;
            let docUri = doc.uri;
            let newUri = nameWithUnderscore(docUri);

            let we = new vscode.WorkspaceEdit();
            we.insert(docUri, new vscode.Position(0, 0), 'Hello');
            we.insert(docUri, new vscode.Position(0, 0), 'Foo');
            we.renameResource(docUri, newUri);
            we.insert(newUri, new vscode.Position(0, 0), 'Bar');

            console.log(JSON.stringify(we.allEntries(), null, '\t'));
            

            vscode.workspace.applyEdit(we);
        }
    });

    context.subscriptions.push(disposable);
}

function nameWithUnderscore(uri: vscode.Uri) {
    let uriPath = uri.fsPath;
    return vscode.Uri.file(path.join(path.dirname(uriPath), '_' + path.basename(uriPath)));
}
@jrieken jrieken added the bug Issue identified by VS Code Team member as probable bug label Jan 31, 2018
@jrieken jrieken added this to the January 2018 milestone Jan 31, 2018
@aeschli
Copy link
Contributor Author

aeschli commented Jan 31, 2018

The edit on the renamed doc is not necessary to reproduce the issue . All that's needed it a edit and a rename:

'use strict';
import * as vscode from 'vscode';
import * as path from 'path';

export function activate(context: vscode.ExtensionContext) {
    let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
        let editor = vscode.window.activeTextEditor;
        if (editor) {
            let doc = editor.document;
            let docUri = doc.uri;
            let newUri = nameWithUnderscore(docUri);

            let we = new vscode.WorkspaceEdit();
            we.insert(docUri, new vscode.Position(0, 0), 'Hello');
            we.renameResource(docUri, newUri);

            console.log(JSON.stringify(we.allEntries(), null, '\t'));    

            vscode.workspace.applyEdit(we);
        }
    });

    context.subscriptions.push(disposable);
}

function nameWithUnderscore(uri: vscode.Uri) {
    let uriPath = uri.fsPath;
    return vscode.Uri.file(path.join(path.dirname(uriPath), '_' + path.basename(uriPath)));
}

@aeschli aeschli changed the title Workspace: applying edits before and after rename duplicates resource WorkspaceEdit: applying edits before and after rename duplicates resource Jan 31, 2018
@jrieken
Copy link
Member

jrieken commented Jan 31, 2018

Similar as before... I see the tab as 'deleted from disk'

screen shot 2018-01-31 at 16 38 29

@jrieken jrieken modified the milestones: January 2018, February 2018 Feb 1, 2018
@jrieken jrieken modified the milestones: February 2018, March 2018 Feb 27, 2018
@jrieken jrieken removed this from the March 2018 milestone Mar 8, 2018
@jrieken jrieken added this to the June 2018 milestone Jun 19, 2018
@jrieken jrieken closed this as completed Jun 19, 2018
@aeschli aeschli added the verified Verification succeeded label Jun 28, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded workspace-edit
Projects
None yet
Development

No branches or pull requests

2 participants