@@ -12,18 +12,18 @@ use tracing::trace;
1212
1313use ignore:: gitignore:: { Gitignore , GitignoreBuilder } ;
1414use pgt_configuration:: {
15- ConfigurationDiagnostic , LinterConfiguration , PartialConfiguration ,
1615 database:: PartialDatabaseConfiguration ,
1716 diagnostics:: InvalidIgnorePattern ,
1817 files:: FilesConfiguration ,
1918 migrations:: { MigrationsConfiguration , PartialMigrationsConfiguration } ,
19+ ConfigurationDiagnostic , LinterConfiguration , PartialConfiguration ,
2020} ;
21- use pgt_fs:: { FileSystem , PgTPath } ;
21+ use pgt_fs:: PgTPath ;
2222
2323use crate :: {
24- DynRef , WorkspaceError ,
2524 matcher:: Matcher ,
2625 workspace:: { ProjectKey , WorkspaceData } ,
26+ WorkspaceError ,
2727} ;
2828
2929#[ derive( Debug , Default ) ]
@@ -49,6 +49,16 @@ impl WorkspaceSettings {
4949 self . current_project
5050 }
5151
52+ pub fn get_current_project_path ( & self ) -> Option < & PgTPath > {
53+ trace ! ( "Current key {:?}" , self . current_project) ;
54+ let data = self . data . get ( self . current_project ) ;
55+ if let Some ( data) = data {
56+ Some ( & data. path )
57+ } else {
58+ None
59+ }
60+ }
61+
5262 pub fn get_current_project_data_mut ( & mut self ) -> & mut ProjectData {
5363 self . data
5464 . get_mut ( self . current_project )
@@ -123,7 +133,8 @@ impl WorkspaceSettings {
123133 for ( key, path_to_settings) in iter {
124134 trace ! (
125135 "Workspace path {:?}, file path {:?}" ,
126- path_to_settings. path, path
136+ path_to_settings. path,
137+ path
127138 ) ;
128139 trace ! ( "Iter key: {:?}" , key) ;
129140 if key == self . current_project {
@@ -145,6 +156,51 @@ impl WorkspaceSettings {
145156 }
146157}
147158
159+ #[ derive( Debug ) ]
160+ pub struct WorkspaceSettingsHandle < ' a > {
161+ inner : RwLockReadGuard < ' a , WorkspaceSettings > ,
162+ }
163+
164+ impl < ' a > WorkspaceSettingsHandle < ' a > {
165+ pub ( crate ) fn new ( settings : & ' a RwLock < WorkspaceSettings > ) -> Self {
166+ Self {
167+ inner : settings. read ( ) . unwrap ( ) ,
168+ }
169+ }
170+
171+ pub ( crate ) fn settings ( & self ) -> Option < & Settings > {
172+ self . inner . get_current_settings ( )
173+ }
174+
175+ pub ( crate ) fn path ( & self ) -> Option < & PgTPath > {
176+ self . inner . get_current_project_path ( )
177+ }
178+ }
179+
180+ impl < ' a > AsRef < WorkspaceSettings > for WorkspaceSettingsHandle < ' a > {
181+ fn as_ref ( & self ) -> & WorkspaceSettings {
182+ & self . inner
183+ }
184+ }
185+
186+ pub struct WorkspaceSettingsHandleMut < ' a > {
187+ inner : RwLockWriteGuard < ' a , WorkspaceSettings > ,
188+ }
189+
190+ impl < ' a > WorkspaceSettingsHandleMut < ' a > {
191+ pub ( crate ) fn new ( settings : & ' a RwLock < WorkspaceSettings > ) -> Self {
192+ Self {
193+ inner : settings. write ( ) . unwrap ( ) ,
194+ }
195+ }
196+ }
197+
198+ impl < ' a > AsMut < WorkspaceSettings > for WorkspaceSettingsHandleMut < ' a > {
199+ fn as_mut ( & mut self ) -> & mut WorkspaceSettings {
200+ & mut self . inner
201+ }
202+ }
203+
148204/// Global settings for the entire workspace
149205#[ derive( Debug , Default ) ]
150206pub struct Settings {
0 commit comments