File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 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" ,
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" ,
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import path = require('path');
99// functions etc. implemented in this extension
1010import * as preview from './preview' ;
1111import * as rGitignore from './rGitignore' ;
12+ import * as lintrConfig from './lintrConfig' ;
1213import * as rTerminal from './rTerminal' ;
1314import * as session from './session' ;
1415import * 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments