英文:
Is it possible to develop a file label extension for EXPLORER?
问题
我想为 VSCode 的 EXPLORER 开发一个扩展,用于为文件/目录设置标签(或标记),以便我可以区分它们。
但我在 VSCode 文档中搜索时,并没有找到介绍这个实现的地方。是否可能实现这个功能?
英文:
I want to develop a VSCode Extension for EXPLORER to set label (or tag) for files/directories, so that I can distinguish out them.
but I searched the Document of VSCode Docs, didn't find a place to introduce this implementation. Is it possible to do it?
答案1
得分: 0
你应该查找FileDecoration API。
它允许你为文件和文件夹定义badge
、color
和tooltip
。
根据你的模拟,我猜这个API应该可以正常工作。除非你需要为badge
属性使用超过2个字符,但这是不可能的,至少目前是这样的。
更新/示例
这是一个小示例。它会在每个文件/文件夹的右侧添加一个笑脸表情(因为我忽略了Uri
),并将文件/文件夹着色为problemsWarningIcon.foreground
。
我认为可能对你来说API的_color_可能并不完全符合你的需求,因为它会应用于文件/文件夹本身,而不仅仅是badge
。如果这不符合你的需求,你需要在VS Code存储库中提出一个功能请求来进行更改。
class EmojiFileDecorationProvider implements vscode.FileDecorationProvider{
onDidChangeFileDecorations?: vscode.Event<vscode.Uri | vscode.Uri[] | undefined> | undefined;
provideFileDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<vscode.FileDecoration> {
return new vscode.FileDecoration("😀", "tooltip smile", new vscode.ThemeColor("problemsWarningIcon.foreground"));
}
}
export function activate(context: vscode.ExtensionContext) {
...
vscode.window.registerFileDecorationProvider(new EmojiFileDecorationProvider());
}
希望对你有所帮助。
英文:
You should look for the FileDecoration API.
It allows you to define badge
, color
and tooltip
for files and folders.
Based on your mockup, I guess this API would work just fine. Unless you need to have more than 2 characters for the badge
attribute, which is not possible, today.
Update / Sample
Here is a small sample. It will add a smile emoji at the right side of every file/folder (because I'm ignoring Uri
) and make the file/folder to be colored as problemsWarningIcon.foreground
.
The color is where I think the API maybe doesn't work perfect for you, because it will be applied to the file/folder too, not only the badge
. If this doesn't fit your needs, you need to open a feature request in VS Code repo asking for changes
class EmojiFileDecorationProvider implements vscode.FileDecorationProvider{
onDidChangeFileDecorations?: vscode.Event<vscode.Uri | vscode.Uri[] | undefined> | undefined;
provideFileDecoration(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<vscode.FileDecoration> {
return new vscode.FileDecoration("😀", "tooltip smile", new vscode.ThemeColor("problemsWarningIcon.foreground"));
}
}
export function activate(context: vscode.ExtensionContext) {
...
vscode.window.registerFileDecorationProvider(new EmojiFileDecorationProvider());
}
Hope this helps
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论