diff --git a/server/src/analyzer/program.ts b/server/src/analyzer/program.ts index c8893115f0d5..ebc7e3760639 100644 --- a/server/src/analyzer/program.ts +++ b/server/src/analyzer/program.ts @@ -7,6 +7,7 @@ * An object that tracks all of the source files being analyzed * and all of their recursive imports. */ + import * as assert from 'assert'; import { CompletionItem, CompletionList, DocumentSymbol, SymbolInformation } from 'vscode-languageserver'; diff --git a/server/src/analyzer/pythonPathUtils.ts b/server/src/analyzer/pythonPathUtils.ts index d72492545dc4..a67f3b3b71cc 100644 --- a/server/src/analyzer/pythonPathUtils.ts +++ b/server/src/analyzer/pythonPathUtils.ts @@ -9,7 +9,7 @@ import * as child_process from 'child_process'; import { ConfigOptions } from '../common/configOptions'; -import * as consts from '../common/consts'; +import * as consts from '../common/pathConsts'; import { combinePaths, ensureTrailingDirectorySeparator, getDirectoryPath, getFileSystemEntries, isDirectory, normalizePath @@ -23,7 +23,7 @@ export function getTypeShedFallbackPath(moduleDirectory?: string) { moduleDirectory = normalizePath(moduleDirectory); return combinePaths(getDirectoryPath( ensureTrailingDirectorySeparator(moduleDirectory)), - consts.TYPESHED_FALLBACK); + consts.typeshedFallback); } return undefined; @@ -50,14 +50,14 @@ export function findPythonSearchPaths(fs: VirtualFileSystem, configOptions: Conf } if (venvPath) { - let libPath = combinePaths(venvPath, consts.LIB); + let libPath = combinePaths(venvPath, consts.lib); if (fs.existsSync(libPath)) { - importFailureInfo.push(`Found path '${ libPath }'; looking for ${ consts.SITE_PACKAGES }`); + importFailureInfo.push(`Found path '${ libPath }'; looking for ${ consts.sitePackages }`); } else { importFailureInfo.push(`Did not find '${ libPath }'; trying 'Lib' instead`); libPath = combinePaths(venvPath, 'Lib'); if (fs.existsSync(libPath)) { - importFailureInfo.push(`Found path '${ libPath }'; looking for ${ consts.SITE_PACKAGES }`); + importFailureInfo.push(`Found path '${ libPath }'; looking for ${ consts.sitePackages }`); } else { importFailureInfo.push(`Did not find '${ libPath }'`); libPath = ''; @@ -65,7 +65,7 @@ export function findPythonSearchPaths(fs: VirtualFileSystem, configOptions: Conf } if (libPath) { - const sitePackagesPath = combinePaths(libPath, consts.SITE_PACKAGES); + const sitePackagesPath = combinePaths(libPath, consts.sitePackages); if (fs.existsSync(sitePackagesPath)) { importFailureInfo.push(`Found path '${ sitePackagesPath }'`); return [sitePackagesPath]; @@ -79,7 +79,7 @@ export function findPythonSearchPaths(fs: VirtualFileSystem, configOptions: Conf for (let i = 0; i < entries.directories.length; i++) { const dirName = entries.directories[i]; if (dirName.startsWith('python')) { - const dirPath = combinePaths(libPath, dirName, consts.SITE_PACKAGES); + const dirPath = combinePaths(libPath, dirName, consts.sitePackages); if (fs.existsSync(dirPath)) { importFailureInfo.push(`Found path '${ dirPath }'`); return [dirPath]; @@ -90,7 +90,7 @@ export function findPythonSearchPaths(fs: VirtualFileSystem, configOptions: Conf } } - importFailureInfo.push(`Did not find '${ consts.SITE_PACKAGES }'. Falling back on python interpreter.`); + importFailureInfo.push(`Did not find '${ consts.sitePackages }'. Falling back on python interpreter.`); } // Fall back on the python interpreter. diff --git a/server/src/common/consts.ts b/server/src/common/consts.ts deleted file mode 100644 index e7f95092e38d..000000000000 --- a/server/src/common/consts.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * consts.ts - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT license. - * - * Defines well known consts and names - */ - -export const TYPESHED_FALLBACK = 'typeshed-fallback'; -export const LIB = 'lib'; -export const SITE_PACKAGES = 'site-packages'; diff --git a/server/src/common/pathConsts.ts b/server/src/common/pathConsts.ts new file mode 100644 index 000000000000..42b9a0a96443 --- /dev/null +++ b/server/src/common/pathConsts.ts @@ -0,0 +1,11 @@ +/* + * pathConsts.ts + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT license. + * + * Defines well known consts and names + */ + +export const typeshedFallback = 'typeshed-fallback'; +export const lib = 'lib'; +export const sitePackages = 'site-packages'; diff --git a/server/src/server.ts b/server/src/server.ts index 77eed84144f9..50ab01fd7d16 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import { isArray } from 'util'; import { CodeAction, CodeActionParams, Command, ExecuteCommandParams } from 'vscode-languageserver'; import { CommandController } from './commands/commandController'; -import * as consts from './common/consts'; +import * as consts from './common/pathConsts'; import * as debug from './common/debug'; import { convertUriToPath, getDirectoryPath, normalizeSlashes } from './common/pathUtils'; import { LanguageServerBase, ServerSettings, WorkspaceServiceInstance } from './languageServerBase'; @@ -28,7 +28,7 @@ class Server extends LanguageServerBase { // 1. to find "typeshed-fallback" folder. // 2. to set "cwd" to run python to find search path. const rootDirectory = getDirectoryPath(__dirname); - debug.assert(fs.existsSync(path.join(rootDirectory, consts.TYPESHED_FALLBACK)), `Unable to locate typeshed fallback folder at '${ rootDirectory }'`); + debug.assert(fs.existsSync(path.join(rootDirectory, consts.typeshedFallback)), `Unable to locate typeshed fallback folder at '${ rootDirectory }'`); super('Pyright', rootDirectory); this._controller = new CommandController(this); diff --git a/server/src/tests/harness/vfs/factory.ts b/server/src/tests/harness/vfs/factory.ts index 047ccec4aa8c..7fa06b7de71e 100644 --- a/server/src/tests/harness/vfs/factory.ts +++ b/server/src/tests/harness/vfs/factory.ts @@ -6,7 +6,7 @@ * Provides a factory to create virtual file system backed by a real file system with some path remapped */ -import * as consts from '../../../common/consts'; +import * as consts from '../../../common/pathConsts'; import { combinePaths, getDirectoryPath, normalizeSlashes, resolvePaths } from '../../../common/pathUtils'; import { GlobalMetadataOptionNames } from '../fourslash/fourSlashTypes'; import { TestHost } from '../host'; @@ -30,8 +30,8 @@ export interface FileSystemCreateOptions extends FileSystemOptions { documents?: readonly TextDocument[]; } -export const libFolder = combinePaths(MODULE_PATH, normalizeSlashes(combinePaths(consts.LIB, consts.SITE_PACKAGES))); -export const typeshedFolder = combinePaths(MODULE_PATH, normalizeSlashes(consts.TYPESHED_FALLBACK)); +export const libFolder = combinePaths(MODULE_PATH, normalizeSlashes(combinePaths(consts.lib, consts.sitePackages))); +export const typeshedFolder = combinePaths(MODULE_PATH, normalizeSlashes(consts.typeshedFallback)); export const srcFolder = normalizeSlashes('/.src'); /** @@ -100,7 +100,7 @@ let localCSFSCache: FileSystem | undefined; function getBuiltLocal(host: TestHost, ignoreCase: boolean, mountPaths: Map): FileSystem { // Ensure typeshed folder if (!mountPaths.has(typeshedFolder)) { - mountPaths.set(typeshedFolder, resolvePaths(host.getWorkspaceRoot(), '../client/' + consts.TYPESHED_FALLBACK)); + mountPaths.set(typeshedFolder, resolvePaths(host.getWorkspaceRoot(), '../client/' + consts.typeshedFallback)); } if (!canReuseCache(host, mountPaths)) {