简体   繁体   中英

Create distictive hovers per word for VSCode extension API?

I have a text in VSCode like so;

"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

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.

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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