import { ExecutionPath } from 'pytea/service/executionPaths' ; import { defaultOptions , PyteaOptions } from 'pytea/service/pyteaOptions' ; import { PyteaService } from 'pytea/service/pyteaService' ; import { createDeferred } from 'pyright-internal/common/deferred' ; import { WorkspaceServiceInstance } from 'pyright-internal/languageServerBase' ; import { PyteaServer } from './server' ; export interface PyteaWorkspaceInstance extends WorkspaceServiceInstance { pyteaService : PyteaService ; pyteaOptions : PyteaOptions ; selectedPath : number ; paths : ExecutionPath [ ] ; } export class PyteaWorkspaceMap extends Map < string , PyteaWorkspaceInstance > { private _defaultWorkspacePath = '<default>' ; constructor ( private _ls ) { super ( ) ; } getNonDefaultWorkspaces ( ) { const workspaces = [ ] ; this . forEach ( ( workspace ) => { if ( workspace . rootPath ) { workspaces . push ( workspace ) ; } } ) ; return workspaces ; } getWorkspaceForFile ( 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 ] ) ! ; } const pyrightService = this . _ls . createAnalyzerService ( this . _defaultWorkspacePath ) ; const pyteaService = new PyteaService ( pyrightService , undefined , this . _ls . console ) ; defaultWorkspace = { workspaceName : '' , rootPath : '' , rootUri : '' , serviceInstance : pyrightService , pyteaService : pyteaService , pyteaOptions : defaultOptions , disableLanguageServices : false , disableOrganizeImports : false , isInitialized : createDeferred < boolean > ( ) , selectedPath : 0 , paths : [ ] , } ; this . set ( this . _defaultWorkspacePath , defaultWorkspace ) ; this . _ls . updateSettingsForWorkspace ( defaultWorkspace ) . ignoreErrors ( ) ; } return defaultWorkspace ; } return bestInstance ; } }