Skip to content

Commit

Permalink
Merge pull request microsoft#510 from microsoft/erictr/debugging
Browse files Browse the repository at this point in the history
Fixed debug builds.
  • Loading branch information
erictraut committed Feb 13, 2020
2 parents 2aa319f + f6bb03b commit 04a01c7
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Commands } from '../../server/src/commands/commands';

export function activate(context: ExtensionContext) {
const bundlePath = context.asAbsolutePath(path.join('server', 'server.bundle.js'));
const nonBundlePath = context.asAbsolutePath(path.join('server', 'server.js'));
const nonBundlePath = context.asAbsolutePath(path.join('server', 'src', 'server.js'));
const debugOptions = { execArgv: ["--nolazy", "--inspect=6600"] };

// If the extension is launched in debug mode, then the debug server options are used.
Expand Down
2 changes: 1 addition & 1 deletion server/src/analyzer/importResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ export class ImportResolver {

// If typeshed directory wasn't found in other locations, use the fallback.
if (!typeshedPath) {
typeshedPath = PythonPathUtils.getTypeShedFallbackPath(this.fileSystem.getModulePath()) || '';
typeshedPath = PythonPathUtils.getTypeShedFallbackPath(this.fileSystem) || '';
}

typeshedPath = PythonPathUtils.getTypeshedSubdirectory(typeshedPath, isStdLib);
Expand Down
46 changes: 29 additions & 17 deletions server/src/analyzer/pythonPathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@
*/

import * as child_process from 'child_process';

import { ConfigOptions } from '../common/configOptions';
import * as consts from '../common/pathConsts';
import {
combinePaths, ensureTrailingDirectorySeparator, getDirectoryPath,
getFileSystemEntries, isDirectory, normalizePath
} from '../common/pathUtils';
import * as pathConsts from '../common/pathConsts';
import { combinePaths, ensureTrailingDirectorySeparator, getDirectoryPath,
getFileSystemEntries, isDirectory, normalizePath } from '../common/pathUtils';
import { VirtualFileSystem } from '../common/vfs';

const cachedSearchPaths = new Map<string, string[]>();

export function getTypeShedFallbackPath(moduleDirectory?: string) {
if (moduleDirectory) {
moduleDirectory = normalizePath(moduleDirectory);
return combinePaths(getDirectoryPath(
ensureTrailingDirectorySeparator(moduleDirectory)),
consts.typeshedFallback);
export function getTypeShedFallbackPath(fs: VirtualFileSystem) {
let moduleDirectory = fs.getModulePath();
if (!moduleDirectory) {
return undefined;
}

moduleDirectory = getDirectoryPath(ensureTrailingDirectorySeparator(
normalizePath(moduleDirectory)));

const typeshedPath = combinePaths(moduleDirectory, pathConsts.typeshedFallback);
if (fs.existsSync(typeshedPath)) {
return typeshedPath;
}

// In the debug version of Pyright, the code is one level
// deeper, so we need to look one level up for the typeshed fallback.
const debugTypeshedPath = combinePaths(moduleDirectory, '../' + pathConsts.typeshedFallback);
if (fs.existsSync(debugTypeshedPath)) {
return debugTypeshedPath;
}

return undefined;
Expand All @@ -50,22 +62,22 @@ export function findPythonSearchPaths(fs: VirtualFileSystem, configOptions: Conf
}

if (venvPath) {
let libPath = combinePaths(venvPath, consts.lib);
let libPath = combinePaths(venvPath, pathConsts.lib);
if (fs.existsSync(libPath)) {
importFailureInfo.push(`Found path '${ libPath }'; looking for ${ consts.sitePackages }`);
importFailureInfo.push(`Found path '${ libPath }'; looking for ${ pathConsts.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.sitePackages }`);
importFailureInfo.push(`Found path '${ libPath }'; looking for ${ pathConsts.sitePackages }`);
} else {
importFailureInfo.push(`Did not find '${ libPath }'`);
libPath = '';
}
}

if (libPath) {
const sitePackagesPath = combinePaths(libPath, consts.sitePackages);
const sitePackagesPath = combinePaths(libPath, pathConsts.sitePackages);
if (fs.existsSync(sitePackagesPath)) {
importFailureInfo.push(`Found path '${ sitePackagesPath }'`);
return [sitePackagesPath];
Expand All @@ -79,7 +91,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.sitePackages);
const dirPath = combinePaths(libPath, dirName, pathConsts.sitePackages);
if (fs.existsSync(dirPath)) {
importFailureInfo.push(`Found path '${ dirPath }'`);
return [dirPath];
Expand All @@ -90,7 +102,7 @@ export function findPythonSearchPaths(fs: VirtualFileSystem, configOptions: Conf
}
}

importFailureInfo.push(`Did not find '${ consts.sitePackages }'. Falling back on python interpreter.`);
importFailureInfo.push(`Did not find '${ pathConsts.sitePackages }'. Falling back on python interpreter.`);
}

// Fall back on the python interpreter.
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/pathConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*
* Defines well known consts and names
* Defines path-related constants.
*/

export const typeshedFallback = 'typeshed-fallback';
Expand Down
16 changes: 1 addition & 15 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
* Implements pyright language server.
*/

import * as fs from 'fs';
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/pathConsts';
import * as debug from './common/debug';
import { convertUriToPath, getDirectoryPath, normalizeSlashes } from './common/pathUtils';
import { LanguageServerBase, ServerSettings, WorkspaceServiceInstance } from './languageServerBase';
import { CodeActionProvider } from './languageService/codeActionProvider';
Expand All @@ -19,17 +15,7 @@ class Server extends LanguageServerBase {
private _controller: CommandController;

constructor() {
// pyright has "typeshed-fallback" under "client" and __dirname points to "client/server"
// make sure root directory point to "client", one level up from "client/server" where we can discover
// "typeshed-fallback" folder. in release, root is "extension" instead of "client" but
// folder structure is same (extension/server).
//
// root directory will be used for 2 different purposes.
// 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.typeshedFallback)), `Unable to locate typeshed fallback folder at '${ rootDirectory }'`);
super('Pyright', rootDirectory);
super('Pyright', getDirectoryPath(__dirname));

this._controller = new CommandController(this);
}
Expand Down
1 change: 1 addition & 0 deletions server/src/tests/fourSlashRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Entry point that will read all *.fourslash.ts files and
* register jest tests for them and run
*/

import * as path from 'path';
import { normalizeSlashes } from '../common/pathUtils';
import { runFourSlashTest } from './harness/fourslash/runner';
Expand Down
10 changes: 6 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/pathConsts';
import * as pathConsts 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,9 @@ export interface FileSystemCreateOptions extends FileSystemOptions {
documents?: readonly TextDocument[];
}

export const libFolder = combinePaths(MODULE_PATH, normalizeSlashes(combinePaths(consts.lib, consts.sitePackages)));
export const typeshedFolder = combinePaths(MODULE_PATH, normalizeSlashes(consts.typeshedFallback));
export const libFolder = combinePaths(MODULE_PATH, normalizeSlashes(
combinePaths(pathConsts.lib, pathConsts.sitePackages)));
export const typeshedFolder = combinePaths(MODULE_PATH, normalizeSlashes(pathConsts.typeshedFallback));
export const srcFolder = normalizeSlashes('/.src');

/**
Expand Down Expand Up @@ -100,7 +101,8 @@ 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.typeshedFallback));
mountPaths.set(typeshedFolder, resolvePaths(host.getWorkspaceRoot(), '../client/' +
pathConsts.typeshedFallback));
}

if (!canReuseCache(host, mountPaths)) {
Expand Down

0 comments on commit 04a01c7

Please sign in to comment.