Skip to content

Commit a77a10e

Browse files
authored
Add support for multi proc debugging (microsoft#2912)
* Multi proc debugging * Simplify launching ptvsd * Debug log should contain proccess id * Fix tests * Fix typo
1 parent 005092b commit a77a10e

30 files changed

Lines changed: 419 additions & 234 deletions

package-lock.json

Lines changed: 19 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,11 +1664,12 @@
16641664
"retyped-diff-match-patch-tsd-ambient": "^1.0.0-0",
16651665
"shortid": "^2.2.8",
16661666
"sinon": "^4.4.5",
1667+
"ts-mockito": "^2.3.1",
16671668
"tslint": "^5.9.1",
16681669
"tslint-eslint-rules": "^5.1.0",
16691670
"tslint-microsoft-contrib": "^5.0.3",
16701671
"typemoq": "^2.1.0",
1671-
"typescript": "^2.9.1",
1672+
"typescript": "^3.1.3",
16721673
"typescript-formatter": "^7.1.0",
16731674
"uuid": "^3.2.1",
16741675
"vscode": "^1.1.21",
Lines changed: 6 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,26 @@
1-
# Python Tools for Visual Studio
2-
# Copyright(c) Microsoft Corporation
3-
# All rights reserved.
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the License); you may not use
6-
# this file except in compliance with the License. You may obtain a copy of the
7-
# License at http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
10-
# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
11-
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
12-
# MERCHANTABLITY OR NON-INFRINGEMENT.
13-
#
14-
# See the Apache Version 2.0 License for specific language governing
15-
# permissions and limitations under the License.
16-
17-
# Source Copied from https://github.com/Microsoft/PTVS/blob/master/Python/Product/PythonTools/ptvsd_launcher.py
18-
"""
19-
Starts Debugging, expected to start with normal program
20-
to start as first argument and directory to run from as
21-
the second argument.
22-
"""
23-
24-
__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>"
25-
__version__ = "3.2.0.0"
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
263

274
import os
285
import os.path
296
import sys
307
import traceback
318

