@@ -118,6 +118,8 @@ lint_package <- function(path = NULL, relative_path = TRUE, ...) {
118
118
119
119
lints <- reorder_lints(lints )
120
120
class(lints ) <- " lints"
121
+ attr(lints , " package_path" ) <- path
122
+ attr(lints , " relative_path" ) <- relative_path
121
123
lints
122
124
}
123
125
@@ -198,10 +200,45 @@ print.lint <- function(x, ...) {
198
200
199
201
# ' @export
200
202
print.lints <- function (x , ... ) {
201
- lapply(x , print , ... )
203
+ if (getOption(" lintr.rstudio_source_markers" , TRUE ) &&
204
+ rstudioapi :: hasFun(" sourceMarkers" ))
205
+ rstudio_source_markers(x )
206
+ else
207
+ lapply(x , print , ... )
202
208
invisible (x )
203
209
}
204
210
211
+ rstudio_source_markers <- function (lints ) {
212
+
213
+ # if relative paths were requested then save the package_path
214
+ # to be passed along as the basePath to the sourceMarker function
215
+ relative_path <- isTRUE(attr(lints , " relative_path" ))
216
+ if (relative_path )
217
+ package_path <- attr(lints , " package_path" )
218
+ else
219
+ package_path <- NULL
220
+
221
+ # generate the markers
222
+ markers <- lapply(lints , function (x ) {
223
+ marker <- list ()
224
+ marker $ type <- x $ type
225
+ if (relative_path )
226
+ x $ filename <- file.path(package_path , x $ filename )
227
+ marker $ file <- x $ filename
228
+ marker $ line <- x $ line_number
229
+ marker $ column <- x $ column_number
230
+ marker $ message <- x $ message
231
+ marker
232
+ })
233
+
234
+ # request source markers
235
+ rstudioapi :: callFun(" sourceMarkers" ,
236
+ name = " lintr" ,
237
+ markers = markers ,
238
+ basePath = package_path ,
239
+ autoSelect = " first" )
240
+ }
241
+
205
242
highlight_string <- function (message , column_number = NULL , ranges = NULL ) {
206
243
207
244
maximum <- max(column_number , unlist(ranges ))
0 commit comments