Change title of untitled tab in Visual Studio Code

2019-06-23 23:27发布

问题:

I'm building a VS Code extension which includes changing the name/title of untitled-1 tab (unsaved file).
I tried running the below code in debugger console of extension but it didn't reflect in the editor:

vscode.workspace.textDocuments[0].fileName="myFile"

Is it not possible or am I missing something?

回答1:

It's not possible - if you check out the source code for the API definition in vscode.d.ts, you'll see that fileName is declared as readonly:

export interface TextDocument {
    // ...
    readonly fileName: string;
    // ...
}

Unfortunately, it seems that the readonly attribute isn't reflected in the API docs on the website.