32-
# Arguments are:
33-
# 1. VS debugger port to connect to.
34-
# 2. '-g' to use the installed ptvsd package, rather than bundled one.
35-
# 3. '--nodebug' to launch without debugging.
36-
# 4. '-m' or '-c' to override the default run-as mode. [optional]
37-
# 5. Startup script name.
38-
# 6. Script arguments.
39-
40-
port_num = int(sys.argv[1])
41-
del sys.argv[0:2]
42-
43-
# Use bundled ptvsd or not?
44-
bundled_ptvsd = True
45-
if sys.argv and sys.argv[0] == '-g':
46-
bundled_ptvsd = False
47-
del sys.argv[0]
48-
49-
# Use bundled ptvsd or not?
50-
no_debug = False
51-
if sys.argv and sys.argv[0] == '--nodebug':
52-
no_debug = True
53-
del sys.argv[0]
54-
55-
# set run_as mode appropriately
56-
run_as = 'script'
57-
if sys.argv and sys.argv[0] == '-m':
58-
run_as = 'module'
59-
del sys.argv[0]
60-
if sys.argv and sys.argv[0] == '-c':
61-
run_as = 'code'
62-
del sys.argv[0]
63-
64-
# preserve filename before we del sys
65-
filename = sys.argv[0]
66-
67-
# fix sys.path to be the script file dir
68-
sys.path[0] = ''
69-
70-
if not bundled_ptvsd and (sys.platform == 'cli' or sys.version_info < (2, 7) or
71-
(sys.version_info >= (3, 0) and sys.version_info < (3, 4))):
72-
# This is experimental debugger incompatibility. Exit immediately.
73-
# This process will be killed by VS since it does not see a debugger
74-
# connect to it. The exit code we will get there will be wrong.
75-
# 687: ERROR_DLL_MIGHT_BE_INCOMPATIBLE
76-
sys.exit(687)
77-
789
# Load the debugger package
7910
try:
80-
ptvs_lib_path = None
81-
if bundled_ptvsd:
82-
ptvs_lib_path = os.path.join(os.path.dirname(__file__), 'ptvsd')
83-
sys.path.append(ptvs_lib_path)
11+
ptvs_lib_path = os.path.join(os.path.dirname(__file__), 'ptvsd')
12+
sys.path.append(ptvs_lib_path)
8413
try:
8514
import ptvsd
8615
import ptvsd.debugger as vspd
16+
from ptvsd.__main__ import main
8717
ptvsd_loaded = True
8818
except ImportError:
8919
ptvsd_loaded = False
9020
raise
9121
vspd.DONT_DEBUG.append(os.path.normcase(__file__))
9222
except:
9323
traceback.print_exc()
94-
if not bundled_ptvsd and not ptvsd_loaded:
95-
# This is experimental debugger import error. Exit immediately.
96-
# This process will be killed by VS since it does not see a debugger
97-
# connect to it. The exit code we will get there will be wrong.
98-
# 126 : ERROR_MOD_NOT_FOUND
99-
sys.exit(126)
10024
print('''
10125
Internal error detected. Please copy the above traceback and report at
10226
https://github.com/Microsoft/vscode-python/issues/new
@@ -111,8 +35,4 @@
11135
if ptvs_lib_path:
11236
sys.path.remove(ptvs_lib_path)
11337

114-
if no_debug:
115-
vspd.run(filename, port_num, run_as, *sys.argv[1:])
116-
else:
117-
# and start debugging
118-
vspd.debug(filename, port_num, '', '', run_as)
38+
main(sys.argv)

src/client/activation/languageServer/languageServerFolderService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { inject, injectable } from 'inversify';
77
import * as path from 'path';
88
import * as semver from 'semver';
99
import { EXTENSION_ROOT_DIR } from '../../common/constants';
10-
import { log } from '../../common/logger';
10+
import { traceVerbose } from '../../common/logger';
1111
import { NugetPackage } from '../../common/nuget/types';
1212
import { IFileSystem } from '../../common/platform/types';
1313
import { IConfigurationService } from '../../common/types';
@@ -20,7 +20,7 @@ const languageServerFolder = 'languageServer';
2020
export class LanguageServerFolderService implements ILanguageServerFolderService {
2121
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) { }
2222

23-
@log('Get language server folder name')
23+
@traceVerbose('Get language server folder name')
2424
public async getLanguageServerFolderName(): Promise<string> {
2525
const currentFolder = await this.getCurrentLanguageServerDirectory();
2626
let serverVersion: NugetPackage | undefined;
@@ -40,7 +40,7 @@ export class LanguageServerFolderService implements ILanguageServerFolderService
4040
return `${languageServerFolder}.${serverVersion!.version.raw}`;
4141
}
4242

43-
@log('Get latest version of Language Server')
43+
@traceVerbose('Get latest version of Language Server')
4444
public getLatestLanguageServerVersion(): Promise<NugetPackage | undefined> {
4545
const lsPackageService = this.serviceContainer.get<ILanguageServerPackageService>(ILanguageServerPackageService);
4646
return lsPackageService.getLatestNugetPackageVersion();

src/client/activation/languageServer/languageServerPackageService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { inject, injectable } from 'inversify';
77
import { parse } from 'semver';
88
import { PVSC_EXTENSION_ID } from '../../common/constants';
9-
import { log } from '../../common/logger';
9+
import { traceVerbose } from '../../common/logger';
1010
import { INugetRepository, INugetService, NugetPackage } from '../../common/nuget/types';
1111
import { IPlatformService } from '../../common/platform/types';
1212
import { IConfigurationService, IExtensions, LanguageServerDownloadChannels } from '../../common/types';
@@ -44,13 +44,13 @@ export class LanguageServerPackageService implements ILanguageServerPackageServi
4444
}
4545
}
4646

47-
@log('Get latest language server nuget package version')
47+
@traceVerbose('Get latest language server nuget package version')
4848
public async getLatestNugetPackageVersion(): Promise<NugetPackage> {
4949
const downloadChannel = this.getLanguageServerDownloadChannel();
5050
const nugetRepo = this.serviceContainer.get<INugetRepository>(INugetRepository, downloadChannel);
5151
const nugetService = this.serviceContainer.get<INugetService>(INugetService);
5252
const packageName = this.getNugetPackageName();
53-
log(`Listing packages for ${downloadChannel} for ${packageName}`);
53+
traceVerbose(`Listing packages for ${downloadChannel} for ${packageName}`);
5454
const packages = await nugetRepo.getPackages(packageName);
5555

5656
const validPackages = packages

src/client/application/diagnostics/checks/invalidPythonPathInDebugger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { inject, injectable } from 'inversify';
77
import { DiagnosticSeverity, Uri } from 'vscode';
88
import '../../../common/extensions';
9-
import { error } from '../../../common/logger';
9+
import { Logger } from '../../../common/logger';
1010
import { IConfigurationService } from '../../../common/types';
1111
import { IInterpreterHelper } from '../../../interpreter/contracts';
1212
import { IServiceContainer } from '../../../ioc/types';
@@ -67,7 +67,7 @@ export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService i
6767
}
6868

6969
this.handle([new InvalidPythonPathInDebuggerDiagnostic()])
70-
.catch(ex => error('Failed to handle invalid python path in debugger', ex))
70+
.catch(ex => Logger.error('Failed to handle invalid python path in debugger', ex))
7171
.ignoreErrors();
7272
return false;
7373
}

src/client/application/diagnostics/checks/powerShellActivation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { inject, injectable } from 'inversify';
77
import { DiagnosticSeverity } from 'vscode';
88
import '../../../common/extensions';
9-
import { error } from '../../../common/logger';
9+
import { Logger } from '../../../common/logger';
1010
import { useCommandPromptAsDefaultShell } from '../../../common/terminal/commandPrompt';
1111
import { IConfigurationService, ICurrentProcess } from '../../../common/types';
1212
import { IServiceContainer } from '../../../ioc/types';
@@ -57,7 +57,7 @@ export class PowerShellActivationHackDiagnosticsService extends BaseDiagnosticsS
5757
command: {
5858
diagnostic, invoke: async (): Promise<void> => {
5959
useCommandPromptAsDefaultShell(currentProcess, configurationService)
60-
.catch(ex => error('Use Command Prompt as default shell', ex));
60+
.catch(ex => Logger.error('Use Command Prompt as default shell', ex));
6161
}
6262
}
6363
},

0 commit comments

Comments
 (0)