Skip to content

Commit

Permalink
Simplifies LS startup and update test baselines (#1762)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Mikhail Arkhipov authored May 29, 2018
1 parent 27a9d81 commit 9b7ebf6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 54 deletions.
57 changes: 10 additions & 47 deletions src/client/activation/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { ExtensionContext, OutputChannel } from 'vscode';
import { Message } from 'vscode-jsonrpc';
import { CloseAction, Disposable, ErrorAction, ErrorHandler, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
import { Disposable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
import { IApplicationShell } from '../common/application/types';
import { isTestExecution, STANDARD_OUTPUT_CHANNEL } from '../common/constants';
import { createDeferred, Deferred } from '../common/helpers';
import { IFileSystem, IPlatformService } from '../common/platform/types';
import { StopWatch } from '../common/stopWatch';
import { IConfigurationService, IExtensionContext, IOutputChannel } from '../common/types';
Expand All @@ -18,8 +16,7 @@ import { IServiceContainer } from '../ioc/types';
import {
PYTHON_ANALYSIS_ENGINE_DOWNLOADED,
PYTHON_ANALYSIS_ENGINE_ENABLED,
PYTHON_ANALYSIS_ENGINE_ERROR,
PYTHON_ANALYSIS_ENGINE_STARTUP
PYTHON_ANALYSIS_ENGINE_ERROR
} from '../telemetry/constants';
import { getTelemetryReporter } from '../telemetry/telemetry';
import { AnalysisEngineDownloader } from './downloader';
Expand All @@ -32,18 +29,6 @@ const dotNetCommand = 'dotnet';
const languageClientName = 'Python Tools';
const analysisEngineFolder = 'analysis';

class LanguageServerStartupErrorHandler implements ErrorHandler {
constructor(private readonly deferred: Deferred<void>) { }
public error(error: Error, message: Message, count: number): ErrorAction {
this.deferred.reject(error);
return ErrorAction.Continue;
}
public closed(): CloseAction {
this.deferred.reject();
return CloseAction.Restart;
}
}

@injectable()
export class AnalysisExtensionActivator implements IExtensionActivator {
private readonly configuration: IConfigurationService;
Expand Down Expand Up @@ -102,8 +87,6 @@ export class AnalysisExtensionActivator implements IExtensionActivator {

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

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

const mscorlib = path.join(context.extensionPath, analysisEngineFolder, 'mscorlib.dll');
if (!await this.fs.fileExists(mscorlib)) {
const downloader = new AnalysisEngineDownloader(this.services, analysisEngineFolder);
await downloader.downloadAnalysisEngine(context);
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_DOWNLOADED);
}

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

private async tryStartLanguageClient(context: ExtensionContext, lc: LanguageClient): Promise<void> {
let disposable: Disposable | undefined;
const deferred = createDeferred<void>();
try {
const sw = new StopWatch();
lc.clientOptions.errorHandler = new LanguageServerStartupErrorHandler(deferred);

disposable = lc.start();
lc.onReady()
.then(() => deferred.resolve())
.catch((reason) => {
deferred.reject(reason);
});
await deferred.promise;

this.output.appendLine(`Language server ready: ${this.sw.elapsedTime} ms`);
context.subscriptions.push(disposable);

const reporter = getTelemetryReporter();
reporter.sendTelemetryEvent(PYTHON_ANALYSIS_ENGINE_STARTUP, {}, { startup_time: sw.elapsedTime });
} catch (ex) {
if (disposable) {
disposable.dispose();
}
throw ex;
private async startLanguageClient(context: ExtensionContext): Promise<void> {
context.subscriptions.push(this.languageClient!.start());
if (isTestExecution()) {
await this.languageClient!.onReady();
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/test/definitions/hover.ptvs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const expected = [
'obj.method1:',
'```python',
'method method1 of one.Class1 objects',
'method method1 of pythonFiles.autocomp.one.Class1 objects',
'```',
'This is method1'
];
Expand All @@ -70,7 +70,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const expected = [
'two.ct().fun:',
'```python',
'method fun of two.ct objects',
'method fun of pythonFiles.autocomp.two.ct objects',
'```',
'This is fun'
];
Expand All @@ -86,7 +86,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
const expected = [
'```python',
'four.Foo.bar() -> bool',
'pythonFiles.autocomp.four.Foo.bar() -> bool',
'declared in Foo',
'```',
'说明 - keep this line, it works',
Expand All @@ -105,7 +105,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
const expected = [
'```python',
'four.showMessage()',
'pythonFiles.autocomp.four.showMessage()',
'```',
'Кюм ут жэмпэр пошжим льаборэж, коммюны янтэрэсщэт нам ед, декта игнота ныморэ жят эи.',
'Шэа декам экшырки эи, эи зыд эррэм докэндё, векж факэтэ пэрчыквюэрёж ку.'
Expand Down Expand Up @@ -138,7 +138,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
const expected = [
'```python',
'class misc.Random(_random.Random)',
'class pythonFiles.autocomp.misc.Random(_random.Random)',
'```',
'Random number generator base class used by bound module functions.',
'Used to instantiate instances of Random to get generators that don\'t',
Expand All @@ -162,7 +162,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const expected = [
'rnd2.randint:',
'```python',
'method randint of misc.Random objects -> int',
'method randint of pythonFiles.autocomp.misc.Random objects -> int',
'```',
'Return random integer in range [a, b], including both end points.'
];
Expand Down Expand Up @@ -195,7 +195,7 @@ suite('Hover Definition (Analysis Engine)', () => {
const actual = normalizeMarkedString(def[0].contents[0]).splitLines();
const expected = [
'```python',
'class misc.Thread(_Verbose)',
'class pythonFiles.autocomp.misc.Thread(_Verbose)',
'```',
'A class that represents a thread of control.',
'This class can be safely subclassed in a limited fashion.'
Expand Down

0 comments on commit 9b7ebf6

Please sign in to comment.