问题
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.
来源:https://stackoverflow.com/questions/45876887/change-title-of-untitled-tab-in-visual-studio-code