From 68561d68cad2c5254300b8b20de605d4d596d1db Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Tue, 14 Sep 2021 00:22:58 +0800 Subject: [PATCH] Extend providers to rmd --- src/completions.ts | 35 +++++++++++++++++++++++++++++++++++ src/extension.ts | 8 ++++---- src/rmarkdown/index.ts | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/completions.ts b/src/completions.ts index 34e92f2b4..f45d75607 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -12,6 +12,7 @@ import { extendSelection } from './selection'; import { cleanLine } from './lineCache'; import { globalRHelp } from './extension'; import { config } from './util'; +import { getChunks } from './rmarkdown'; // Get with names(roxygen2:::default_tags()) @@ -33,6 +34,15 @@ export class HoverProvider implements vscode.HoverProvider { if(!session.globalenv){ return null; } + + if (document.languageId === 'rmd') { + const chunks = getChunks(document); + const chunk = chunks.find((chunk) => chunk.language === 'r' && chunk.startLine < position.line && chunk.endLine > position.line); + if (!chunk) { + return null; + } + } + const wordRange = document.getWordRangeAtPosition(position); const text = document.getText(wordRange); // use juggling check here for both @@ -50,6 +60,15 @@ export class HelpLinkHoverProvider implements vscode.HoverProvider { if(!config().get('helpPanel.enableHoverLinks')){ return null; } + + if (document.languageId === 'rmd') { + const chunks = getChunks(document); + const chunk = chunks.find((chunk) => chunk.language === 'r' && chunk.startLine < position.line && chunk.endLine > position.line); + if (!chunk) { + return null; + } + } + const re = /([a-zA-Z0-9._:])+/; const wordRange = document.getWordRangeAtPosition(position, re); const token = document.getText(wordRange); @@ -71,6 +90,14 @@ export class HelpLinkHoverProvider implements vscode.HoverProvider { export class StaticCompletionItemProvider implements vscode.CompletionItemProvider { provideCompletionItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] | undefined { + if (document.languageId === 'rmd') { + const chunks = getChunks(document); + const chunk = chunks.find((chunk) => chunk.language === 'r' && chunk.startLine < position.line && chunk.endLine > position.line); + if (!chunk) { + return undefined; + } + } + if (document.lineAt(position).text .substr(0, 2) === '#\'') { return roxygenTagCompletionItems; @@ -93,6 +120,14 @@ export class LiveCompletionItemProvider implements vscode.CompletionItemProvider return items; } + if (document.languageId === 'rmd') { + const chunks = getChunks(document); + const chunk = chunks.find((chunk) => chunk.language === 'r' && chunk.startLine < position.line && chunk.endLine > position.line); + if (!chunk) { + return items; + } + } + const trigger = completionContext.triggerCharacter; if (trigger === undefined) { diff --git a/src/extension.ts b/src/extension.ts index 4656413ee..fc1d64efc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -175,9 +175,9 @@ export async function activate(context: vscode.ExtensionContext): Promise