import { createDeferred } from './common/deferred' ; import { LanguageServerBase , WorkspaceServiceInstance } from './languageServerBase' ; export class WorkspaceMap extends Map < string , WorkspaceServiceInstance > { private _defaultWorkspacePath = '<default>' ; getNonDefaultWorkspaces ( ) { const workspaces = [ ] ; this . forEach ( ( workspace ) => { if ( workspace . rootPath ) { workspaces . push ( workspace ) ; } } ) ; return workspaces ; } getWorkspaceForFile ( ls , filePath ) { let bestRootPath ; let bestInstance ; this . forEach ( ( workspace ) => { if ( workspace . rootPath ) { if ( filePath . startsWith ( workspace . rootPath ) ) { if ( bestRootPath === undefined || workspace . rootPath . startsWith ( bestRootPath ) ) { bestRootPath = workspace . rootPath ; bestInstance = workspace ; } } } } ) ; if ( bestInstance === undefined ) { let defaultWorkspace = this . get ( this . _defaultWorkspacePath ) ; if ( ! defaultWorkspace ) { const workspaceNames = [ ... this . keys ( ) ] ; if ( workspaceNames . length === 1 ) { return this . get ( workspaceNames [ 0 ] ) ! ; } defaultWorkspace = { workspaceName : '' , rootPath : '' , rootUri : '' , serviceInstance : ls . createAnalyzerService ( this . _defaultWorkspacePath ) , disableLanguageServices : false , disableOrganizeImports : false , isInitialized : createDeferred < boolean > ( ) , } ; this . set ( this . _defaultWorkspacePath , defaultWorkspace ) ; ls . updateSettingsForWorkspace ( defaultWorkspace ) . ignoreErrors ( ) ; } return defaultWorkspace ; } return bestInstance ; } }