Skip to content

Commit

Permalink
addressed PR feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
heejaechang committed Feb 13, 2020
1 parent fd3f962 commit bd914d1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions server/src/analyzer/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
16 changes: 8 additions & 8 deletions server/src/analyzer/pythonPathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +23,7 @@ export function getTypeShedFallbackPath(moduleDirectory?: string) {
moduleDirectory = normalizePath(moduleDirectory);
return combinePaths(getDirectoryPath(
ensureTrailingDirectorySeparator(moduleDirectory)),
consts.TYPESHED_FALLBACK);
consts.typeshedFallback);
}

return undefined;
Expand All @@ -50,22 +50,22 @@ 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 = '';
}
}

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];
Expand All @@ -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];
Expand All @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions server/src/common/consts.ts

This file was deleted.

11 changes: 11 additions & 0 deletions server/src/common/pathConsts.ts
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 2 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions server/src/tests/harness/vfs/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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');

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ let localCSFSCache: FileSystem | undefined;
function getBuiltLocal(host: TestHost, ignoreCase: boolean, mountPaths: Map<string, string>): 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)) {
Expand Down

0 comments on commit bd914d1

Please sign in to comment.