Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"onCommand:r.goToPreviousChunk",
"onCommand:r.goToNextChunk",
"onCommand:r.createGitignore",
"onCommand:r.createLintrConfig",
"onCommand:r.runCommandWithSelectionOrWord",
"onCommand:r.runCommandWithEditorPath",
"onCommand:r.runCommand",
Expand Down Expand Up @@ -424,6 +425,11 @@
"category": "R",
"command": "r.createGitignore"
},
{
"title": "Create .lintr to the workspace",
"category": "R",
"command": "r.createLintrConfig"
},
{
"title": "Preview Dataframe",
"category": "R",
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import path = require('path');
// functions etc. implemented in this extension
import * as preview from './preview';
import * as rGitignore from './rGitignore';
import * as lintrConfig from './lintrConfig';
import * as rTerminal from './rTerminal';
import * as session from './session';
import * as util from './util';
Expand Down Expand Up @@ -107,6 +108,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp

// editor independent commands
'r.createGitignore': rGitignore.createGitignore,
'r.createLintrConfig': lintrConfig.createLintrConfig,
'r.loadAll': () => rTerminal.runTextInTerm('devtools::load_all()'),

// environment independent commands. this is a workaround for using the Tasks API: https://github.com/microsoft/vscode/issues/40758
Expand Down
29 changes: 29 additions & 0 deletions src/lintrConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

import { existsSync, unlinkSync } from 'fs';
import { join } from 'path';
import { window } from 'vscode';
import { executeRCommand, getCurrentWorkspaceFolder } from './util';

export async function createLintrConfig(): Promise<string> {
const currentWorkspaceFolder = getCurrentWorkspaceFolder()?.uri.fsPath;
if (currentWorkspaceFolder === undefined) {
void window.showWarningMessage('Please open a workspace folder to create .lintr');
return;
}
const lintrFilePath = join(currentWorkspaceFolder, '.lintr');
if (existsSync(lintrFilePath)) {
const overwrite = await window.showWarningMessage(
'".lintr" file already exists. Do you want to overwrite?',
'Yes', 'No'
);
if (overwrite === 'No') {
return;
}
void unlinkSync(lintrFilePath);
}
return await executeRCommand(`lintr::use_lintr()`, currentWorkspaceFolder, (e: Error) => {
void window.showErrorMessage(e.message);
return '';
});
}