@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
8
8
import { LoggingService } from '../services/logging-service' ;
9
9
import { resolveVariables } from '../lib/tools' ;
10
10
import * as fg from 'fast-glob' ;
11
+ import { glob } from 'glob' ;
11
12
12
13
export default class FortranLintingProvider {
13
14
constructor ( private loggingService : LoggingService ) { }
@@ -174,13 +175,38 @@ export default class FortranLintingProvider {
174
175
private getIncludePaths ( ) : string [ ] {
175
176
const config = vscode . workspace . getConfiguration ( 'fortran' ) ;
176
177
const includePaths : string [ ] = config . get ( 'includePaths' , [ ] ) ;
178
+ // Output the original include paths
179
+ this . loggingService . logInfo ( `Linter.include:\n${ includePaths . join ( '\r\n' ) } ` ) ;
177
180
// Resolve internal variables and expand glob patterns
178
181
const resIncludePaths = includePaths . map ( e => resolveVariables ( e ) ) ;
179
182
// This needs to be after the resolvevariables since {} are used in globs
180
- const globIncPaths : string [ ] = fg . sync ( resIncludePaths , { onlyDirectories : true } ) ;
181
- // Output the original include paths
182
- this . loggingService . logInfo ( `Linter.include:\n${ includePaths . join ( '\r\n' ) } ` ) ;
183
- return globIncPaths ;
183
+ try {
184
+ const globIncPaths : string [ ] = fg . sync ( resIncludePaths , {
185
+ onlyDirectories : true ,
186
+ suppressErrors : false ,
187
+ } ) ;
188
+ return globIncPaths ;
189
+ // Try to recover from fast-glob failing due to EACCES using slower more
190
+ // robust glob.
191
+ } catch ( eacces ) {
192
+ this . loggingService . logWarning ( `You lack read permissions for an include directory
193
+ or more likely a glob match from the input 'includePaths' list. This can happen when
194
+ using overly broad root level glob patters e.g. /usr/lib/** .
195
+ No reason to worry. I will attempt to recover.
196
+ You should consider adjusting your 'includePaths' if linting performance is slow.` ) ;
197
+ this . loggingService . logWarning ( `${ eacces . message } ` ) ;
198
+ try {
199
+ const globIncPaths : string [ ] = [ ] ;
200
+ for ( const i of resIncludePaths ) {
201
+ // use '/' to match only directories and not files
202
+ globIncPaths . push ( ...glob . sync ( i + '/' , { strict : false } ) ) ;
203
+ }
204
+ return globIncPaths ;
205
+ // if we failed again then our includes are somehow wrong. Abort
206
+ } catch ( error ) {
207
+ this . loggingService . logError ( `Failed to recover: ${ error } ` ) ;
208
+ }
209
+ }
184
210
}
185
211
186
212
private getGfortranPath ( ) : string {
0 commit comments