Skip to content

Commit 1f692eb

Browse files
eitsupiElianHugh
andauthored
Add Create .linr command (#1112)
* add create .lintr command * Update package.json Minor typo fix * use executeRCommand instead of runTextInTerm Co-authored-by: Elian H. Thiele-Evans <[email protected]>
1 parent cf7836d commit 1f692eb

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"onCommand:r.goToPreviousChunk",
5555
"onCommand:r.goToNextChunk",
5656
"onCommand:r.createGitignore",
57+
"onCommand:r.createLintrConfig",
5758
"onCommand:r.runCommandWithSelectionOrWord",
5859
"onCommand:r.runCommandWithEditorPath",
5960
"onCommand:r.runCommand",
@@ -424,6 +425,11 @@
424425
"category": "R",
425426
"command": "r.createGitignore"
426427
},
428+
{
429+
"title": "Create .lintr to the workspace",
430+
"category": "R",
431+
"command": "r.createLintrConfig"
432+
},
427433
{
428434
"title": "Preview Dataframe",
429435
"category": "R",

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import path = require('path');
99
// functions etc. implemented in this extension
1010
import * as preview from './preview';
1111
import * as rGitignore from './rGitignore';
12+
import * as lintrConfig from './lintrConfig';
1213
import * as rTerminal from './rTerminal';
1314
import * as session from './session';
1415
import * as util from './util';
@@ -111,6 +112,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<apiImp
111112

112113
// editor independent commands
113114
'r.createGitignore': rGitignore.createGitignore,
115+
'r.createLintrConfig': lintrConfig.createLintrConfig,
114116
'r.loadAll': () => rTerminal.runTextInTerm('devtools::load_all()'),
115117

116118
// environment independent commands. this is a workaround for using the Tasks API: https://github.com/microsoft/vscode/issues/40758

src/lintrConfig.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
import { existsSync, unlinkSync } from 'fs';
4+
import { join } from 'path';
5+
import { window } from 'vscode';
6+
import { executeRCommand, getCurrentWorkspaceFolder } from './util';
7+
8+
export async function createLintrConfig(): Promise<string> {
9+
const currentWorkspaceFolder = getCurrentWorkspaceFolder()?.uri.fsPath;
10+
if (currentWorkspaceFolder === undefined) {
11+
void window.showWarningMessage('Please open a workspace folder to create .lintr');
12+
return;
13+
}
14+
const lintrFilePath = join(currentWorkspaceFolder, '.lintr');
15+
if (existsSync(lintrFilePath)) {
16+
const overwrite = await window.showWarningMessage(
17+
'".lintr" file already exists. Do you want to overwrite?',
18+
'Yes', 'No'
19+
);
20+
if (overwrite === 'No') {
21+
return;
22+
}
23+
void unlinkSync(lintrFilePath);
24+
}
25+
return await executeRCommand(`lintr::use_lintr()`, currentWorkspaceFolder, (e: Error) => {
26+
void window.showErrorMessage(e.message);
27+
return '';
28+
});
29+
}

0 commit comments

Comments
 (0)