import { isPythonBinary } from '../analyzer/pythonPathUtils' ; import { AnalyzerService } from '../analyzer/service' ; import type { BackgroundAnalysis } from '../backgroundAnalysis' ; import { CommandLineOptions } from '../common/commandLineOptions' ; import { createDeferred } from '../common/deferred' ; import { FileSystem } from '../common/fileSystem' ; import { combinePaths } from '../common/pathUtils' ; import { LanguageServerInterface , ServerSettings , WorkspaceServiceInstance } from '../languageServerBase' ; export class AnalyzerServiceExecutor { static runWithOptions ( languageServiceRootPath , workspace , serverSettings , typeStubTargetImportName ? , trackFiles = true ) { const commandLineOptions = getEffectiveCommandLineOptions ( languageServiceRootPath , workspace . rootPath , serverSettings , trackFiles , typeStubTargetImportName ) ; workspace . serviceInstance . setOptions ( commandLineOptions ) ; } static async cloneService ( ls , workspace , typeStubTargetImportName ? , backgroundAnalysis ? , fileSystem ? ) { const tempWorkspace = { workspaceName : `temp workspace for cloned service` , rootPath : workspace . rootPath , rootUri : workspace . rootUri , serviceInstance : workspace . serviceInstance . clone ( 'cloned service' , backgroundAnalysis , fileSystem ) , disableLanguageServices : true , disableOrganizeImports : true , isInitialized : createDeferred < boolean > ( ) , } ; const serverSettings = await ls . getSettings ( workspace ) ; AnalyzerServiceExecutor . runWithOptions ( ls . rootPath , tempWorkspace , serverSettings , typeStubTargetImportName , false ) ; return tempWorkspace . serviceInstance ; } } function getEffectiveCommandLineOptions ( languageServiceRootPath , workspaceRootPath , serverSettings , trackFiles , typeStubTargetImportName ? ) { const commandLineOptions = new CommandLineOptions ( workspaceRootPath , true ) ; commandLineOptions . checkOnlyOpenFiles = serverSettings . openFilesOnly ; commandLineOptions . useLibraryCodeForTypes = serverSettings . useLibraryCodeForTypes ; commandLineOptions . typeCheckingMode = serverSettings . typeCheckingMode ; commandLineOptions . autoImportCompletions = serverSettings . autoImportCompletions ; commandLineOptions . indexing = serverSettings . indexing ; commandLineOptions . logTypeEvaluationTime = serverSettings . logTypeEvaluationTime ?? false ; commandLineOptions . typeEvaluationTimeThreshold = serverSettings . typeEvaluationTimeThreshold ?? 50 ; commandLineOptions . enableAmbientAnalysis = trackFiles ; if ( ! trackFiles ) { commandLineOptions . watchForSourceChanges = false ; commandLineOptions . watchForLibraryChanges = false ; commandLineOptions . watchForConfigChanges = false ; } else { commandLineOptions . watchForSourceChanges = serverSettings . watchForSourceChanges ; commandLineOptions . watchForLibraryChanges = serverSettings . watchForLibraryChanges ; commandLineOptions . watchForConfigChanges = serverSettings . watchForConfigChanges ; } if ( serverSettings . venvPath ) { commandLineOptions . venvPath = combinePaths ( workspaceRootPath || languageServiceRootPath , serverSettings . venvPath ) ; } if ( serverSettings . pythonPath ) { if ( ! isPythonBinary ( serverSettings . pythonPath ) ) { commandLineOptions . pythonPath = combinePaths ( workspaceRootPath || languageServiceRootPath , serverSettings . pythonPath ) ; } } if ( serverSettings . typeshedPath ) { commandLineOptions . typeshedPath = serverSettings . typeshedPath ; } if ( serverSettings . stubPath ) { commandLineOptions . stubPath = serverSettings . stubPath ; } if ( typeStubTargetImportName ) { commandLineOptions . typeStubTargetImportName = typeStubTargetImportName ; } commandLineOptions . autoSearchPaths = serverSettings . autoSearchPaths ; commandLineOptions . extraPaths = serverSettings . extraPaths ; commandLineOptions . diagnosticSeverityOverrides = serverSettings . diagnosticSeverityOverrides ; return commandLineOptions ; }