首页 > 解决方案 > 如何注入/跟踪编辑器/文档元数据?

问题描述

有没有办法将自定义属性注入文档/编辑器?

例如,我需要从 api 端点编辑文本。调用 api 并在编辑器中显示数据,然后编辑文本很容易。我似乎找不到放置有关​​文本的元数据的好方法,因此可以发布帖子来更新源。需要保存 api-end-point 和文档 ID 等信息,而不将其注入主编辑器文本。

我一直在研究从自定义文档/提供程序到自定义文件系统提供程序的所有内容,但这些选项对于我的需要似乎相当复杂。

Example:
api-endpoint: GET /docs

const resp = [{
  name: /docs/note1.txt,
  id: 12345,
  content: 'some text document content'
}, {
  name: /notes/othernote.txt
  id: 54312,
  content: 'special text in another note'
}];

// open a document/editor and display the content of one of the docs from the api reponse
await workspace.openTextDocument({ content: resp[0].content, language: 'text' })
        .then( async (doc) => {
            await window.showTextDocument( doc, { preview: false });
            this.documents.push(doc);
        });

现在我们有一个显示内容的编辑器,但无法将该内容链接回 api 端点(带有 doc id)。看来我需要查看文件系统提供程序,以便我可以在文件统计信息中注入更多详细信息。

https://code.visualstudio.com/api/references/vscode-api#FileSystemProvider

建议?

标签: visual-studio-codevscode-extensions

解决方案


推荐阅读