@@ -8,6 +8,7 @@ import * as vscode from 'vscode';
88import { LoggingService } from '../services/logging-service' ;
99import { resolveVariables } from '../lib/tools' ;
1010import * as fg from 'fast-glob' ;
11+ import { glob } from 'glob' ;
1112
1213export default class FortranLintingProvider {
1314 constructor ( private loggingService : LoggingService ) { }
@@ -174,13 +175,38 @@ export default class FortranLintingProvider {
174175 private getIncludePaths ( ) : string [ ] {
175176 const config = vscode . workspace . getConfiguration ( 'fortran' ) ;
176177 const includePaths : string [ ] = config . get ( 'includePaths' , [ ] ) ;
178+ // Output the original include paths
179+ this . loggingService . logInfo ( `Linter.include:\n${ includePaths . join ( '\r\n' ) } ` ) ;
177180 // Resolve internal variables and expand glob patterns
178181 const resIncludePaths = includePaths . map ( e => resolveVariables ( e ) ) ;
179182 // 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+ }
184210 }
185211
186212 private getGfortranPath ( ) : string {
0 commit comments