@@ -19,26 +19,21 @@ public KiCad6LibraryReader(ISettingsProvider settingsProvider)
1919
2020 public async Task < string [ ] > GetFootprintsAsync ( )
2121 {
22- var settings = await _settingsProvider . GetWorkspaceSettings ( )
23- . ConfigureAwait ( false ) ;
22+ var settings = await _settingsProvider . GetWorkspaceSettings ( ) . ConfigureAwait ( false ) ;
2423
2524 var kicadFootprints = GetFootprintInfosFromDirectory ( settings . FootprintsPath ) ;
2625
27- return kicadFootprints
28- . Select ( x => x . ToString ( ) )
29- . ToArray ( ) ;
26+ return kicadFootprints . Select ( x => x . ToString ( ) ) . ToArray ( ) ;
3027 }
3128
3229 public async Task < string [ ] > GetSymbolsAsync ( )
3330 {
34- var settings = await _settingsProvider . GetWorkspaceSettings ( )
35- . ConfigureAwait ( false ) ;
31+ var settings = await _settingsProvider . GetWorkspaceSettings ( ) . ConfigureAwait ( false ) ;
3632
3733 var kicadSymbols = await GetSymbolInfosFromDirectoryAsync ( settings . SymbolsPath )
3834 . ConfigureAwait ( false ) ;
3935
40- return kicadSymbols
41- . ToArray ( ) ;
36+ return kicadSymbols . ToArray ( ) ;
4237 }
4338
4439 private static IEnumerable < LibraryItemInfo > GetFootprintInfosFromDirectory ( string directory )
@@ -48,45 +43,53 @@ private static IEnumerable<LibraryItemInfo> GetFootprintInfosFromDirectory(strin
4843 throw new DirectoryNotFoundException ( $ "Directory \" { directory } \" not found.") ;
4944 }
5045
51- return Directory . EnumerateDirectories ( directory , $ "*{ FileExtensions . Pretty } ")
46+ return Directory
47+ . EnumerateDirectories ( directory , $ "*{ FileExtensions . Pretty } ")
5248 . SelectMany ( GetFootprintInfos ) ;
5349 }
5450
5551 private static LibraryItemInfo [ ] GetFootprintInfos ( string footprintDirectory )
5652 {
57- var library = new DirectoryInfo ( footprintDirectory ) . Name [ ..^ FileExtensions . Pretty . Length ] ;
58-
59- return Directory . EnumerateFiles ( footprintDirectory , $ "*{ FileExtensions . KicadMod } ")
60- . Select ( Path . GetFileNameWithoutExtension )
61- . Select ( footprint => new LibraryItemInfo ( library , footprint ! ) )
62- . ToArray ( ) ;
53+ var library = new DirectoryInfo ( footprintDirectory ) . Name [
54+ ..^ FileExtensions . Pretty . Length
55+ ] ;
56+
57+ return Directory
58+ . EnumerateFiles ( footprintDirectory , $ "*{ FileExtensions . KicadMod } ")
59+ . Select ( Path . GetFileNameWithoutExtension )
60+ . Select ( footprint => new LibraryItemInfo ( library , footprint ! ) )
61+ . ToArray ( ) ;
6362 }
6463
65- private static async Task < IEnumerable < string > > GetSymbolInfosFromDirectoryAsync ( string directory )
64+ private static async Task < IEnumerable < string > > GetSymbolInfosFromDirectoryAsync (
65+ string directory
66+ )
6667 {
6768 if ( ! Directory . Exists ( directory ) )
6869 {
6970 throw new DirectoryNotFoundException ( $ "Directory \" { directory } \" not found.") ;
7071 }
7172
72- return await Directory . EnumerateFiles ( directory , $ "*{ FileExtensions . KicadSym } ")
73+ return await Directory
74+ . EnumerateFiles ( directory , $ "*{ FileExtensions . KicadSym } ")
7375 . ToAsyncEnumerable ( )
7476 . SelectMany ( GetSymbolInfosAsync )
7577 . Select ( item => item . ToString ( ) )
7678 . ToArrayAsync ( )
7779 . ConfigureAwait ( false ) ;
7880 }
7981
80- private static async IAsyncEnumerable < LibraryItemInfo > GetSymbolInfosAsync ( string libraryFile )
82+ private static async IAsyncEnumerable < LibraryItemInfo > GetSymbolInfosAsync (
83+ string libraryFile
84+ )
8185 {
8286 var sw = Stopwatch . StartNew ( ) ;
8387 var libraryName = Path . GetFileNameWithoutExtension ( libraryFile ) ;
84- var regex = new Regex ( "\\ (symbol \ " (.+?)\" (?!.*?extends)" ) ;
88+ var regex = new Regex ( "\\ (symbol\\ s+? \ " (.+?)\" \\ s+? (?!.*?extends)" ) ;
8589 var lines = await File . ReadAllTextAsync ( libraryFile , Encoding . UTF8 )
8690 . ConfigureAwait ( false ) ;
8791
88- var symbols = regex . Matches ( lines )
89- . Select ( match => match . Groups [ 1 ] . Value ) ;
92+ var symbols = regex . Matches ( lines ) . Select ( match => match . Groups [ 1 ] . Value ) ;
9093
9194 foreach ( var symbol in symbols )
9295 {
@@ -97,4 +100,4 @@ private static async IAsyncEnumerable<LibraryItemInfo> GetSymbolInfosAsync(strin
97100 Debug . WriteLine ( $ "Get Symbols from { libraryFile } : { sw . ElapsedMilliseconds } ms") ;
98101 }
99102 }
100- }
103+ }
0 commit comments