Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { isNull } from "util";
import { commands, ExtensionContext, languages, Terminal, window, IndentAction } from "vscode";
import { commands, ExtensionContext, languages, Terminal, window, IndentAction, Position, TextDocument, CompletionItem } from "vscode";
import { buildPkg, documentPkg, installPkg, loadAllPkg, testPkg } from "./package";
import { previewDataframe, previewEnvironment } from "./preview";
import { createGitignore } from "./rGitignore";
Expand All @@ -12,6 +12,18 @@ import { config, delay } from "./util";

const wordPattern = /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\<\>\/\s]+)/g;

// Get with names(roxygen2:::default_tags())
const roxygenTagCompletionItems = [
"export", "exportClass", "exportMethod", "exportPattern", "import", "importClassesFrom",
"importFrom", "importMethodsFrom", "rawNamespace", "S3method", "useDynLib", "aliases",
"author", "backref", "concept", "describeIn", "description", "details",
"docType", "encoding", "evalRd", "example", "examples", "family",
"field", "format", "inherit", "inheritParams", "inheritDotParams", "inheritSection",
"keywords", "method", "name", "md", "noMd", "noRd",
"note", "param", "rdname", "rawRd", "references", "return",
"section", "seealso", "slot", "source", "template", "templateVar",
"title", "usage"].map((x) => new CompletionItem(x + " "));

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: ExtensionContext) {
Expand Down Expand Up @@ -149,6 +161,16 @@ export function activate(context: ExtensionContext) {
term.show(focus !== "terminal");
}

languages.registerCompletionItemProvider("r", {
provideCompletionItems(document: TextDocument, position: Position) {
if (document.lineAt(position).text.substr(0, 2) === "#'") {
return roxygenTagCompletionItems;
} else {
return undefined;
};
}
}, '@'); // Trigger on '@'

languages.setLanguageConfiguration("r", {
wordPattern,
onEnterRules: [{ // Automatically continue roxygen comments: #'
Expand Down