@@ -28,12 +28,12 @@ let documents: TextDocuments = new TextDocuments();
2828// for open, change and close text document events
2929documents . listen ( connection ) ;
3030
31- let allModulePaths : Map < string , string > ;
32- let allModuleSources : Map < string , Set < string > > ;
31+ let allModulePaths : Map < string | null , string > ;
32+ let allModuleSources : Map < string | null , Set < string > > ;
3333export function initializeModuleMeta ( ) {
3434 trace ( '***initializeModuleMeta***' )
35- allModulePaths = new Map ( )
36- allModuleSources = new Map ( )
35+ allModulePaths = new Map ( [ [ null , workspaceRoot ] ] )
36+ allModuleSources = new Map ( [ [ null , new Set ( ) ] ] )
3737 const shPath = getShellExecPath ( )
3838 trace ( '***getShellExecPath: ' , shPath )
3939 const sp = spawn ( shPath , [ "-c" ,
@@ -84,7 +84,12 @@ export function getAllSourcePaths(srcPath: string): string[] {
8484 return Array . from ( ss )
8585 }
8686 }
87- return null //can not find?
87+ // when not found: interpret all global files
88+ const globalSources = allModuleSources . get ( null )
89+ if ( globalSources . has ( srcPath ) === false ) {
90+ globalSources . add ( srcPath )
91+ }
92+ return Array . from ( allModuleSources . get ( null ) )
8893}
8994
9095// After the server has started the client sends an initilize request. The server receives
@@ -201,23 +206,22 @@ documents.onDidChangeContent((change) => {
201206connection . onDidChangeWatchedFiles ( ( watched ) => {
202207 // trace('---','onDidChangeWatchedFiles');
203208 watched . changes . forEach ( e => {
204- let file ;
209+ let file : string ;
210+ function targetEntryForFile ( filePath : string ) : [ string | null , string ] {
211+ return Array . from ( allModulePaths . entries ( ) )
212+ . find ( ( [ targetName , ] ) => file . startsWith ( targetName ) )
213+ || [ null , allModulePaths . get ( null ) ] ;
214+ }
205215 switch ( e . type ) {
206216 case FileChangeType . Created :
207217 file = fromUriString ( e . uri )
208- for ( const [ m , p ] of allModulePaths ) {
209- if ( file . startsWith ( m ) ) {
210- allModuleSources . get ( m ) . add ( file )
211- }
212- }
218+ const [ targetNameToAdd , ] = targetEntryForFile ( file ) ;
219+ allModuleSources . get ( targetNameToAdd ) . add ( file ) ;
213220 break
214221 case FileChangeType . Deleted :
215222 file = fromUriString ( e . uri )
216- for ( const [ m , p ] of allModulePaths ) {
217- if ( file . startsWith ( m ) ) {
218- allModuleSources . get ( m ) . delete ( file )
219- }
220- }
223+ const [ targetNameToDelete , ] = targetEntryForFile ( file ) ;
224+ allModuleSources . get ( targetNameToDelete ) . delete ( file ) ;
221225 break
222226 default :
223227 //do nothing
0 commit comments