MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / provideHover

Method provideHover

src/completions.ts:81–109  ·  view source on GitHub ↗
(document: vscode.TextDocument, position: vscode.Position)

Source from the content-addressed store, hash-verified

79
80export class HelpLinkHoverProvider implements vscode.HoverProvider {
81 async provideHover(document: vscode.TextDocument, position: vscode.Position): Promise<vscode.Hover | null> {
82 if(!config().get<boolean>('helpPanel.enableHoverLinks')){
83 return null;
84 }
85
86 if (document.languageId === 'rmd') {
87 const chunks = getChunks(document);
88 const chunk = chunks.find((chunk) => chunk.language === 'r' && chunk.startLine < position.line && chunk.endLine > position.line);
89 if (!chunk) {
90 return null;
91 }
92 }
93
94 const re = /([a-zA-Z0-9._:])+/;
95 const wordRange = document.getWordRangeAtPosition(position, re);
96 const token = document.getText(wordRange);
97 const aliases = await globalRHelp?.getMatchingAliases(token) || [];
98 const mds = aliases.map(a => {
99 const cmdText = `${a.package}::${a.alias}`;
100 const args = [`/library/${a.package}/html/${a.name}.html`];
101 const encodedArgs = encodeURIComponent(JSON.stringify(args));
102 const cmd = 'command:r.helpPanel.openForPath';
103 const cmdUri = vscode.Uri.parse(`${cmd}?${encodedArgs}`);
104 return `[\`${cmdText}\`](${cmdUri})`;
105 });
106 const md = new vscode.MarkdownString(mds.join(' \n'));
107 md.isTrusted = true;
108 return new vscode.Hover(md, wordRange);
109 }
110}
111
112

Callers

nothing calls this directly

Calls 3

configFunction · 0.90
getChunksFunction · 0.90
getMatchingAliasesMethod · 0.80

Tested by

no test coverage detected