@zzzen/pyright-internal 1.2.0-dev.20231126 → 1.2.0-dev.20231210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerFileInfo.d.ts +4 -3
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +15 -14
- package/dist/analyzer/backgroundAnalysisProgram.js +38 -38
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +59 -52
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -1
- package/dist/analyzer/checker.js +189 -42
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/circularDependency.d.ts +3 -2
- package/dist/analyzer/circularDependency.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +36 -36
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/commentUtils.js +7 -0
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +14 -5
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +2 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +58 -47
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +5 -3
- package/dist/analyzer/declaration.js +3 -2
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +3 -2
- package/dist/analyzer/declarationUtils.js +14 -12
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +29 -25
- package/dist/analyzer/importResolver.js +300 -301
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.d.ts +5 -4
- package/dist/analyzer/importResult.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +5 -4
- package/dist/analyzer/importStatementUtils.js +23 -22
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +3 -3
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +16 -14
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeReport.d.ts +7 -6
- package/dist/analyzer/packageTypeReport.js +4 -4
- package/dist/analyzer/packageTypeReport.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +68 -64
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.d.ts +7 -6
- package/dist/analyzer/parentDirectoryCache.js +9 -10
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/parseTreeUtils.js +6 -3
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +79 -14
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +27 -26
- package/dist/analyzer/program.js +162 -156
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +3 -3
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +27 -13
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pyTypedUtils.d.ts +3 -2
- package/dist/analyzer/pyTypedUtils.js +4 -5
- package/dist/analyzer/pyTypedUtils.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.d.ts +7 -6
- package/dist/analyzer/pythonPathUtils.js +21 -23
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +24 -23
- package/dist/analyzer/service.js +187 -183
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +4 -5
- package/dist/analyzer/sourceFile.js +68 -56
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +3 -3
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +11 -10
- package/dist/analyzer/sourceMapper.js +59 -62
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/sourceMapperUtils.d.ts +2 -1
- package/dist/analyzer/sourceMapperUtils.js +2 -2
- package/dist/analyzer/sourceMapperUtils.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +3 -2
- package/dist/analyzer/tracePrinter.js +21 -23
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +2 -1
- package/dist/analyzer/typeDocStringUtils.js +14 -17
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +298 -231
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -1
- package/dist/analyzer/typeEvaluatorTypes.js +1 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -3
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +2 -0
- package/dist/analyzer/typePrinter.js +48 -8
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.d.ts +2 -1
- package/dist/analyzer/typeStubWriter.js +2 -2
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +5 -3
- package/dist/analyzer/typeUtils.js +32 -17
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +2 -0
- package/dist/analyzer/typeVarContext.js +27 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +6 -36
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +8 -12
- package/dist/analyzer/types.js +13 -20
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.d.ts +1 -2
- package/dist/backgroundAnalysis.js +6 -4
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +22 -20
- package/dist/backgroundAnalysisBase.js +76 -55
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +1 -1
- package/dist/backgroundThreadBase.js +20 -11
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/commandController.js +1 -2
- package/dist/commands/commandController.js.map +1 -1
- package/dist/commands/commands.d.ts +0 -1
- package/dist/commands/commands.js +0 -1
- package/dist/commands/commands.js.map +1 -1
- package/dist/commands/createTypeStub.js +3 -2
- package/dist/commands/createTypeStub.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +21 -20
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +5 -5
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +15 -13
- package/dist/common/configOptions.js +120 -30
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnostic.d.ts +6 -9
- package/dist/common/diagnostic.js +2 -2
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +2 -1
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/common/editAction.d.ts +6 -5
- package/dist/common/editAction.js +2 -2
- package/dist/common/editAction.js.map +1 -1
- package/dist/common/envVarUtils.d.ts +2 -1
- package/dist/common/envVarUtils.js +20 -28
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +19 -19
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +29 -28
- package/dist/common/fileWatcher.d.ts +3 -2
- package/dist/common/fileWatcher.js.map +1 -1
- package/dist/common/fullAccessHost.d.ts +8 -7
- package/dist/common/fullAccessHost.js +21 -16
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +7 -6
- package/dist/common/host.js +1 -1
- package/dist/common/host.js.map +1 -1
- package/dist/common/logTracker.d.ts +2 -1
- package/dist/common/logTracker.js +4 -4
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/pathUtils.d.ts +1 -28
- package/dist/common/pathUtils.js +17 -366
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +7 -3
- package/dist/common/realFileSystem.js +78 -60
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +2 -1
- package/dist/common/serviceProviderExtensions.js +5 -2
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/textEditTracker.d.ts +2 -1
- package/dist/common/textEditTracker.js +28 -28
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/textRange.d.ts +2 -1
- package/dist/common/textRange.js.map +1 -1
- package/dist/common/uri/baseUri.d.ts +51 -0
- package/dist/common/uri/baseUri.js +194 -0
- package/dist/common/uri/baseUri.js.map +1 -0
- package/dist/common/uri/emptyUri.d.ts +32 -0
- package/dist/common/uri/emptyUri.js +122 -0
- package/dist/common/uri/emptyUri.js.map +1 -0
- package/dist/common/uri/fileUri.d.ts +36 -0
- package/dist/common/uri/fileUri.js +180 -0
- package/dist/common/uri/fileUri.js.map +1 -0
- package/dist/common/uri/memoization.d.ts +3 -0
- package/dist/common/uri/memoization.js +72 -0
- package/dist/common/uri/memoization.js.map +1 -0
- package/dist/common/uri/uri.d.ts +50 -0
- package/dist/common/uri/uri.js +104 -0
- package/dist/common/uri/uri.js.map +1 -0
- package/dist/common/uri/uriUtils.d.ts +39 -0
- package/dist/common/uri/uriUtils.js +362 -0
- package/dist/common/uri/uriUtils.js.map +1 -0
- package/dist/common/uri/webUri.d.ts +36 -0
- package/dist/common/uri/webUri.js +207 -0
- package/dist/common/uri/webUri.js.map +1 -0
- package/dist/common/workspaceEditUtils.d.ts +8 -8
- package/dist/common/workspaceEditUtils.js +34 -37
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +19 -22
- package/dist/languageServerBase.js +91 -95
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +2 -1
- package/dist/languageService/analyzerServiceExecutor.js +14 -16
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +11 -9
- package/dist/languageService/autoImporter.js +45 -44
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +3 -2
- package/dist/languageService/callHierarchyProvider.js +23 -35
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/codeActionProvider.d.ts +2 -1
- package/dist/languageService/codeActionProvider.js +8 -24
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +7 -6
- package/dist/languageService/completionProvider.js +32 -30
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +2 -1
- package/dist/languageService/completionProviderUtils.js +1 -1
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +4 -3
- package/dist/languageService/definitionProvider.js +26 -24
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.d.ts +3 -2
- package/dist/languageService/documentHighlightProvider.js +3 -3
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +8 -7
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.d.ts +5 -4
- package/dist/languageService/documentSymbolProvider.js +9 -11
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +4 -3
- package/dist/languageService/hoverProvider.js +6 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/navigationUtils.d.ts +2 -1
- package/dist/languageService/navigationUtils.js +2 -3
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/quickActions.d.ts +2 -2
- package/dist/languageService/quickActions.js +3 -83
- package/dist/languageService/quickActions.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +10 -9
- package/dist/languageService/referencesProvider.js +28 -28
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +4 -3
- package/dist/languageService/renameProvider.js +17 -18
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +3 -2
- package/dist/languageService/signatureHelpProvider.js +4 -4
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +2 -1
- package/dist/languageService/symbolIndexer.js +1 -1
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +10 -4
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.d.ts +4 -3
- package/dist/languageService/workspaceSymbolProvider.js +10 -11
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +13 -9
- package/dist/localization/localize.js +7 -4
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -4
- package/dist/localization/package.nls.de.json +0 -4
- package/dist/localization/package.nls.en-us.json +9 -6
- package/dist/localization/package.nls.es.json +2 -6
- package/dist/localization/package.nls.fr.json +0 -4
- package/dist/localization/package.nls.it.json +0 -4
- package/dist/localization/package.nls.ja.json +0 -4
- package/dist/localization/package.nls.ko.json +0 -4
- package/dist/localization/package.nls.pl.json +0 -4
- package/dist/localization/package.nls.pt-br.json +0 -4
- package/dist/localization/package.nls.qps-ploc.json +0 -4
- package/dist/localization/package.nls.ru.json +0 -4
- package/dist/localization/package.nls.tr.json +0 -4
- package/dist/localization/package.nls.zh-cn.json +0 -4
- package/dist/localization/package.nls.zh-tw.json +0 -4
- package/dist/pyright.js +18 -17
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +13 -13
- package/dist/pyrightFileSystem.js +39 -44
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +29 -28
- package/dist/readonlyAugmentedFileSystem.js +68 -61
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +22 -21
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +39 -30
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +38 -29
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +7 -3
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +24 -22
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/documentSymbolCollector.test.js +3 -2
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +37 -35
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +4 -4
- package/dist/tests/fourSlashParser.test.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -2
- package/dist/tests/fourslash/hover.docstring.alias.fourslash.js +27 -11
- package/dist/tests/fourslash/hover.docstring.alias.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +2 -2
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +4 -5
- package/dist/tests/harness/fourslash/testLanguageService.js +9 -15
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -2
- package/dist/tests/harness/fourslash/testState.Consts.js +0 -1
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +4 -4
- package/dist/tests/harness/fourslash/testState.js +92 -52
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/testAccessHost.d.ts +3 -2
- package/dist/tests/harness/testAccessHost.js +2 -1
- package/dist/tests/harness/testAccessHost.js.map +1 -1
- package/dist/tests/harness/testHost.js +13 -11
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/vfs/factory.d.ts +3 -2
- package/dist/tests/harness/vfs/factory.js +5 -4
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +32 -31
- package/dist/tests/harness/vfs/filesystem.js +47 -49
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +1 -10
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/importResolver.test.js +81 -58
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +10 -9
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +12 -11
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/logger.test.js +2 -1
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +2 -1
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +3 -138
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +76 -25
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/service.test.js +37 -42
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +3 -2
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +8 -7
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +13 -6
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +13 -9
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +2 -5
- package/dist/tests/testStateUtils.js +27 -64
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/testUtils.d.ts +3 -5
- package/dist/tests/testUtils.js +15 -64
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +4 -3
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +23 -19
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +21 -12
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +84 -70
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +26 -21
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +36 -31
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +4 -3
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/uri.test.d.ts +1 -0
- package/dist/tests/uri.test.js +695 -0
- package/dist/tests/uri.test.js.map +1 -0
- package/dist/tests/workspaceEditUtils.test.js +28 -28
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +11 -11
- package/dist/tests/zipfs.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +13 -14
- package/dist/workspaceFactory.js +54 -55
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +2 -2
- package/dist/common/uriParser.d.ts +0 -24
- package/dist/common/uriParser.js +0 -45
- package/dist/common/uriParser.js.map +0 -1
@@ -41,6 +41,8 @@ const pythonVersion_1 = require("../common/pythonVersion");
|
|
41
41
|
const serviceProviderExtensions_1 = require("../common/serviceProviderExtensions");
|
42
42
|
const StringUtils = __importStar(require("../common/stringUtils"));
|
43
43
|
const stringUtils_1 = require("../common/stringUtils");
|
44
|
+
const uri_1 = require("../common/uri/uri");
|
45
|
+
const uriUtils_1 = require("../common/uri/uriUtils");
|
44
46
|
const characters_1 = require("../parser/characters");
|
45
47
|
const importStatementUtils_1 = require("./importStatementUtils");
|
46
48
|
const parentDirectoryCache_1 = require("./parentDirectoryCache");
|
@@ -84,20 +86,25 @@ class ImportResolver {
|
|
84
86
|
this._cachedImportResults = new Map();
|
85
87
|
this._cachedModuleNameResults = new Map();
|
86
88
|
this._cachedEntriesForPath = new Map();
|
89
|
+
this._cachedFilesForPath = new Map();
|
90
|
+
this._cachedDirExistenceForRoot = new Map();
|
87
91
|
this.cachedParentImportResults = new parentDirectoryCache_1.ParentDirectoryCache(() => this.getPythonSearchPaths([]));
|
88
92
|
}
|
89
93
|
get fileSystem() {
|
90
94
|
return this.serviceProvider.fs();
|
91
95
|
}
|
96
|
+
get tmp() {
|
97
|
+
return this.serviceProvider.tmp();
|
98
|
+
}
|
92
99
|
get partialStubs() {
|
93
100
|
return this.serviceProvider.tryGet(serviceProviderExtensions_1.ServiceKeys.partialStubs);
|
94
101
|
}
|
95
|
-
static isSupportedImportSourceFile(
|
96
|
-
const fileExtension =
|
102
|
+
static isSupportedImportSourceFile(uri) {
|
103
|
+
const fileExtension = uri.lastExtension.toLowerCase();
|
97
104
|
return supportedSourceFileExtensions.some((ext) => fileExtension === ext);
|
98
105
|
}
|
99
|
-
static isSupportedImportFile(
|
100
|
-
const fileExtension =
|
106
|
+
static isSupportedImportFile(uri) {
|
107
|
+
const fileExtension = uri.lastExtension.toLowerCase();
|
101
108
|
return exports.supportedFileExtensions.some((ext) => fileExtension === ext);
|
102
109
|
}
|
103
110
|
invalidateCache() {
|
@@ -111,28 +118,24 @@ class ImportResolver {
|
|
111
118
|
}
|
112
119
|
// Resolves the import and returns the path if it exists, otherwise
|
113
120
|
// returns undefined.
|
114
|
-
resolveImport(
|
121
|
+
resolveImport(sourceFileUri, execEnv, moduleDescriptor) {
|
115
122
|
// Wrap internal call to resolveImportInternal() to prevent calling any
|
116
123
|
// child class version of resolveImport().
|
117
|
-
return this.resolveImportInternal(
|
124
|
+
return this.resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor);
|
118
125
|
}
|
119
|
-
getCompletionSuggestions(
|
120
|
-
const suggestions = this._getCompletionSuggestionsStrict(
|
126
|
+
getCompletionSuggestions(sourceFileUri, execEnv, moduleDescriptor) {
|
127
|
+
const suggestions = this._getCompletionSuggestionsStrict(sourceFileUri, execEnv, moduleDescriptor);
|
121
128
|
// We only do parent import resolution for absolute path.
|
122
129
|
if (moduleDescriptor.leadingDots > 0) {
|
123
130
|
return suggestions;
|
124
131
|
}
|
125
|
-
const root = this.getParentImportResolutionRoot(
|
126
|
-
const origin =
|
132
|
+
const root = this.getParentImportResolutionRoot(sourceFileUri, execEnv.root);
|
133
|
+
const origin = sourceFileUri.getDirectory();
|
127
134
|
let current = origin;
|
128
|
-
while (this._shouldWalkUp(current, root, execEnv)) {
|
129
|
-
this._getCompletionSuggestionsAbsolute(
|
135
|
+
while (this._shouldWalkUp(current, root, execEnv) && current) {
|
136
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, current, moduleDescriptor, suggestions,
|
130
137
|
/* strictOnly */ false);
|
131
|
-
|
132
|
-
[success, current] = this._tryWalkUp(current);
|
133
|
-
if (!success) {
|
134
|
-
break;
|
135
|
-
}
|
138
|
+
current = this._tryWalkUp(current);
|
136
139
|
}
|
137
140
|
return suggestions;
|
138
141
|
}
|
@@ -144,21 +147,21 @@ class ImportResolver {
|
|
144
147
|
this.invalidateCache();
|
145
148
|
}
|
146
149
|
// Returns the implementation file(s) for the given stub file.
|
147
|
-
getSourceFilesFromStub(
|
148
|
-
const
|
150
|
+
getSourceFilesFromStub(stubFileUri, execEnv, _mapCompiled) {
|
151
|
+
const sourceFileUris = [];
|
149
152
|
// When ImportResolver resolves an import to a stub file, a second resolve is done
|
150
153
|
// ignoring stub files, which gives us an approximation of where the implementation
|
151
154
|
// for that stub is located.
|
152
155
|
this._cachedImportResults.forEach((map) => {
|
153
156
|
map.forEach((result) => {
|
154
157
|
if (result.isStubFile && result.isImportFound && result.nonStubImportResult) {
|
155
|
-
if (result.
|
158
|
+
if (result.resolvedUris[result.resolvedUris.length - 1].equals(stubFileUri)) {
|
156
159
|
if (result.nonStubImportResult.isImportFound) {
|
157
|
-
const
|
158
|
-
if (
|
160
|
+
const nonEmptyUri = result.nonStubImportResult.resolvedUris[result.nonStubImportResult.resolvedUris.length - 1];
|
161
|
+
if (nonEmptyUri.pathEndsWith('.py') || nonEmptyUri.pathEndsWith('.pyi')) {
|
159
162
|
// We allow pyi in case there are multiple pyi for a compiled module such as
|
160
163
|
// numpy.random.mtrand
|
161
|
-
|
164
|
+
sourceFileUris.push(nonEmptyUri);
|
162
165
|
}
|
163
166
|
}
|
164
167
|
}
|
@@ -167,14 +170,14 @@ class ImportResolver {
|
|
167
170
|
});
|
168
171
|
// We haven't seen an import of that stub, attempt to find the source
|
169
172
|
// in some other ways.
|
170
|
-
if (
|
173
|
+
if (sourceFileUris.length === 0) {
|
171
174
|
// Simple case where the stub and source files are next to each other.
|
172
|
-
const
|
173
|
-
if (this.dirExistsCached(
|
174
|
-
|
175
|
+
const sourceFileUri = stubFileUri.replaceExtension('.py');
|
176
|
+
if (this.dirExistsCached(sourceFileUri)) {
|
177
|
+
sourceFileUris.push(sourceFileUri);
|
175
178
|
}
|
176
179
|
}
|
177
|
-
if (
|
180
|
+
if (sourceFileUris.length === 0) {
|
178
181
|
// The stub and the source file may have the same name, but be located
|
179
182
|
// in different folder hierarchies.
|
180
183
|
// Example:
|
@@ -183,66 +186,62 @@ class ImportResolver {
|
|
183
186
|
// We get the relative path(s) of the stub to its import root(s),
|
184
187
|
// in theory there can be more than one, then look for source
|
185
188
|
// files in all the import roots using the same relative path(s).
|
186
|
-
const
|
189
|
+
const importRoots = this.getImportRoots(execEnv);
|
187
190
|
const relativeStubPaths = [];
|
188
|
-
for (const
|
189
|
-
if (
|
190
|
-
const parts = (
|
191
|
-
|
192
|
-
if (parts.length > 1) {
|
191
|
+
for (const importRootUri of importRoots) {
|
192
|
+
if (stubFileUri.isChild(importRootUri)) {
|
193
|
+
const parts = Array.from(importRootUri.getRelativePathComponents(stubFileUri));
|
194
|
+
if (parts.length >= 1) {
|
193
195
|
// Handle the case where the symbol was resolved to a stubs package
|
194
196
|
// rather than the real package. We'll strip off the "-stubs" suffix
|
195
197
|
// in this case.
|
196
|
-
if (parts[
|
197
|
-
parts[
|
198
|
-
}
|
199
|
-
const relativeStubPath = (0, pathUtils_1.combinePathComponents)(parts);
|
200
|
-
if (relativeStubPath) {
|
201
|
-
relativeStubPaths.push(relativeStubPath);
|
198
|
+
if (parts[0].endsWith(pathConsts_1.stubsSuffix)) {
|
199
|
+
parts[0] = parts[0].slice(0, parts[0].length - pathConsts_1.stubsSuffix.length);
|
202
200
|
}
|
201
|
+
relativeStubPaths.push(parts.join('/'));
|
203
202
|
}
|
204
203
|
}
|
205
204
|
}
|
206
205
|
for (const relativeStubPath of relativeStubPaths) {
|
207
|
-
for (const
|
208
|
-
const absoluteStubPath =
|
209
|
-
let absoluteSourcePath =
|
206
|
+
for (const importRootUri of importRoots) {
|
207
|
+
const absoluteStubPath = importRootUri.combinePaths(relativeStubPath);
|
208
|
+
let absoluteSourcePath = absoluteStubPath.replaceExtension('.py');
|
210
209
|
if (this.fileExistsCached(absoluteSourcePath)) {
|
211
|
-
|
210
|
+
sourceFileUris.push(absoluteSourcePath);
|
212
211
|
}
|
213
212
|
else {
|
214
|
-
const filePathWithoutExtension =
|
215
|
-
if (filePathWithoutExtension.
|
213
|
+
const filePathWithoutExtension = absoluteSourcePath.stripExtension();
|
214
|
+
if (filePathWithoutExtension.pathEndsWith('__init__')) {
|
216
215
|
// Did not match: <root>/package/__init__.py
|
217
216
|
// Try equivalent: <root>/package.py
|
218
|
-
absoluteSourcePath =
|
219
|
-
filePathWithoutExtension.substr(0, filePathWithoutExtension.length - 9) + '.py';
|
217
|
+
absoluteSourcePath = filePathWithoutExtension.getDirectory().packageUri;
|
220
218
|
if (this.fileExistsCached(absoluteSourcePath)) {
|
221
|
-
|
219
|
+
sourceFileUris.push(absoluteSourcePath);
|
222
220
|
}
|
223
221
|
}
|
224
222
|
else {
|
225
223
|
// Did not match: <root>/package.py
|
226
224
|
// Try equivalent: <root>/package/__init__.py
|
227
|
-
absoluteSourcePath =
|
225
|
+
absoluteSourcePath = filePathWithoutExtension.initPyUri;
|
228
226
|
if (this.fileExistsCached(absoluteSourcePath)) {
|
229
|
-
|
227
|
+
sourceFileUris.push(absoluteSourcePath);
|
230
228
|
}
|
231
229
|
}
|
232
230
|
}
|
233
231
|
}
|
234
232
|
}
|
235
233
|
}
|
236
|
-
return
|
234
|
+
return sourceFileUris;
|
237
235
|
}
|
238
236
|
// Returns the module name (of the form X.Y.Z) that needs to be imported
|
239
237
|
// from the current context to access the module with the specified file path.
|
240
238
|
// In a sense, it's performing the inverse of resolveImport.
|
241
|
-
getModuleNameForImport(
|
239
|
+
getModuleNameForImport(fileUri, execEnv, allowInvalidModuleName = false, detectPyTyped = false) {
|
240
|
+
var _a;
|
242
241
|
// Cache results of the reverse of resolveImport as we cache resolveImport.
|
243
|
-
const cache = (0, collectionUtils_1.getOrAdd)(this._cachedModuleNameResults, execEnv.root, () => new Map());
|
244
|
-
const key = `${allowInvalidModuleName}.${detectPyTyped}.${
|
245
|
-
return (0, collectionUtils_1.getOrAdd)(cache, key, () => this._getModuleNameForImport(
|
242
|
+
const cache = (0, collectionUtils_1.getOrAdd)(this._cachedModuleNameResults, (_a = execEnv.root) === null || _a === void 0 ? void 0 : _a.key, () => new Map());
|
243
|
+
const key = `${allowInvalidModuleName}.${detectPyTyped}.${fileUri.key}`;
|
244
|
+
return (0, collectionUtils_1.getOrAdd)(cache, key, () => this._getModuleNameForImport(fileUri, execEnv, allowInvalidModuleName, detectPyTyped));
|
246
245
|
}
|
247
246
|
getTypeshedStdLibPath(execEnv) {
|
248
247
|
const unused = [];
|
@@ -279,7 +278,7 @@ class ImportResolver {
|
|
279
278
|
// is where the third party folder is in the roots.
|
280
279
|
const thirdPartyRoot = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
|
281
280
|
if (thirdPartyRoot) {
|
282
|
-
roots.push(
|
281
|
+
roots.push(thirdPartyRoot.combinePaths('...'));
|
283
282
|
}
|
284
283
|
}
|
285
284
|
else {
|
@@ -297,6 +296,7 @@ class ImportResolver {
|
|
297
296
|
return roots;
|
298
297
|
}
|
299
298
|
ensurePartialStubPackages(execEnv) {
|
299
|
+
var _a;
|
300
300
|
if (!this.partialStubs) {
|
301
301
|
return false;
|
302
302
|
}
|
@@ -309,7 +309,7 @@ class ImportResolver {
|
|
309
309
|
const typeshedPathEx = this.getTypeshedPathEx(execEnv, ignored);
|
310
310
|
// Add paths to search stub packages.
|
311
311
|
addPaths(this._configOptions.stubPath);
|
312
|
-
addPaths(execEnv.root);
|
312
|
+
addPaths((_a = execEnv.root) !== null && _a !== void 0 ? _a : this._configOptions.projectRoot);
|
313
313
|
execEnv.extraPaths.forEach((p) => addPaths(p));
|
314
314
|
addPaths(typeshedPathEx);
|
315
315
|
this.getPythonSearchPaths(ignored).forEach((p) => addPaths(p));
|
@@ -349,59 +349,58 @@ class ImportResolver {
|
|
349
349
|
if (versionRange.max !== undefined && pythonVersion > versionRange.max) {
|
350
350
|
// Add excludes for both the ".pyi" file and the directory that contains it
|
351
351
|
// (in case it's using a "__init__.pyi" file).
|
352
|
-
const moduleDirPath =
|
352
|
+
const moduleDirPath = typeshedStdlibPath.combinePaths(...moduleName.split('.'));
|
353
353
|
excludes.push(moduleDirPath);
|
354
|
-
const moduleFilePath = moduleDirPath
|
354
|
+
const moduleFilePath = moduleDirPath.replaceExtension('.pyi');
|
355
355
|
excludes.push(moduleFilePath);
|
356
356
|
}
|
357
357
|
});
|
358
358
|
return excludes;
|
359
359
|
}
|
360
|
-
readdirEntriesCached(
|
361
|
-
const cachedValue = this._cachedEntriesForPath.get(
|
360
|
+
readdirEntriesCached(uri) {
|
361
|
+
const cachedValue = this._cachedEntriesForPath.get(uri.key);
|
362
362
|
if (cachedValue) {
|
363
363
|
return cachedValue;
|
364
364
|
}
|
365
365
|
let newCacheValue;
|
366
366
|
try {
|
367
|
-
newCacheValue = this.fileSystem.readdirEntriesSync(
|
367
|
+
newCacheValue = this.fileSystem.readdirEntriesSync(uri);
|
368
368
|
}
|
369
369
|
catch {
|
370
370
|
newCacheValue = [];
|
371
371
|
}
|
372
372
|
// Populate cache for next time.
|
373
|
-
this._cachedEntriesForPath.set(
|
373
|
+
this._cachedEntriesForPath.set(uri.key, newCacheValue);
|
374
374
|
return newCacheValue;
|
375
375
|
}
|
376
376
|
// Resolves the import and returns the path if it exists, otherwise
|
377
377
|
// returns undefined.
|
378
|
-
resolveImportInternal(
|
378
|
+
resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor) {
|
379
379
|
const importName = this.formatImportName(moduleDescriptor);
|
380
380
|
const importFailureInfo = [];
|
381
|
-
const importResult = this._resolveImportStrict(importName,
|
381
|
+
const importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo);
|
382
382
|
if (importResult.isImportFound || moduleDescriptor.leadingDots > 0) {
|
383
383
|
return importResult;
|
384
384
|
}
|
385
385
|
// If the import is absolute and no other method works, try resolving the
|
386
386
|
// absolute in the importing file's directory, then the parent directory,
|
387
387
|
// and so on, until the import root is reached.
|
388
|
-
|
389
|
-
const origin = (0, pathUtils_1.ensureTrailingDirectorySeparator)((0, pathUtils_1.getDirectoryPath)(sourceFilePath));
|
388
|
+
const origin = sourceFileUri.getDirectory();
|
390
389
|
const result = this.cachedParentImportResults.getImportResult(origin, importName, importResult);
|
391
390
|
if (result) {
|
392
391
|
// Already ran the parent directory resolution for this import name on this location.
|
393
392
|
return this.filterImplicitImports(result, moduleDescriptor.importedSymbols);
|
394
393
|
}
|
395
394
|
// Check whether the given file is in the parent directory import resolution cache.
|
396
|
-
const root = this.getParentImportResolutionRoot(
|
397
|
-
if (!this.cachedParentImportResults.checkValidPath(this.fileSystem,
|
395
|
+
const root = this.getParentImportResolutionRoot(sourceFileUri, execEnv.root);
|
396
|
+
if (!this.cachedParentImportResults.checkValidPath(this.fileSystem, sourceFileUri, root)) {
|
398
397
|
return importResult;
|
399
398
|
}
|
400
399
|
const importPath = { importPath: undefined };
|
401
400
|
// Going up the given folder one by one until we can resolve the import.
|
402
401
|
let current = origin;
|
403
|
-
while (this._shouldWalkUp(current, root, execEnv)) {
|
404
|
-
const result = this.resolveAbsoluteImport(
|
402
|
+
while (this._shouldWalkUp(current, root, execEnv) && current) {
|
403
|
+
const result = this.resolveAbsoluteImport(sourceFileUri, current, execEnv, moduleDescriptor, importName, [],
|
405
404
|
/* allowPartial */ undefined,
|
406
405
|
/* allowNativeLib */ undefined,
|
407
406
|
/* useStubPackage */ false,
|
@@ -417,68 +416,72 @@ class ImportResolver {
|
|
417
416
|
});
|
418
417
|
return this.filterImplicitImports(result, moduleDescriptor.importedSymbols);
|
419
418
|
}
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
}
|
419
|
+
current = this._tryWalkUp(current);
|
420
|
+
}
|
421
|
+
if (current) {
|
422
|
+
this.cachedParentImportResults.checked(current, importName, importPath);
|
425
423
|
}
|
426
|
-
this.cachedParentImportResults.checked(current, importName, importPath);
|
427
424
|
return importResult;
|
428
425
|
}
|
429
|
-
fileExistsCached(
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
return false;
|
435
|
-
}
|
436
|
-
return (_b = (_a = (0, pathUtils_1.tryStat)(this.fileSystem, path)) === null || _a === void 0 ? void 0 : _a.isFile()) !== null && _b !== void 0 ? _b : false;
|
426
|
+
fileExistsCached(uri) {
|
427
|
+
const directory = uri.getDirectory();
|
428
|
+
if (directory.equals(uri)) {
|
429
|
+
// Started at root, so this can't be a file.
|
430
|
+
return false;
|
437
431
|
}
|
438
|
-
const
|
439
|
-
const
|
432
|
+
const fileName = uri.fileName;
|
433
|
+
const entries = this.readdirEntriesCached(directory);
|
434
|
+
const entry = entries.find((entry) => entry.name === fileName);
|
440
435
|
if (entry === null || entry === void 0 ? void 0 : entry.isFile()) {
|
441
436
|
return true;
|
442
437
|
}
|
443
438
|
if (entry === null || entry === void 0 ? void 0 : entry.isSymbolicLink()) {
|
444
|
-
const realPath = (0,
|
445
|
-
if (realPath && this.fileSystem.existsSync(realPath) && (0,
|
439
|
+
const realPath = (0, uriUtils_1.tryRealpath)(this.fileSystem, uri);
|
440
|
+
if (realPath && this.fileSystem.existsSync(realPath) && (0, uriUtils_1.isFile)(this.fileSystem, realPath)) {
|
446
441
|
return true;
|
447
442
|
}
|
448
443
|
}
|
449
444
|
return false;
|
450
445
|
}
|
451
|
-
dirExistsCached(
|
446
|
+
dirExistsCached(uri) {
|
452
447
|
var _a, _b;
|
453
|
-
const
|
454
|
-
if (
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
448
|
+
const parent = uri.getDirectory();
|
449
|
+
if (parent.equals(uri)) {
|
450
|
+
// Started at root. No entries to read, so have to check ourselves.
|
451
|
+
let cachedExistence = this._cachedDirExistenceForRoot.get(uri.key);
|
452
|
+
// Check if the value was in the cache or not. Undefined means it wasn't.
|
453
|
+
if (cachedExistence === undefined) {
|
454
|
+
cachedExistence = (_b = (_a = (0, uriUtils_1.tryStat)(this.fileSystem, uri)) === null || _a === void 0 ? void 0 : _a.isDirectory()) !== null && _b !== void 0 ? _b : false;
|
455
|
+
this._cachedDirExistenceForRoot.set(uri.key, cachedExistence);
|
456
|
+
}
|
457
|
+
return cachedExistence;
|
458
|
+
}
|
459
|
+
// Otherwise not a root, so read the entries we have cached to see if
|
460
|
+
// the directory exists or not.
|
461
|
+
const directoryName = uri.fileName;
|
462
|
+
const entries = this.readdirEntriesCached(parent);
|
463
|
+
const entry = entries.find((entry) => entry.name === directoryName);
|
462
464
|
if (entry === null || entry === void 0 ? void 0 : entry.isDirectory()) {
|
463
465
|
return true;
|
464
466
|
}
|
465
467
|
if (entry === null || entry === void 0 ? void 0 : entry.isSymbolicLink()) {
|
466
|
-
const realPath = (0,
|
467
|
-
if (realPath && this.fileSystem.existsSync(realPath) && (0,
|
468
|
+
const realPath = (0, uriUtils_1.tryRealpath)(this.fileSystem, uri);
|
469
|
+
if (realPath && this.fileSystem.existsSync(realPath) && (0, uriUtils_1.isDirectory)(this.fileSystem, realPath)) {
|
468
470
|
return true;
|
469
471
|
}
|
470
472
|
}
|
471
473
|
return false;
|
472
474
|
}
|
473
|
-
addResultsToCache(
|
475
|
+
addResultsToCache(sourceFileUri, execEnv, importName, importResult, moduleDescriptor, fromUserFile) {
|
476
|
+
var _a;
|
474
477
|
// If the import is relative, include the source file path in the key.
|
475
|
-
const
|
476
|
-
(0, collectionUtils_1.getOrAdd)(this._cachedImportResults, execEnv.root, () => new Map()).set(this._getImportCacheKey(
|
478
|
+
const relativeSourceFileUri = moduleDescriptor && moduleDescriptor.leadingDots > 0 ? sourceFileUri : undefined;
|
479
|
+
(0, collectionUtils_1.getOrAdd)(this._cachedImportResults, (_a = execEnv.root) === null || _a === void 0 ? void 0 : _a.key, () => new Map()).set(this._getImportCacheKey(relativeSourceFileUri, importName, fromUserFile), importResult);
|
477
480
|
return this.filterImplicitImports(importResult, moduleDescriptor === null || moduleDescriptor === void 0 ? void 0 : moduleDescriptor.importedSymbols);
|
478
481
|
}
|
479
482
|
// Follows import resolution algorithm defined in PEP-420:
|
480
483
|
// https://www.python.org/dev/peps/pep-0420/
|
481
|
-
resolveAbsoluteImport(
|
484
|
+
resolveAbsoluteImport(sourceFileUri, rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial = false, allowNativeLib = false, useStubPackage = false, allowPyi = true, lookForPyTyped = false) {
|
482
485
|
if (allowPyi && useStubPackage) {
|
483
486
|
// Look for packaged stubs first. PEP 561 indicates that package authors can ship
|
484
487
|
// their stubs separately from their package implementation by appending the string
|
@@ -508,46 +511,43 @@ class ImportResolver {
|
|
508
511
|
// Intended to be overridden by subclasses to provide additional stub
|
509
512
|
// resolving capabilities. Return undefined if no stubs were found for
|
510
513
|
// this import.
|
511
|
-
resolveImportEx(
|
514
|
+
resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo = [], allowPyi = true) {
|
512
515
|
return undefined;
|
513
516
|
}
|
514
517
|
// Intended to be overridden by subclasses to provide additional stub
|
515
518
|
// resolving capabilities for native (compiled) modules. Returns undefined
|
516
519
|
// if no stubs were found for this import.
|
517
|
-
resolveNativeImportEx(
|
520
|
+
resolveNativeImportEx(libraryFileUri, importName, importFailureInfo = []) {
|
518
521
|
return undefined;
|
519
522
|
}
|
520
|
-
getNativeModuleName(
|
521
|
-
const fileExtension =
|
523
|
+
getNativeModuleName(uri) {
|
524
|
+
const fileExtension = uri.lastExtension.toLowerCase();
|
522
525
|
if (this._isNativeModuleFileExtension(fileExtension)) {
|
523
|
-
return (0, pathUtils_1.stripFileExtension)(
|
526
|
+
return (0, pathUtils_1.stripFileExtension)(uri.fileName, /* multiDotExtension */ true);
|
524
527
|
}
|
525
528
|
return undefined;
|
526
529
|
}
|
527
|
-
getModuleNameFromPath(containerPath,
|
528
|
-
const moduleNameInfo = this.getModuleNameInfoFromPath(containerPath,
|
530
|
+
getModuleNameFromPath(containerPath, fileUri, stripTopContainerDir = false) {
|
531
|
+
const moduleNameInfo = this.getModuleNameInfoFromPath(containerPath, fileUri, stripTopContainerDir);
|
529
532
|
if (!moduleNameInfo || moduleNameInfo.containsInvalidCharacters) {
|
530
533
|
return undefined;
|
531
534
|
}
|
532
535
|
return moduleNameInfo.moduleName;
|
533
536
|
}
|
534
|
-
getModuleNameInfoFromPath(containerPath,
|
535
|
-
|
536
|
-
let filePathWithoutExtension = (0, pathUtils_1.stripFileExtension)(filePath);
|
537
|
+
getModuleNameInfoFromPath(containerPath, fileUri, stripTopContainerDir = false) {
|
538
|
+
let fileUriWithoutExtension = fileUri.stripExtension();
|
537
539
|
// If module is native, strip platform part, such as 'cp36-win_amd64' in 'mtrand.cp36-win_amd64'.
|
538
|
-
if (this._isNativeModuleFileExtension(
|
539
|
-
|
540
|
+
if (this._isNativeModuleFileExtension(fileUri.lastExtension)) {
|
541
|
+
fileUriWithoutExtension = fileUriWithoutExtension.stripExtension();
|
540
542
|
}
|
541
|
-
if (!
|
543
|
+
if (!fileUriWithoutExtension.startsWith(containerPath)) {
|
542
544
|
return undefined;
|
543
545
|
}
|
544
546
|
// Strip off the '/__init__' if it's present.
|
545
|
-
if (
|
546
|
-
|
547
|
+
if (fileUriWithoutExtension.pathEndsWith('__init__')) {
|
548
|
+
fileUriWithoutExtension = fileUriWithoutExtension.getDirectory();
|
547
549
|
}
|
548
|
-
const
|
549
|
-
const parts = (0, pathUtils_1.getPathComponents)(relativeFilePath);
|
550
|
-
parts.shift();
|
550
|
+
const parts = Array.from(containerPath.getRelativePathComponents(fileUriWithoutExtension));
|
551
551
|
if (stripTopContainerDir) {
|
552
552
|
if (parts.length === 0) {
|
553
553
|
return undefined;
|
@@ -600,14 +600,14 @@ class ImportResolver {
|
|
600
600
|
formatImportName(moduleDescriptor) {
|
601
601
|
return '.'.repeat(moduleDescriptor.leadingDots) + moduleDescriptor.nameParts.join('.');
|
602
602
|
}
|
603
|
-
getParentImportResolutionRoot(
|
603
|
+
getParentImportResolutionRoot(sourceFileUri, executionRoot) {
|
604
604
|
if (executionRoot) {
|
605
|
-
return
|
605
|
+
return this.fileSystem.realCasePath(executionRoot);
|
606
606
|
}
|
607
|
-
return
|
607
|
+
return sourceFileUri.getDirectory();
|
608
608
|
}
|
609
|
-
_resolveImportStrict(importName,
|
610
|
-
const fromUserFile = (0, configOptions_1.matchFileSpecs)(this._configOptions,
|
609
|
+
_resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo) {
|
610
|
+
const fromUserFile = (0, configOptions_1.matchFileSpecs)(this._configOptions, sourceFileUri);
|
611
611
|
const notFoundResult = {
|
612
612
|
importName,
|
613
613
|
isRelative: false,
|
@@ -617,7 +617,7 @@ class ImportResolver {
|
|
617
617
|
isInitFilePresent: false,
|
618
618
|
isStubPackage: false,
|
619
619
|
importFailureInfo,
|
620
|
-
|
620
|
+
resolvedUris: [],
|
621
621
|
importType: 2 /* ImportType.Local */,
|
622
622
|
isStubFile: false,
|
623
623
|
isNativeLib: false,
|
@@ -628,18 +628,18 @@ class ImportResolver {
|
|
628
628
|
this.ensurePartialStubPackages(execEnv);
|
629
629
|
// Is it a relative import?
|
630
630
|
if (moduleDescriptor.leadingDots > 0) {
|
631
|
-
const cachedResults = this._lookUpResultsInCache(
|
631
|
+
const cachedResults = this._lookUpResultsInCache(sourceFileUri, execEnv, importName, moduleDescriptor, fromUserFile);
|
632
632
|
if (cachedResults) {
|
633
633
|
return cachedResults;
|
634
634
|
}
|
635
|
-
const relativeImport = this._resolveRelativeImport(
|
635
|
+
const relativeImport = this._resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo);
|
636
636
|
if (relativeImport) {
|
637
637
|
relativeImport.isRelative = true;
|
638
|
-
return this.addResultsToCache(
|
638
|
+
return this.addResultsToCache(sourceFileUri, execEnv, importName, relativeImport, moduleDescriptor, fromUserFile);
|
639
639
|
}
|
640
640
|
}
|
641
641
|
else {
|
642
|
-
const cachedResults = this._lookUpResultsInCache(
|
642
|
+
const cachedResults = this._lookUpResultsInCache(sourceFileUri, execEnv, importName, moduleDescriptor, fromUserFile);
|
643
643
|
if (cachedResults) {
|
644
644
|
// In most cases, we can simply return a cached entry. However, there are cases
|
645
645
|
// where the cached entry refers to a previously-resolved namespace package
|
@@ -653,54 +653,54 @@ class ImportResolver {
|
|
653
653
|
return cachedResults;
|
654
654
|
}
|
655
655
|
}
|
656
|
-
const bestImport = this._resolveBestAbsoluteImport(
|
656
|
+
const bestImport = this._resolveBestAbsoluteImport(sourceFileUri, execEnv, moduleDescriptor,
|
657
657
|
/* allowPyi */ true);
|
658
658
|
if (bestImport) {
|
659
659
|
if (bestImport.isStubFile) {
|
660
660
|
bestImport.nonStubImportResult =
|
661
|
-
this._resolveBestAbsoluteImport(
|
661
|
+
this._resolveBestAbsoluteImport(sourceFileUri, execEnv, moduleDescriptor,
|
662
662
|
/* allowPyi */ false) || notFoundResult;
|
663
663
|
}
|
664
|
-
return this.addResultsToCache(
|
664
|
+
return this.addResultsToCache(sourceFileUri, execEnv, importName, bestImport, moduleDescriptor, fromUserFile);
|
665
665
|
}
|
666
666
|
}
|
667
|
-
return this.addResultsToCache(
|
667
|
+
return this.addResultsToCache(sourceFileUri, execEnv, importName, notFoundResult,
|
668
668
|
/* moduleDescriptor */ undefined, fromUserFile);
|
669
669
|
}
|
670
|
-
_getCompletionSuggestionsStrict(
|
670
|
+
_getCompletionSuggestionsStrict(sourceFileUri, execEnv, moduleDescriptor) {
|
671
671
|
const importFailureInfo = [];
|
672
672
|
const suggestions = new Map();
|
673
673
|
// Is it a relative import?
|
674
674
|
if (moduleDescriptor.leadingDots > 0) {
|
675
|
-
this._getCompletionSuggestionsRelative(
|
675
|
+
this._getCompletionSuggestionsRelative(sourceFileUri, execEnv, moduleDescriptor, suggestions);
|
676
676
|
}
|
677
677
|
else {
|
678
678
|
// First check for a typeshed file.
|
679
679
|
if (moduleDescriptor.nameParts.length > 0) {
|
680
|
-
this._getCompletionSuggestionsTypeshedPath(
|
680
|
+
this._getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, true, suggestions);
|
681
681
|
}
|
682
682
|
// Look for it in the root directory of the execution environment.
|
683
683
|
if (execEnv.root) {
|
684
|
-
this._getCompletionSuggestionsAbsolute(
|
684
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, execEnv.root, moduleDescriptor, suggestions);
|
685
685
|
}
|
686
686
|
for (const extraPath of execEnv.extraPaths) {
|
687
|
-
this._getCompletionSuggestionsAbsolute(
|
687
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, extraPath, moduleDescriptor, suggestions);
|
688
688
|
}
|
689
689
|
// Check for a typings file.
|
690
690
|
if (this._configOptions.stubPath) {
|
691
|
-
this._getCompletionSuggestionsAbsolute(
|
691
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, this._configOptions.stubPath, moduleDescriptor, suggestions);
|
692
692
|
}
|
693
693
|
// Check for a typeshed file.
|
694
|
-
this._getCompletionSuggestionsTypeshedPath(
|
694
|
+
this._getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, false, suggestions);
|
695
695
|
// Look for the import in the list of third-party packages.
|
696
696
|
const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
|
697
697
|
for (const searchPath of pythonSearchPaths) {
|
698
|
-
this._getCompletionSuggestionsAbsolute(
|
698
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, searchPath, moduleDescriptor, suggestions);
|
699
699
|
}
|
700
700
|
}
|
701
701
|
return suggestions;
|
702
702
|
}
|
703
|
-
_getModuleNameForImport(
|
703
|
+
_getModuleNameForImport(fileUri, execEnv, allowInvalidModuleName, detectPyTyped) {
|
704
704
|
let moduleName;
|
705
705
|
let importType = 0 /* ImportType.BuiltIn */;
|
706
706
|
let isLocalTypingsFile = false;
|
@@ -715,7 +715,7 @@ class ImportResolver {
|
|
715
715
|
// Is this a stdlib typeshed path?
|
716
716
|
const stdLibTypeshedPath = this._getStdlibTypeshedPath(this._configOptions.typeshedPath, execEnv.pythonVersion, importFailureInfo);
|
717
717
|
if (stdLibTypeshedPath) {
|
718
|
-
moduleName = this.getModuleNameFromPath(stdLibTypeshedPath,
|
718
|
+
moduleName = this.getModuleNameFromPath(stdLibTypeshedPath, fileUri);
|
719
719
|
if (moduleName) {
|
720
720
|
const moduleDescriptor = {
|
721
721
|
leadingDots: 0,
|
@@ -735,7 +735,7 @@ class ImportResolver {
|
|
735
735
|
}
|
736
736
|
// Look for it in the root directory of the execution environment.
|
737
737
|
if (execEnv.root) {
|
738
|
-
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(execEnv.root,
|
738
|
+
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(execEnv.root, fileUri);
|
739
739
|
if (candidateModuleNameInfo) {
|
740
740
|
if (candidateModuleNameInfo.containsInvalidCharacters) {
|
741
741
|
moduleNameWithInvalidCharacters = candidateModuleNameInfo.moduleName;
|
@@ -747,7 +747,7 @@ class ImportResolver {
|
|
747
747
|
importType = 2 /* ImportType.Local */;
|
748
748
|
}
|
749
749
|
for (const extraPath of execEnv.extraPaths) {
|
750
|
-
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(extraPath,
|
750
|
+
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(extraPath, fileUri);
|
751
751
|
if (candidateModuleNameInfo) {
|
752
752
|
if (candidateModuleNameInfo.containsInvalidCharacters) {
|
753
753
|
moduleNameWithInvalidCharacters = candidateModuleNameInfo.moduleName;
|
@@ -765,7 +765,7 @@ class ImportResolver {
|
|
765
765
|
}
|
766
766
|
// Check for a typings file.
|
767
767
|
if (this._configOptions.stubPath) {
|
768
|
-
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(this._configOptions.stubPath,
|
768
|
+
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(this._configOptions.stubPath, fileUri);
|
769
769
|
if (candidateModuleNameInfo) {
|
770
770
|
if (candidateModuleNameInfo.containsInvalidCharacters) {
|
771
771
|
moduleNameWithInvalidCharacters = candidateModuleNameInfo.moduleName;
|
@@ -786,7 +786,7 @@ class ImportResolver {
|
|
786
786
|
// Check for a typeshed file.
|
787
787
|
const thirdPartyTypeshedPath = this._getThirdPartyTypeshedPath(this._configOptions.typeshedPath, importFailureInfo);
|
788
788
|
if (thirdPartyTypeshedPath) {
|
789
|
-
const candidateModuleName = this.getModuleNameFromPath(thirdPartyTypeshedPath,
|
789
|
+
const candidateModuleName = this.getModuleNameFromPath(thirdPartyTypeshedPath, fileUri,
|
790
790
|
/* stripTopContainerDir */ true);
|
791
791
|
// Does this candidate look better than the previous best module name?
|
792
792
|
// We'll always try to use the shortest version.
|
@@ -798,7 +798,7 @@ class ImportResolver {
|
|
798
798
|
}
|
799
799
|
const thirdPartyTypeshedPathEx = this.getTypeshedPathEx(execEnv, importFailureInfo);
|
800
800
|
if (thirdPartyTypeshedPathEx) {
|
801
|
-
const candidateModuleName = this.getModuleNameFromPath(thirdPartyTypeshedPathEx,
|
801
|
+
const candidateModuleName = this.getModuleNameFromPath(thirdPartyTypeshedPathEx, fileUri);
|
802
802
|
// Does this candidate look better than the previous best module name?
|
803
803
|
// We'll always try to use the shortest version.
|
804
804
|
if (!moduleName || (candidateModuleName && candidateModuleName.length < moduleName.length)) {
|
@@ -810,7 +810,7 @@ class ImportResolver {
|
|
810
810
|
// Look for the import in the list of third-party packages.
|
811
811
|
const pythonSearchPaths = this.getPythonSearchPaths(importFailureInfo);
|
812
812
|
for (const searchPath of pythonSearchPaths) {
|
813
|
-
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(searchPath,
|
813
|
+
const candidateModuleNameInfo = this.getModuleNameInfoFromPath(searchPath, fileUri);
|
814
814
|
if (candidateModuleNameInfo) {
|
815
815
|
if (candidateModuleNameInfo.containsInvalidCharacters) {
|
816
816
|
moduleNameWithInvalidCharacters = candidateModuleNameInfo.moduleName;
|
@@ -828,22 +828,16 @@ class ImportResolver {
|
|
828
828
|
}
|
829
829
|
}
|
830
830
|
if (detectPyTyped && importType === 1 /* ImportType.ThirdParty */) {
|
831
|
-
const root = this.getParentImportResolutionRoot(
|
831
|
+
const root = this.getParentImportResolutionRoot(fileUri, execEnv.root);
|
832
832
|
// Go up directories one by one looking for a py.typed file.
|
833
|
-
let current =
|
833
|
+
let current = fileUri.getDirectory();
|
834
834
|
while (this._shouldWalkUp(current, root, execEnv)) {
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
isThirdPartyPyTypedPresent = true;
|
839
|
-
}
|
840
|
-
break;
|
841
|
-
}
|
842
|
-
let success;
|
843
|
-
[success, current] = this._tryWalkUp(current);
|
844
|
-
if (!success) {
|
845
|
-
break;
|
835
|
+
const pyTypedInfo = this._getPyTypedInfo(current);
|
836
|
+
if (pyTypedInfo && !pyTypedInfo.isPartiallyTyped) {
|
837
|
+
isThirdPartyPyTypedPresent = true;
|
846
838
|
}
|
839
|
+
break;
|
840
|
+
current = this._tryWalkUp(current);
|
847
841
|
}
|
848
842
|
}
|
849
843
|
if (moduleName) {
|
@@ -869,17 +863,8 @@ class ImportResolver {
|
|
869
863
|
}
|
870
864
|
_invalidateFileSystemCache() {
|
871
865
|
this._cachedEntriesForPath.clear();
|
872
|
-
|
873
|
-
|
874
|
-
// a file or dir within that containing directory.
|
875
|
-
_splitPath(path) {
|
876
|
-
const pathComponents = (0, pathUtils_1.getPathComponents)(path);
|
877
|
-
if (pathComponents.length <= 1) {
|
878
|
-
return [path, ''];
|
879
|
-
}
|
880
|
-
const containingPath = (0, pathUtils_1.combinePathComponents)(pathComponents.slice(0, -1));
|
881
|
-
const fileOrDirName = pathComponents[pathComponents.length - 1];
|
882
|
-
return [containingPath, fileOrDirName];
|
866
|
+
this._cachedFilesForPath.clear();
|
867
|
+
this._cachedDirExistenceForRoot.clear();
|
883
868
|
}
|
884
869
|
_resolveAbsoluteImport(rootPath, execEnv, moduleDescriptor, importName, importFailureInfo, allowPartial, allowNativeLib, useStubPackage, allowPyi, lookForPyTyped) {
|
885
870
|
if (useStubPackage) {
|
@@ -902,9 +887,8 @@ class ImportResolver {
|
|
902
887
|
let pyTypedInfo;
|
903
888
|
// Handle the "from . import XXX" case.
|
904
889
|
if (moduleDescriptor.nameParts.length === 0) {
|
905
|
-
const
|
906
|
-
const
|
907
|
-
const pyiFilePath = (0, pathUtils_1.combinePaths)(dirPath, fileNameWithoutExtension + '.pyi');
|
890
|
+
const pyFilePath = dirPath.initPyUri;
|
891
|
+
const pyiFilePath = dirPath.initPyiUri;
|
908
892
|
if (allowPyi && this.fileExistsCached(pyiFilePath)) {
|
909
893
|
importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
|
910
894
|
resolvedPaths.push(pyiFilePath);
|
@@ -916,7 +900,7 @@ class ImportResolver {
|
|
916
900
|
}
|
917
901
|
else {
|
918
902
|
importFailureInfo.push(`Partially resolved import with directory '${dirPath}'`);
|
919
|
-
resolvedPaths.push(
|
903
|
+
resolvedPaths.push(uri_1.Uri.empty());
|
920
904
|
isNamespacePackage = true;
|
921
905
|
}
|
922
906
|
implicitImports = this._findImplicitImports(importName, dirPath, [pyFilePath, pyiFilePath]);
|
@@ -925,9 +909,9 @@ class ImportResolver {
|
|
925
909
|
for (let i = 0; i < moduleDescriptor.nameParts.length; i++) {
|
926
910
|
const isFirstPart = i === 0;
|
927
911
|
const isLastPart = i === moduleDescriptor.nameParts.length - 1;
|
928
|
-
dirPath =
|
912
|
+
dirPath = dirPath.combinePaths(moduleDescriptor.nameParts[i]);
|
929
913
|
if (useStubPackage && isFirstPart) {
|
930
|
-
dirPath
|
914
|
+
dirPath = dirPath.addPath(pathConsts_1.stubsSuffix);
|
931
915
|
isStubPackage = true;
|
932
916
|
}
|
933
917
|
const foundDirectory = this.dirExistsCached(dirPath);
|
@@ -936,9 +920,8 @@ class ImportResolver {
|
|
936
920
|
packageDirectory = dirPath;
|
937
921
|
}
|
938
922
|
// See if we can find an __init__.py[i] in this directory.
|
939
|
-
const
|
940
|
-
const
|
941
|
-
const pyiFilePath = (0, pathUtils_1.combinePaths)(dirPath, fileNameWithoutExtension + '.pyi');
|
923
|
+
const pyFilePath = dirPath.initPyUri;
|
924
|
+
const pyiFilePath = dirPath.initPyiUri;
|
942
925
|
isInitFilePresent = false;
|
943
926
|
if (allowPyi && this.fileExistsCached(pyiFilePath)) {
|
944
927
|
importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
|
@@ -954,15 +937,13 @@ class ImportResolver {
|
|
954
937
|
isInitFilePresent = true;
|
955
938
|
}
|
956
939
|
if (!pyTypedInfo && lookForPyTyped) {
|
957
|
-
|
958
|
-
pyTypedInfo = (0, pyTypedUtils_1.getPyTypedInfo)(this.fileSystem, dirPath);
|
959
|
-
}
|
940
|
+
pyTypedInfo = this._getPyTypedInfo(dirPath);
|
960
941
|
}
|
961
942
|
if (!isLastPart) {
|
962
943
|
// We are not at the last part, and we found a directory,
|
963
944
|
// so continue to look for the next part.
|
964
945
|
if (!isInitFilePresent) {
|
965
|
-
resolvedPaths.push(
|
946
|
+
resolvedPaths.push(uri_1.Uri.empty());
|
966
947
|
isNamespacePackage = true;
|
967
948
|
pyTypedInfo = undefined;
|
968
949
|
}
|
@@ -979,11 +960,9 @@ class ImportResolver {
|
|
979
960
|
// We weren't able to find a directory or we found a directory with
|
980
961
|
// no __init__.py[i] file. See if we can find a ".py" or ".pyi" file
|
981
962
|
// with this name.
|
982
|
-
|
983
|
-
const
|
984
|
-
fileDirectory =
|
985
|
-
const pyFilePath = (0, pathUtils_1.combinePaths)(fileDirectory, fileNameWithoutExtension + '.py');
|
986
|
-
const pyiFilePath = (0, pathUtils_1.combinePaths)(fileDirectory, fileNameWithoutExtension + '.pyi');
|
963
|
+
const pyFilePath = dirPath.packageUri;
|
964
|
+
const pyiFilePath = dirPath.packageStubUri;
|
965
|
+
const fileDirectory = dirPath.getDirectory();
|
987
966
|
if (allowPyi && this.fileExistsCached(pyiFilePath)) {
|
988
967
|
importFailureInfo.push(`Resolved import with file '${pyiFilePath}'`);
|
989
968
|
resolvedPaths.push(pyiFilePath);
|
@@ -998,16 +977,16 @@ class ImportResolver {
|
|
998
977
|
else {
|
999
978
|
if (allowNativeLib && this.dirExistsCached(fileDirectory)) {
|
1000
979
|
const filesInDir = this._getFilesInDirectory(fileDirectory);
|
1001
|
-
const
|
1002
|
-
|
1003
|
-
|
980
|
+
const dirName = dirPath.fileName;
|
981
|
+
const nativeLibPath = filesInDir.find((f) => this._isNativeModuleFileName(dirName, f));
|
982
|
+
if (nativeLibPath) {
|
1004
983
|
// Try resolving native library to a custom stub.
|
1005
984
|
isNativeLib = this._resolveNativeModuleStub(nativeLibPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths);
|
1006
985
|
}
|
1007
986
|
}
|
1008
987
|
if (!isNativeLib && foundDirectory) {
|
1009
988
|
importFailureInfo.push(`Partially resolved import with directory '${dirPath}'`);
|
1010
|
-
resolvedPaths.push(
|
989
|
+
resolvedPaths.push(uri_1.Uri.empty());
|
1011
990
|
if (isLastPart) {
|
1012
991
|
implicitImports = this._findImplicitImports(importName, dirPath, [pyFilePath, pyiFilePath]);
|
1013
992
|
isNamespacePackage = true;
|
@@ -1018,9 +997,7 @@ class ImportResolver {
|
|
1018
997
|
}
|
1019
998
|
}
|
1020
999
|
if (!pyTypedInfo && lookForPyTyped) {
|
1021
|
-
|
1022
|
-
pyTypedInfo = (0, pyTypedUtils_1.getPyTypedInfo)(this.fileSystem, fileDirectory);
|
1023
|
-
}
|
1000
|
+
pyTypedInfo = this._getPyTypedInfo(fileDirectory);
|
1024
1001
|
}
|
1025
1002
|
break;
|
1026
1003
|
}
|
@@ -1043,7 +1020,7 @@ class ImportResolver {
|
|
1043
1020
|
isPartlyResolved,
|
1044
1021
|
importFailureInfo,
|
1045
1022
|
importType: 2 /* ImportType.Local */,
|
1046
|
-
resolvedPaths,
|
1023
|
+
resolvedUris: resolvedPaths,
|
1047
1024
|
searchPath: rootPath,
|
1048
1025
|
isStubFile,
|
1049
1026
|
isNativeLib,
|
@@ -1053,17 +1030,19 @@ class ImportResolver {
|
|
1053
1030
|
packageDirectory,
|
1054
1031
|
};
|
1055
1032
|
}
|
1056
|
-
_getImportCacheKey(
|
1057
|
-
|
1033
|
+
_getImportCacheKey(sourceFileUri, importName, fromUserFile) {
|
1034
|
+
var _a;
|
1035
|
+
return `${(_a = sourceFileUri === null || sourceFileUri === void 0 ? void 0 : sourceFileUri.key) !== null && _a !== void 0 ? _a : ''}-${importName}-${fromUserFile}`;
|
1058
1036
|
}
|
1059
|
-
_lookUpResultsInCache(
|
1060
|
-
|
1037
|
+
_lookUpResultsInCache(sourceFileUri, execEnv, importName, moduleDescriptor, fromUserFile) {
|
1038
|
+
var _a, _b;
|
1039
|
+
const cacheForExecEnv = this._cachedImportResults.get((_b = (_a = execEnv.root) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : '');
|
1061
1040
|
if (!cacheForExecEnv) {
|
1062
1041
|
return undefined;
|
1063
1042
|
}
|
1064
1043
|
// If the import is relative, include the source file path in the key.
|
1065
|
-
const
|
1066
|
-
const cachedEntry = cacheForExecEnv.get(this._getImportCacheKey(
|
1044
|
+
const relativeSourceFileUri = moduleDescriptor.leadingDots > 0 ? sourceFileUri : undefined;
|
1045
|
+
const cachedEntry = cacheForExecEnv.get(this._getImportCacheKey(relativeSourceFileUri, importName, fromUserFile));
|
1067
1046
|
if (!cachedEntry) {
|
1068
1047
|
return undefined;
|
1069
1048
|
}
|
@@ -1085,13 +1064,13 @@ class ImportResolver {
|
|
1085
1064
|
}
|
1086
1065
|
return true;
|
1087
1066
|
}
|
1088
|
-
_resolveBestAbsoluteImport(
|
1067
|
+
_resolveBestAbsoluteImport(sourceFileUri, execEnv, moduleDescriptor, allowPyi) {
|
1089
1068
|
const importName = this.formatImportName(moduleDescriptor);
|
1090
1069
|
const importFailureInfo = [];
|
1091
1070
|
// Check for a local stub file using stubPath.
|
1092
1071
|
if (allowPyi && this._configOptions.stubPath) {
|
1093
1072
|
importFailureInfo.push(`Looking in stubPath '${this._configOptions.stubPath}'`);
|
1094
|
-
const typingsImport = this.resolveAbsoluteImport(
|
1073
|
+
const typingsImport = this.resolveAbsoluteImport(sourceFileUri, this._configOptions.stubPath, execEnv, moduleDescriptor, importName, importFailureInfo,
|
1095
1074
|
/* allowPartial */ undefined,
|
1096
1075
|
/* allowNativeLib */ false,
|
1097
1076
|
/* useStubPackage */ true, allowPyi,
|
@@ -1104,7 +1083,7 @@ class ImportResolver {
|
|
1104
1083
|
// the imported symbols are present in the implicit imports. If not, we'll
|
1105
1084
|
// skip the typings import and continue searching.
|
1106
1085
|
if (typingsImport.isNamespacePackage &&
|
1107
|
-
!typingsImport.
|
1086
|
+
!typingsImport.resolvedUris[typingsImport.resolvedUris.length - 1]) {
|
1108
1087
|
if (this._isNamespacePackageResolved(moduleDescriptor, typingsImport.implicitImports)) {
|
1109
1088
|
return typingsImport;
|
1110
1089
|
}
|
@@ -1119,7 +1098,7 @@ class ImportResolver {
|
|
1119
1098
|
// Look for it in the root directory of the execution environment.
|
1120
1099
|
if (execEnv.root) {
|
1121
1100
|
importFailureInfo.push(`Looking in root directory of execution environment ` + `'${execEnv.root}'`);
|
1122
|
-
localImport = this.resolveAbsoluteImport(
|
1101
|
+
localImport = this.resolveAbsoluteImport(sourceFileUri, execEnv.root, execEnv, moduleDescriptor, importName, importFailureInfo,
|
1123
1102
|
/* allowPartial */ undefined,
|
1124
1103
|
/* allowNativeLib */ true,
|
1125
1104
|
/* useStubPackage */ true, allowPyi,
|
@@ -1128,7 +1107,7 @@ class ImportResolver {
|
|
1128
1107
|
}
|
1129
1108
|
for (const extraPath of execEnv.extraPaths) {
|
1130
1109
|
importFailureInfo.push(`Looking in extraPath '${extraPath}'`);
|
1131
|
-
localImport = this.resolveAbsoluteImport(
|
1110
|
+
localImport = this.resolveAbsoluteImport(sourceFileUri, extraPath, execEnv, moduleDescriptor, importName, importFailureInfo,
|
1132
1111
|
/* allowPartial */ undefined,
|
1133
1112
|
/* allowNativeLib */ true,
|
1134
1113
|
/* useStubPackage */ true, allowPyi,
|
@@ -1140,7 +1119,7 @@ class ImportResolver {
|
|
1140
1119
|
if (pythonSearchPaths.length > 0) {
|
1141
1120
|
for (const searchPath of pythonSearchPaths) {
|
1142
1121
|
importFailureInfo.push(`Looking in python search path '${searchPath}'`);
|
1143
|
-
const thirdPartyImport = this.resolveAbsoluteImport(
|
1122
|
+
const thirdPartyImport = this.resolveAbsoluteImport(sourceFileUri, searchPath, execEnv, moduleDescriptor, importName, importFailureInfo,
|
1144
1123
|
/* allowPartial */ allowPartialResolutionForThirdPartyPackages,
|
1145
1124
|
/* allowNativeLib */ true,
|
1146
1125
|
/* useStubPackage */ true, allowPyi,
|
@@ -1163,7 +1142,7 @@ class ImportResolver {
|
|
1163
1142
|
}
|
1164
1143
|
}
|
1165
1144
|
// Call the extensibility hook for subclasses.
|
1166
|
-
const extraResults = this.resolveImportEx(
|
1145
|
+
const extraResults = this.resolveImportEx(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo, allowPyi);
|
1167
1146
|
if (extraResults) {
|
1168
1147
|
return extraResults;
|
1169
1148
|
}
|
@@ -1198,8 +1177,8 @@ class ImportResolver {
|
|
1198
1177
|
}
|
1199
1178
|
if (newImport.isImportFound) {
|
1200
1179
|
// Prefer traditional packages over namespace packages.
|
1201
|
-
const soFarIndex = bestImportSoFar.
|
1202
|
-
const newIndex = newImport.
|
1180
|
+
const soFarIndex = bestImportSoFar.resolvedUris.findIndex((path) => !path.isEmpty());
|
1181
|
+
const newIndex = newImport.resolvedUris.findIndex((path) => !path.isEmpty());
|
1203
1182
|
if (soFarIndex !== newIndex) {
|
1204
1183
|
if (soFarIndex < 0) {
|
1205
1184
|
return newImport;
|
@@ -1253,7 +1232,7 @@ class ImportResolver {
|
|
1253
1232
|
return newImport;
|
1254
1233
|
}
|
1255
1234
|
// All else equal, prefer shorter resolution paths.
|
1256
|
-
if (bestImportSoFar.
|
1235
|
+
if (bestImportSoFar.resolvedUris.length > newImport.resolvedUris.length) {
|
1257
1236
|
return newImport;
|
1258
1237
|
}
|
1259
1238
|
}
|
@@ -1267,8 +1246,8 @@ class ImportResolver {
|
|
1267
1246
|
// bestSoFar: a/~b/~c/~d new: a Result: bestSoFar wins
|
1268
1247
|
// bestSoFar: ~a/~b/~c/~d new: a Result: new wins
|
1269
1248
|
// bestSoFar: a/~b/~c/~d new: a/b Result: new wins
|
1270
|
-
const soFarIndex = bestImportSoFar.
|
1271
|
-
const newIndex = newImport.
|
1249
|
+
const soFarIndex = bestImportSoFar.resolvedUris.findIndex((path) => !path.isEmpty());
|
1250
|
+
const newIndex = newImport.resolvedUris.findIndex((path) => !path.isEmpty());
|
1272
1251
|
if (soFarIndex !== newIndex) {
|
1273
1252
|
if (soFarIndex < 0) {
|
1274
1253
|
return newImport;
|
@@ -1322,7 +1301,7 @@ class ImportResolver {
|
|
1322
1301
|
const readDir = (root, prefix) => {
|
1323
1302
|
this.readdirEntriesCached(root).forEach((entry) => {
|
1324
1303
|
if (entry.isDirectory()) {
|
1325
|
-
const dirRoot =
|
1304
|
+
const dirRoot = root.combinePaths(entry.name);
|
1326
1305
|
readDir(dirRoot, prefix ? `${prefix}.${entry.name}` : entry.name);
|
1327
1306
|
}
|
1328
1307
|
else if (entry.name.includes('.py')) {
|
@@ -1348,7 +1327,7 @@ class ImportResolver {
|
|
1348
1327
|
if (thirdPartyDir) {
|
1349
1328
|
this.readdirEntriesCached(thirdPartyDir).forEach((outerEntry) => {
|
1350
1329
|
if (outerEntry.isDirectory()) {
|
1351
|
-
const innerDirPath =
|
1330
|
+
const innerDirPath = thirdPartyDir.combinePaths(outerEntry.name);
|
1352
1331
|
this.readdirEntriesCached(innerDirPath).forEach((innerEntry) => {
|
1353
1332
|
if (innerEntry.name === '@python2') {
|
1354
1333
|
return;
|
@@ -1381,7 +1360,7 @@ class ImportResolver {
|
|
1381
1360
|
const flattenPaths = Array.from(this._cachedTypeshedThirdPartyPackagePaths.values()).flatMap((v) => v);
|
1382
1361
|
this._cachedTypeshedThirdPartyPackageRoots = Array.from(new Set(flattenPaths)).sort();
|
1383
1362
|
}
|
1384
|
-
_getCompletionSuggestionsTypeshedPath(
|
1363
|
+
_getCompletionSuggestionsTypeshedPath(sourceFileUri, execEnv, moduleDescriptor, isStdLib, suggestions) {
|
1385
1364
|
const importFailureInfo = [];
|
1386
1365
|
let typeshedPaths;
|
1387
1366
|
if (isStdLib) {
|
@@ -1404,7 +1383,7 @@ class ImportResolver {
|
|
1404
1383
|
}
|
1405
1384
|
typeshedPaths.forEach((typeshedPath) => {
|
1406
1385
|
if (this.dirExistsCached(typeshedPath)) {
|
1407
|
-
this._getCompletionSuggestionsAbsolute(
|
1386
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, typeshedPath, moduleDescriptor, suggestions);
|
1408
1387
|
}
|
1409
1388
|
});
|
1410
1389
|
}
|
@@ -1449,7 +1428,7 @@ class ImportResolver {
|
|
1449
1428
|
const typeshedStdLibPath = this._getTypeshedSubdirectory(
|
1450
1429
|
/* isStdLib */ true, customTypeshedPath, importFailureInfo);
|
1451
1430
|
if (typeshedStdLibPath) {
|
1452
|
-
const versionsFilePath =
|
1431
|
+
const versionsFilePath = typeshedStdLibPath.combinePaths('VERSIONS');
|
1453
1432
|
try {
|
1454
1433
|
const fileStats = this.fileSystem.statSync(versionsFilePath);
|
1455
1434
|
if (fileStats.size > 0 && fileStats.size < 256 * 1024) {
|
@@ -1516,10 +1495,11 @@ class ImportResolver {
|
|
1516
1495
|
return this._cachedTypeshedThirdPartyPackageRoots;
|
1517
1496
|
}
|
1518
1497
|
_getTypeshedRoot(customTypeshedPath, importFailureInfo) {
|
1498
|
+
var _a;
|
1519
1499
|
if (this._cachedTypeshedRoot !== undefined) {
|
1520
1500
|
return this._cachedTypeshedRoot;
|
1521
1501
|
}
|
1522
|
-
let typeshedPath =
|
1502
|
+
let typeshedPath = undefined;
|
1523
1503
|
// Did the user specify a typeshed path? If not, we'll look in the
|
1524
1504
|
// python search paths, then in the typeshed-fallback directory.
|
1525
1505
|
if (customTypeshedPath) {
|
@@ -1529,7 +1509,7 @@ class ImportResolver {
|
|
1529
1509
|
}
|
1530
1510
|
// If typeshed directory wasn't found in other locations, use the fallback.
|
1531
1511
|
if (!typeshedPath) {
|
1532
|
-
typeshedPath = PythonPathUtils.getTypeShedFallbackPath(this.fileSystem)
|
1512
|
+
typeshedPath = (_a = PythonPathUtils.getTypeShedFallbackPath(this.fileSystem)) !== null && _a !== void 0 ? _a : uri_1.Uri.empty();
|
1533
1513
|
}
|
1534
1514
|
this._cachedTypeshedRoot = typeshedPath;
|
1535
1515
|
return typeshedPath;
|
@@ -1560,23 +1540,23 @@ class ImportResolver {
|
|
1560
1540
|
}
|
1561
1541
|
return typeshedPath;
|
1562
1542
|
}
|
1563
|
-
_resolveRelativeImport(
|
1543
|
+
_resolveRelativeImport(sourceFileUri, execEnv, moduleDescriptor, importName, importFailureInfo) {
|
1564
1544
|
importFailureInfo.push('Attempting to resolve relative import');
|
1565
1545
|
// Determine which search path this file is part of.
|
1566
|
-
const directory = (0, importStatementUtils_1.getDirectoryLeadingDotsPointsTo)(
|
1546
|
+
const directory = (0, importStatementUtils_1.getDirectoryLeadingDotsPointsTo)(sourceFileUri.getDirectory(), moduleDescriptor.leadingDots);
|
1567
1547
|
if (!directory) {
|
1568
1548
|
importFailureInfo.push(`Invalid relative path '${importName}'`);
|
1569
1549
|
return undefined;
|
1570
1550
|
}
|
1571
1551
|
// Now try to match the module parts from the current directory location.
|
1572
|
-
const absImport = this.resolveAbsoluteImport(
|
1552
|
+
const absImport = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importFailureInfo,
|
1573
1553
|
/* allowPartial */ false,
|
1574
1554
|
/* allowNativeLib */ true);
|
1575
1555
|
if (absImport && absImport.isStubFile) {
|
1576
1556
|
// If we found a stub for a relative import, only search
|
1577
1557
|
// the same folder for the real module. Otherwise, it will
|
1578
1558
|
// error out on runtime.
|
1579
|
-
absImport.nonStubImportResult = this.resolveAbsoluteImport(
|
1559
|
+
absImport.nonStubImportResult = this.resolveAbsoluteImport(sourceFileUri, directory, execEnv, moduleDescriptor, importName, importFailureInfo,
|
1580
1560
|
/* allowPartial */ false,
|
1581
1561
|
/* allowNativeLib */ true,
|
1582
1562
|
/* useStubPackage */ false,
|
@@ -1588,7 +1568,7 @@ class ImportResolver {
|
|
1588
1568
|
isNamespacePackage: false,
|
1589
1569
|
isStubPackage: false,
|
1590
1570
|
importFailureInfo,
|
1591
|
-
|
1571
|
+
resolvedUris: [],
|
1592
1572
|
importType: 2 /* ImportType.Local */,
|
1593
1573
|
isStubFile: false,
|
1594
1574
|
isNativeLib: false,
|
@@ -1599,29 +1579,40 @@ class ImportResolver {
|
|
1599
1579
|
}
|
1600
1580
|
return absImport;
|
1601
1581
|
}
|
1602
|
-
_getCompletionSuggestionsRelative(
|
1582
|
+
_getCompletionSuggestionsRelative(sourceFileUri, execEnv, moduleDescriptor, suggestions) {
|
1603
1583
|
// Determine which search path this file is part of.
|
1604
|
-
const directory = (0, importStatementUtils_1.getDirectoryLeadingDotsPointsTo)(
|
1584
|
+
const directory = (0, importStatementUtils_1.getDirectoryLeadingDotsPointsTo)(sourceFileUri.getDirectory(), moduleDescriptor.leadingDots);
|
1605
1585
|
if (!directory) {
|
1606
1586
|
return;
|
1607
1587
|
}
|
1608
1588
|
// Now try to match the module parts from the current directory location.
|
1609
|
-
this._getCompletionSuggestionsAbsolute(
|
1589
|
+
this._getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, directory, moduleDescriptor, suggestions);
|
1610
1590
|
}
|
1611
1591
|
_getFilesInDirectory(dirPath) {
|
1612
|
-
const
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1592
|
+
const cachedValue = this._cachedFilesForPath.get(dirPath.key);
|
1593
|
+
if (cachedValue) {
|
1594
|
+
return cachedValue;
|
1595
|
+
}
|
1596
|
+
let newCacheValue = [];
|
1597
|
+
try {
|
1598
|
+
const entriesInDir = this.readdirEntriesCached(dirPath);
|
1599
|
+
const filesInDir = entriesInDir.filter((f) => f.isFile());
|
1600
|
+
// Add any symbolic links that point to files.
|
1601
|
+
entriesInDir.forEach((f) => {
|
1602
|
+
var _a;
|
1603
|
+
if (f.isSymbolicLink() && ((_a = (0, uriUtils_1.tryStat)(this.fileSystem, dirPath.combinePaths(f.name))) === null || _a === void 0 ? void 0 : _a.isFile())) {
|
1604
|
+
filesInDir.push(f);
|
1605
|
+
}
|
1606
|
+
});
|
1607
|
+
newCacheValue = filesInDir.map((f) => dirPath.combinePaths(f.name));
|
1608
|
+
}
|
1609
|
+
catch {
|
1610
|
+
newCacheValue = [];
|
1611
|
+
}
|
1612
|
+
this._cachedFilesForPath.set(dirPath.key, newCacheValue);
|
1613
|
+
return newCacheValue;
|
1623
1614
|
}
|
1624
|
-
_getCompletionSuggestionsAbsolute(
|
1615
|
+
_getCompletionSuggestionsAbsolute(sourceFileUri, execEnv, rootPath, moduleDescriptor, suggestions, strictOnly = true) {
|
1625
1616
|
// Starting at the specified path, walk the file system to find the
|
1626
1617
|
// specified module.
|
1627
1618
|
let dirPath = rootPath;
|
@@ -1638,29 +1629,29 @@ class ImportResolver {
|
|
1638
1629
|
// Handle the case where the user has typed the first
|
1639
1630
|
// dot (or multiple) in a relative path.
|
1640
1631
|
if (nameParts.length === 0) {
|
1641
|
-
this._addFilteredSuggestionsAbsolute(
|
1632
|
+
this._addFilteredSuggestionsAbsolute(sourceFileUri, execEnv, dirPath, '', suggestions, leadingDots, parentNameParts, strictOnly);
|
1642
1633
|
}
|
1643
1634
|
else {
|
1644
1635
|
for (let i = 0; i < nameParts.length; i++) {
|
1645
1636
|
// Provide completions only if we're on the last part
|
1646
1637
|
// of the name.
|
1647
1638
|
if (i === nameParts.length - 1) {
|
1648
|
-
this._addFilteredSuggestionsAbsolute(
|
1639
|
+
this._addFilteredSuggestionsAbsolute(sourceFileUri, execEnv, dirPath, nameParts[i], suggestions, leadingDots, parentNameParts, strictOnly);
|
1649
1640
|
}
|
1650
|
-
dirPath =
|
1641
|
+
dirPath = dirPath.combinePaths(nameParts[i]);
|
1651
1642
|
if (!this.dirExistsCached(dirPath)) {
|
1652
1643
|
break;
|
1653
1644
|
}
|
1654
1645
|
}
|
1655
1646
|
}
|
1656
1647
|
}
|
1657
|
-
_addFilteredSuggestionsAbsolute(
|
1648
|
+
_addFilteredSuggestionsAbsolute(sourceFileUri, execEnv, currentPath, filter, suggestions, leadingDots, parentNameParts, strictOnly) {
|
1658
1649
|
// Enumerate all of the files and directories in the path, expanding links.
|
1659
|
-
const entries = (0,
|
1650
|
+
const entries = (0, uriUtils_1.getFileSystemEntriesFromDirEntries)(this.readdirEntriesCached(currentPath), this.fileSystem, currentPath);
|
1660
1651
|
entries.files.forEach((file) => {
|
1661
1652
|
// Strip multi-dot extensions to handle file names like "foo.cpython-32m.so". We want
|
1662
1653
|
// to detect the ".so" but strip off the entire ".cpython-32m.so" extension.
|
1663
|
-
const fileWithoutExtension =
|
1654
|
+
const fileWithoutExtension = file.stripAllExtensions().fileName;
|
1664
1655
|
if (ImportResolver.isSupportedImportFile(file)) {
|
1665
1656
|
if (fileWithoutExtension === '__init__') {
|
1666
1657
|
return;
|
@@ -1669,38 +1660,39 @@ class ImportResolver {
|
|
1669
1660
|
return;
|
1670
1661
|
}
|
1671
1662
|
if (!this._isUniqueValidSuggestion(fileWithoutExtension, suggestions) ||
|
1672
|
-
!this._isResolvableSuggestion(fileWithoutExtension, leadingDots, parentNameParts,
|
1663
|
+
!this._isResolvableSuggestion(fileWithoutExtension, leadingDots, parentNameParts, sourceFileUri, execEnv, strictOnly)) {
|
1673
1664
|
return;
|
1674
1665
|
}
|
1675
|
-
suggestions.set(fileWithoutExtension,
|
1666
|
+
suggestions.set(fileWithoutExtension, file);
|
1676
1667
|
}
|
1677
1668
|
});
|
1678
1669
|
entries.directories.forEach((dir) => {
|
1679
|
-
|
1670
|
+
const dirSuggestion = dir.fileName;
|
1671
|
+
if (filter && !dirSuggestion.startsWith(filter)) {
|
1680
1672
|
return;
|
1681
1673
|
}
|
1682
|
-
if (!this._isUniqueValidSuggestion(
|
1683
|
-
!this._isResolvableSuggestion(
|
1674
|
+
if (!this._isUniqueValidSuggestion(dirSuggestion, suggestions) ||
|
1675
|
+
!this._isResolvableSuggestion(dirSuggestion, leadingDots, parentNameParts, sourceFileUri, execEnv, strictOnly)) {
|
1684
1676
|
return;
|
1685
1677
|
}
|
1686
|
-
const initPyiPath =
|
1678
|
+
const initPyiPath = dir.initPyiUri;
|
1687
1679
|
if (this.fileExistsCached(initPyiPath)) {
|
1688
|
-
suggestions.set(
|
1680
|
+
suggestions.set(dirSuggestion, initPyiPath);
|
1689
1681
|
return;
|
1690
1682
|
}
|
1691
|
-
const initPyPath =
|
1683
|
+
const initPyPath = dir.initPyUri;
|
1692
1684
|
if (this.fileExistsCached(initPyPath)) {
|
1693
|
-
suggestions.set(
|
1685
|
+
suggestions.set(dirSuggestion, initPyPath);
|
1694
1686
|
return;
|
1695
1687
|
}
|
1696
1688
|
// It is a namespace package. there is no corresponding module path.
|
1697
|
-
suggestions.set(
|
1689
|
+
suggestions.set(dirSuggestion, uri_1.Uri.empty());
|
1698
1690
|
});
|
1699
1691
|
}
|
1700
1692
|
// Fix for editable installed submodules where the suggested directory was a namespace directory that wouldn't resolve.
|
1701
1693
|
// only used for absolute imports
|
1702
|
-
_isResolvableSuggestion(name, leadingDots, parentNameParts,
|
1703
|
-
// We always resolve names based on
|
1694
|
+
_isResolvableSuggestion(name, leadingDots, parentNameParts, sourceFileUri, execEnv, strictOnly) {
|
1695
|
+
// We always resolve names based on sourceFileUri.
|
1704
1696
|
const moduleDescriptor = {
|
1705
1697
|
leadingDots: leadingDots,
|
1706
1698
|
nameParts: [...parentNameParts, name],
|
@@ -1711,10 +1703,10 @@ class ImportResolver {
|
|
1711
1703
|
if (strictOnly) {
|
1712
1704
|
const importName = this.formatImportName(moduleDescriptor);
|
1713
1705
|
const importFailureInfo = [];
|
1714
|
-
importResult = this._resolveImportStrict(importName,
|
1706
|
+
importResult = this._resolveImportStrict(importName, sourceFileUri, execEnv, moduleDescriptor, importFailureInfo);
|
1715
1707
|
}
|
1716
1708
|
else {
|
1717
|
-
importResult = this.resolveImportInternal(
|
1709
|
+
importResult = this.resolveImportInternal(sourceFileUri, execEnv, moduleDescriptor);
|
1718
1710
|
}
|
1719
1711
|
if (importResult && importResult.isImportFound) {
|
1720
1712
|
// Check the import isn't for a private or protected module. If it is, then
|
@@ -1742,42 +1734,41 @@ class ImportResolver {
|
|
1742
1734
|
_findImplicitImports(importingModuleName, dirPath, exclusions) {
|
1743
1735
|
const implicitImportMap = new Map();
|
1744
1736
|
// Enumerate all of the files and directories in the path, expanding links.
|
1745
|
-
const entries = (0,
|
1737
|
+
const entries = (0, uriUtils_1.getFileSystemEntriesFromDirEntries)(this.readdirEntriesCached(dirPath), this.fileSystem, dirPath);
|
1746
1738
|
// Add implicit file-based modules.
|
1747
|
-
for (const
|
1748
|
-
const fileExt =
|
1739
|
+
for (const filePath of entries.files) {
|
1740
|
+
const fileExt = filePath.lastExtension;
|
1749
1741
|
let strippedFileName;
|
1750
1742
|
let isNativeLib = false;
|
1751
1743
|
if (fileExt === '.py' || fileExt === '.pyi') {
|
1752
|
-
strippedFileName = (0, pathUtils_1.stripFileExtension)(fileName);
|
1744
|
+
strippedFileName = (0, pathUtils_1.stripFileExtension)(filePath.fileName);
|
1753
1745
|
}
|
1754
1746
|
else if (this._isNativeModuleFileExtension(fileExt) &&
|
1755
|
-
!this.fileExistsCached(
|
1756
|
-
!this.fileExistsCached(
|
1747
|
+
!this.fileExistsCached(filePath.packageUri) &&
|
1748
|
+
!this.fileExistsCached(filePath.packageStubUri)) {
|
1757
1749
|
// Native module.
|
1758
|
-
strippedFileName =
|
1750
|
+
strippedFileName = filePath.stripAllExtensions().fileName;
|
1759
1751
|
isNativeLib = true;
|
1760
1752
|
}
|
1761
1753
|
else {
|
1762
1754
|
continue;
|
1763
1755
|
}
|
1764
|
-
|
1765
|
-
if (!exclusions.find((exclusion) => exclusion === filePath)) {
|
1756
|
+
if (!exclusions.find((exclusion) => exclusion.equals(filePath))) {
|
1766
1757
|
const implicitImport = {
|
1767
|
-
isStubFile:
|
1758
|
+
isStubFile: filePath.hasExtension('.pyi'),
|
1768
1759
|
isNativeLib,
|
1769
1760
|
name: strippedFileName,
|
1770
|
-
|
1761
|
+
uri: filePath,
|
1771
1762
|
};
|
1772
1763
|
// Always prefer stub files over non-stub files.
|
1773
1764
|
const entry = implicitImportMap.get(implicitImport.name);
|
1774
1765
|
if (!entry || !entry.isStubFile) {
|
1775
1766
|
// Try resolving resolving native lib to a custom stub.
|
1776
1767
|
if (isNativeLib) {
|
1777
|
-
const nativeLibPath =
|
1768
|
+
const nativeLibPath = filePath;
|
1778
1769
|
const nativeStubPath = this.resolveNativeImportEx(nativeLibPath, `${importingModuleName}.${strippedFileName}`, []);
|
1779
1770
|
if (nativeStubPath) {
|
1780
|
-
implicitImport.
|
1771
|
+
implicitImport.uri = nativeStubPath;
|
1781
1772
|
implicitImport.isNativeLib = false;
|
1782
1773
|
}
|
1783
1774
|
}
|
@@ -1786,11 +1777,11 @@ class ImportResolver {
|
|
1786
1777
|
}
|
1787
1778
|
}
|
1788
1779
|
// Add implicit directory-based modules.
|
1789
|
-
for (const
|
1790
|
-
const pyFilePath =
|
1791
|
-
const pyiFilePath =
|
1780
|
+
for (const dirPath of entries.directories) {
|
1781
|
+
const pyFilePath = dirPath.initPyUri;
|
1782
|
+
const pyiFilePath = dirPath.initPyiUri;
|
1792
1783
|
let isStubFile = false;
|
1793
|
-
let path
|
1784
|
+
let path;
|
1794
1785
|
if (this.fileExistsCached(pyiFilePath)) {
|
1795
1786
|
isStubFile = true;
|
1796
1787
|
path = pyiFilePath;
|
@@ -1799,13 +1790,13 @@ class ImportResolver {
|
|
1799
1790
|
path = pyFilePath;
|
1800
1791
|
}
|
1801
1792
|
if (path) {
|
1802
|
-
if (!exclusions.find((exclusion) => exclusion
|
1793
|
+
if (!exclusions.find((exclusion) => exclusion.equals(path))) {
|
1803
1794
|
const implicitImport = {
|
1804
1795
|
isStubFile,
|
1805
1796
|
isNativeLib: false,
|
1806
|
-
name:
|
1807
|
-
path,
|
1808
|
-
pyTypedInfo:
|
1797
|
+
name: dirPath.fileName,
|
1798
|
+
uri: path,
|
1799
|
+
pyTypedInfo: this._getPyTypedInfo(dirPath),
|
1809
1800
|
};
|
1810
1801
|
implicitImportMap.set(implicitImport.name, implicitImport);
|
1811
1802
|
}
|
@@ -1813,6 +1804,14 @@ class ImportResolver {
|
|
1813
1804
|
}
|
1814
1805
|
return implicitImportMap;
|
1815
1806
|
}
|
1807
|
+
// Retrieves the pytyped info for a directory if it exists. This is a small perf optimization
|
1808
|
+
// that allows skipping the search when the pytyped file doesn't exist.
|
1809
|
+
_getPyTypedInfo(filePath) {
|
1810
|
+
if (!this.fileExistsCached(filePath.pytypedUri)) {
|
1811
|
+
return undefined;
|
1812
|
+
}
|
1813
|
+
return (0, pyTypedUtils_1.getPyTypedInfo)(this.fileSystem, filePath);
|
1814
|
+
}
|
1816
1815
|
_resolveNativeModuleStub(nativeLibPath, execEnv, importName, moduleDescriptor, importFailureInfo, resolvedPaths) {
|
1817
1816
|
let moduleFullName = importName;
|
1818
1817
|
if (moduleDescriptor.leadingDots > 0) {
|
@@ -1830,12 +1829,12 @@ class ImportResolver {
|
|
1830
1829
|
resolvedPaths.push(nativeLibPath);
|
1831
1830
|
return true;
|
1832
1831
|
}
|
1833
|
-
_isNativeModuleFileName(moduleName,
|
1832
|
+
_isNativeModuleFileName(moduleName, fileUri) {
|
1834
1833
|
// Strip off the final file extension and the part of the file name
|
1835
1834
|
// that excludes all (multi-part) file extensions. This allows us to
|
1836
1835
|
// handle file names like "foo.cpython-32m.so".
|
1837
|
-
const fileExtension =
|
1838
|
-
const withoutExtension = (0, pathUtils_1.stripFileExtension)(fileName, /* multiDotExtension */ true);
|
1836
|
+
const fileExtension = fileUri.lastExtension.toLowerCase();
|
1837
|
+
const withoutExtension = (0, pathUtils_1.stripFileExtension)(fileUri.fileName, /* multiDotExtension */ true);
|
1839
1838
|
return (this._isNativeModuleFileExtension(fileExtension) &&
|
1840
1839
|
(0, stringUtils_1.equateStringsCaseInsensitive)(moduleName, withoutExtension));
|
1841
1840
|
}
|
@@ -1843,18 +1842,18 @@ class ImportResolver {
|
|
1843
1842
|
return supportedNativeLibExtensions.some((ext) => ext === fileExtension);
|
1844
1843
|
}
|
1845
1844
|
_tryWalkUp(current) {
|
1846
|
-
if ((
|
1847
|
-
return
|
1845
|
+
if (!current || current.isEmpty() || current.isRoot()) {
|
1846
|
+
return undefined;
|
1848
1847
|
}
|
1849
|
-
// Ensure we don't go around forever even if
|
1850
|
-
const next =
|
1851
|
-
if (next
|
1852
|
-
return
|
1848
|
+
// Ensure we don't go around forever even if isRoot returns false.
|
1849
|
+
const next = current.combinePaths('..');
|
1850
|
+
if (next.equals(current)) {
|
1851
|
+
return undefined;
|
1853
1852
|
}
|
1854
|
-
return
|
1853
|
+
return next;
|
1855
1854
|
}
|
1856
1855
|
_shouldWalkUp(current, root, execEnv) {
|
1857
|
-
return current
|
1856
|
+
return current && (current.isChild(root) || (current.equals(root) && !execEnv.root));
|
1858
1857
|
}
|
1859
1858
|
}
|
1860
1859
|
exports.ImportResolver = ImportResolver;
|