简体   繁体   English

为VSCode扩展API创建每个单词的distictive hovers?

[英]Create distictive hovers per word for VSCode extension API?

I have a text in VSCode like so; 我在VSCode中有一个文本就像这样;

"The quick brown fox jumps over the lazy dog"

I am working on an extension & want to be able to hover over each word using regex (or anything really) & see distinctive further information about a word in the sentence. 我正在进行扩展并希望能够使用正则表达式(或任何真正的东西)将鼠标悬停在每个单词上,并查看有关单词中单词的独特信息。

How do I add parameters that enable this? 如何添加启用此功能的参数?

The snippet (pasted below) offed by VS code works but it provides the same hover information "Hover information for word" for every word in the sentence 由VS代码关闭的片段(粘贴在下面)可以工作,但它为句子中的每个单词提供相同的悬停信息“单词悬停信息”

vscode.languages.registerHoverProvider('plaintext', {
  provideHover(document, position, token) {
    return {
      contents: ['Hover information for word']
    };
  }
});

What I want is for every word in the sentance to have its unique Hover information. 我想要的是,在sentance中的每个单词都有其独特的悬停信息。

For Instance, hovering my cursor over "fox" may show "wild animal" & hovering over "dog" will show "domestic animal" 对于实例,将光标悬停在“狐狸”上可能会显示“野生动物”并在“狗”上方盘旋会显示“家畜”

const wordRange = document.getWordRangeAtPosition(position);
const word = document.getText(wordRange);
const map = {
    fox: 'wild',
    dog: 'domestic',
};
return new vscode.Hover(map[word]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM