Skip to content

Commit 9b7ebf6

Browse files
author
Mikhail Arkhipov
authored
Simplifies LS startup and update test baselines (#1762)
* Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3f. * Revert "Remove double event listening" This reverts commit af573be. * #1096 The if statement is automatically formatted incorrectly * Merge fix * Add more tests * More tests * Typo * Test * Also better handle multiline arguments * Add a couple missing periods [skip ci] * Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3f. * Revert "Remove double event listening" This reverts commit af573be. * Merge fix * #1257 On type formatting errors for args and kwargs * Handle f-strings * Stop importing from test code * #1308 Single line statements leading to an indentation on the next line * #726 editing python after inline if statement invalid indent * Undo change * Move constant * Harden LS startup error checks * #1364 Intellisense doesn't work after specific const string * Telemetry for the analysis enging * PR feedback * Fix typo * Test baseline update * Jedi 0.12 * Priority to goto_defition * News * Replace unzip * Linux flavors + test * Grammar check * Grammar test * Test baselines * Add news * Pin dependency [skip ci] * Specify markdown as preferable format * Improve function argument detection * Specify markdown * Pythia setting * Baseline updates * Baseline update * Improve startup * Handle missing interpreter better * Handle interpreter change * Delete old file * Fix LS startup time reporting * Remove Async suffix from IFileSystem * Remove Pythia * Remove pre-packaged MSIL * Exe name on Unix * Plain linux * Fix casing * Fix message * Update PTVS engine activation steps * Type formatter eats space in from . * fIX CASING * Remove flag * Don't wait for LS * Small test fixes * Update hover baselines
1 parent 27a9d81 commit 9b7ebf6

File tree

2 files changed

+17
-54
lines changed

2 files changed

+17
-54
lines changed

src/client/activation/analysis.ts

+10-47
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import { inject, injectable } from 'inversify';
55
import * as path from 'path';
66
import { ExtensionContext, OutputChannel } from 'vscode';
7-
import { Message } from 'vscode-jsonrpc';
8-
import { CloseAction, Disposable, ErrorAction, ErrorHandler, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
7+
import { Disposable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
98
import { IApplicationShell } from '../common/application/types';
109
import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
11-
import { createDeferred, Deferred } from '../common/helpers';
1210
import { IFileSystem, IPlatformService } from '../common/platform/types';
1311
import { StopWatch } from '../common/stopWatch';
1412
import { IConfigurationService, IExtensionContext, IOutputChannel } from '../common/types';
@@ -18,8 +16,7 @@ import { IServiceContainer } from '../ioc/types';
1816
import {
1917
PYTHON_ANALYSIS_ENGINE_DOWNLOADED,
2018
PYTHON_ANALYSIS_ENGINE_ENABLED,
21-
PYTHON_ANALYSIS_ENGINE_ERROR,
22-
PYTHON_ANALYSIS_ENGINE_STARTUP
19+
PYTHON_ANALYSIS_ENGINE_ERROR
2320
} from '../telemetry/constants';
2421
import { getTelemetryReporter } from '../telemetry/telemetry';
2522
import { AnalysisEngineDownloader } from './downloader';
@@ -32,18 +29,6 @@ const dotNetCommand = 'dotnet';
3229
const languageClientName = 'Python Tools';
3330
const analysisEngineFolder = 'analysis';
3431

35-
class LanguageServerStartupErrorHandler implements ErrorHandler {
36-
constructor(private readonly deferred: Deferred<void>) { }
37-
public error(error: Error, message: Message, count: number): ErrorAction {
38-
this.deferred.reject(error);
39-
return ErrorAction.Continue;
40-
}
41-
public closed(): CloseAction {
42-
this.deferred.reject();
43-
return CloseAction.Restart;
44-
}
45-
}
46-
4732
@injectable()
4833
export class AnalysisExtensionActivator implements IExtensionActivator {
4934
private readonly configuration: IConfigurationService;
@@ -102,8 +87,6 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
10287

10388
private async startLanguageServer(context: ExtensionContext, clientOptions: LanguageClientOptions): Promise<boolean> {
10489
// Determine if we are running MSIL/Universal via dotnet or self-contained app.
105-
const mscorlib = path.join(context.extensionPath, analysisEngineFolder, 'mscorlib.dll');
106-
const downloader = new AnalysisEngineDownloader(this.services, analysisEngineFolder);
10790

10891
const reporter = getTelemetryReporter();
10992
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_ENABLED);
@@ -112,20 +95,21 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
11295
if (!settings.downloadCodeAnalysis) {
11396
// Depends on .NET Runtime or SDK. Typically development-only case.
11497
this.languageClient = this.createSimpleLanguageClient(context, clientOptions);
115-
await this.tryStartLanguageClient(context, this.languageClient);
98+
await this.startLanguageClient(context);
11699
return true;
117100
}
118101

102+
const mscorlib = path.join(context.extensionPath, analysisEngineFolder, 'mscorlib.dll');
119103
if (!await this.fs.fileExists(mscorlib)) {
104+
const downloader = new AnalysisEngineDownloader(this.services, analysisEngineFolder);
120105
await downloader.downloadAnalysisEngine(context);
121106
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_DOWNLOADED);
122107
}
123108

124109
const serverModule = path.join(context.extensionPath, analysisEngineFolder, this.platformData.getEngineExecutableName());
125-
// Now try to start self-contained app
126110
this.languageClient = this.createSelfContainedLanguageClient(context, serverModule, clientOptions);
127111
try {
128-
await this.tryStartLanguageClient(context, this.languageClient);
112+
await this.startLanguageClient(context);
129113
return true;
130114
} catch (ex) {
131115
this.appShell.showErrorMessage(`Language server failed to start. Error ${ex}`);
@@ -134,31 +118,10 @@ export class AnalysisExtensionActivator implements IExtensionActivator {
134118
}
135119
}
136120

137-
private async tryStartLanguageClient(context: ExtensionContext, lc: LanguageClient): Promise<void> {
138-
let disposable: Disposable | undefined;
139-
const deferred = createDeferred<void>();
140-
try {
141-
const sw = new StopWatch();
142-
lc.clientOptions.errorHandler = new LanguageServerStartupErrorHandler(deferred);
143-
144-
disposable = lc.start();
145-
lc.onReady()
146-
.then(() => deferred.resolve())
147-
.catch((reason) => {
148-
deferred.reject(reason);
149-
});
150-
await deferred.promise;
151-
152-
this.output.appendLine(`Language server ready: ${this.sw.elapsedTime} ms`);
153-
context.subscriptions.push(disposable);
154-
155-
const reporter = getTelemetryReporter();
156-
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_STARTUP, {}, { startup_time: sw.elapsedTime });
157-
} catch (ex) {
158-
if (disposable) {
159-
disposable.dispose();
160-
}
161-
throw ex;
121+
private async startLanguageClient(context: ExtensionContext): Promise<void> {
122+
context.subscriptions.push(this.languageClient!.start());
123+
if (isTestExecution()) {
124+
await this.languageClient!.onReady();
162125
}
163126
}
164127

src/test/definitions/hover.ptvs.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ suite('Hover Definition (Analysis Engine)', () => {
5353
const expected = [
5454
'obj.method1:',
5555
'```python',
56-
'method method1 of one.Class1 objects',
56+
'method method1 of pythonFiles.autocomp.one.Class1 objects',
5757
'```',
5858
'This is method1'
5959
];
@@ -70,7 +70,7 @@ suite('Hover Definition (Analysis Engine)', () => {
7070
const expected = [
7171
'two.ct().fun:',
7272
'```python',
73-
'method fun of two.ct objects',
73+
'method fun of pythonFiles.autocomp.two.ct objects',
7474
'```',
7575
'This is fun'
7676
];
@@ -86,7 +86,7 @@ suite('Hover Definition (Analysis Engine)', () => {
8686
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
8787
const expected = [
8888
'```python',
89-
'four.Foo.bar() -> bool',
89+
'pythonFiles.autocomp.four.Foo.bar() -> bool',
9090
'declared in Foo',
9191
'```',
9292
'说明 - keep this line, it works',
@@ -105,7 +105,7 @@ suite('Hover Definition (Analysis Engine)', () => {
105105
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
106106
const expected = [
107107
'```python',
108-
'four.showMessage()',
108+
'pythonFiles.autocomp.four.showMessage()',
109109
'```',
110110
'Кюм ут жэмпэр пошжим льаборэж, коммюны янтэрэсщэт нам ед, декта игнота ныморэ жят эи.',
111111
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.'
@@ -138,7 +138,7 @@ suite('Hover Definition (Analysis Engine)', () => {
138138
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
139139
const expected = [
140140
'```python',
141-
'class misc.Random(_random.Random)',
141+
'class pythonFiles.autocomp.misc.Random(_random.Random)',
142142
'```',
143143
'Random number generator base class used by bound module functions.',
144144
'Used to instantiate instances of Random to get generators that don\'t',
@@ -162,7 +162,7 @@ suite('Hover Definition (Analysis Engine)', () => {
162162
const expected = [
163163
'rnd2.randint:',
164164
'```python',
165-
'method randint of misc.Random objects -> int',
165+
'method randint of pythonFiles.autocomp.misc.Random objects -> int',
166166
'```',
167167
'Return random integer in range [a, b], including both end points.'
168168
];
@@ -195,7 +195,7 @@ suite('Hover Definition (Analysis Engine)', () => {
195195
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
196196
const expected = [
197197
'```python',
198-
'class misc.Thread(_Verbose)',
198+
'class pythonFiles.autocomp.misc.Thread(_Verbose)',
199199
'```',
200200
'A class that represents a thread of control.',
201201
'This class can be safely subclassed in a limited fashion.'

0 commit comments

Comments
 (0)