Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "off",
// Overriding formatting rules to let Prettier handle them
"comma-dangle": "off",
"function-paren-newline": "off",
"implicit-arrow-linebreak": "off",
"indent": "off",
"max-len": "off",
"object-curly-newline": ["error", {"ImportDeclaration": {"consistent": true}}],
"operator-linebreak": "off",
// Other rules
"class-methods-use-this": ["error", {"exceptMethods": ["dispose"]}],
"func-names": "off",
"import/extensions": "off",
"import/namespace": "off",
Expand All @@ -52,24 +61,7 @@
}
],
"import/prefer-default-export": "off",
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"linebreak-style": "off",
"max-len": [
"warn",
{
"code": 120,
"ignorePattern": "^import\\s.+\\sfrom\\s.+;$",
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreUrls": true
}
],
"no-await-in-loop": "off",
"no-confusing-arrow": [
"error",
Expand Down
17 changes: 12 additions & 5 deletions src/client/activation/jedi/languageServerProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ import { ILanguageClientFactory, ILanguageServerProxy } from '../types';
@injectable()
export class JediLanguageServerProxy implements ILanguageServerProxy {
public languageClient: LanguageClient | undefined;

private startupCompleted: Deferred<void>;

private cancellationStrategy: FileBasedCancellationStrategy | undefined;

private readonly disposables: Disposable[] = [];
private disposed: boolean = false;

private disposed = false;

private lsVersion: string | undefined;

constructor(
Expand All @@ -53,7 +58,7 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
}

@traceDecorators.verbose('Stopping language server')
public dispose() {
public dispose(): void {
if (this.languageClient) {
// Do not await on this.
this.languageClient.stop().then(noop, (ex) => traceError('Stopping language client failed', ex));
Expand Down Expand Up @@ -120,8 +125,10 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
}
}

// tslint:disable-next-line: no-empty
public loadExtension(_args?: {}) {}
// eslint-disable-next-line class-methods-use-this
public loadExtension(/* _args?: {} */): void {
// No body.
}

@captureTelemetry(
EventName.LANGUAGE_SERVER_READY,
Expand All @@ -141,7 +148,7 @@ export class JediLanguageServerProxy implements ILanguageServerProxy {
}

@swallowExceptions('Activating Unit Tests Manager for Jedi language server')
protected async registerTestServices() {
protected async registerTestServices(): Promise<void> {
if (!this.languageClient) {
throw new Error('languageClient not initialized');
}
Expand Down
20 changes: 14 additions & 6 deletions src/client/activation/jedi/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ import {
@injectable()
export class JediLanguageServerManager implements ILanguageServerManager {
private languageServerProxy?: ILanguageServerProxy;

private resource!: Resource;

private interpreter: PythonEnvironment | undefined;

private middleware: LanguageClientMiddleware | undefined;

private disposables: IDisposable[] = [];
private connected: boolean = false;

private connected = false;

private lsVersion: string | undefined;

constructor(
Expand All @@ -54,14 +60,14 @@ export class JediLanguageServerManager implements ILanguageServerManager {
};
}

public dispose() {
public dispose(): void {
if (this.languageProxy) {
this.languageProxy.dispose();
}
this.disposables.forEach((d) => d.dispose());
}

public get languageProxy() {
public get languageProxy(): ILanguageServerProxy | undefined {
return this.languageServerProxy;
}

Expand All @@ -80,6 +86,7 @@ export class JediLanguageServerManager implements ILanguageServerManager {
// Search using a regex in the text
const match = /jedi-language-server==([0-9\.]*)/.exec(requirementsTxt);
if (match && match.length > 1) {
// eslint-disable-next-line prefer-destructuring
this.lsVersion = match[1];
} else {
this.lsVersion = '0.19.3';
Expand All @@ -89,12 +96,12 @@ export class JediLanguageServerManager implements ILanguageServerManager {
await this.startLanguageServer();
}

public connect() {
public connect(): void {
this.connected = true;
this.middleware?.connect();
}

public disconnect() {
public disconnect(): void {
this.connected = false;
this.middleware?.disconnect();
}
Expand Down Expand Up @@ -125,12 +132,13 @@ export class JediLanguageServerManager implements ILanguageServerManager {
this.languageServerProxy = this.serviceContainer.get<ILanguageServerProxy>(ILanguageServerProxy);

const options = await this.analysisOptions.getAnalysisOptions();
options.middleware = this.middleware = new LanguageClientMiddleware(
this.middleware = new LanguageClientMiddleware(
this.serviceContainer,
LanguageServerType.Jedi,
() => this.languageServerProxy?.languageClient,
this.lsVersion
);
options.middleware = this.middleware;

// Make sure the middleware is connected if we restart and we we're already connected.
if (this.connected) {
Expand Down
23 changes: 20 additions & 3 deletions src/client/activation/jedi/multiplexingActivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SignatureHelpContext,
TextDocument
} from 'vscode';
import { ServerCapabilities } from 'vscode-languageserver-protocol';
// tslint:disable-next-line: import-name
import { IWorkspaceService } from '../../common/application/types';
import { isTestExecution } from '../../common/constants';
Expand All @@ -26,7 +27,7 @@ import {
import { IServiceManager } from '../../ioc/types';
import { PythonEnvironment } from '../../pythonEnvironments/info';
import { JediExtensionActivator } from '../jedi';
import { ILanguageServerActivator, ILanguageServerManager } from '../types';
import { ILanguageServerActivator, ILanguageServerConnection, ILanguageServerManager } from '../types';
import { JediLanguageServerActivator } from './activator';

/**
Expand All @@ -40,7 +41,9 @@ import { JediLanguageServerActivator } from './activator';
@injectable()
export class MultiplexingJediLanguageServerActivator implements ILanguageServerActivator {
private realLanguageServerPromise: Promise<ILanguageServerActivator>;

private realLanguageServer: ILanguageServerActivator | undefined;

private onDidChangeCodeLensesEmitter = new EventEmitter<void>();

constructor(
Expand All @@ -64,37 +67,43 @@ export class MultiplexingJediLanguageServerActivator implements ILanguageServerA
return this.realLanguageServer;
});
}

public async start(resource: Resource, interpreter: PythonEnvironment | undefined): Promise<void> {
const realServer = await this.realLanguageServerPromise;
if (!isTestExecution()) {
this.proposePylancePopup.showBanner().ignoreErrors();
}
return realServer.start(resource, interpreter);
}

public activate(): void {
if (this.realLanguageServer) {
this.realLanguageServer.activate();
}
}

public deactivate(): void {
if (this.realLanguageServer) {
this.realLanguageServer.deactivate();
}
}

public get onDidChangeCodeLenses(): Event<void> {
return this.onDidChangeCodeLensesEmitter.event;
}

public get connection() {
public get connection(): ILanguageServerConnection | undefined {
if (this.realLanguageServer) {
return this.realLanguageServer.connection;
}
return undefined;
}

public get capabilities() {
public get capabilities(): ServerCapabilities | undefined {
if (this.realLanguageServer) {
return this.realLanguageServer.capabilities;
}
return undefined;
}

public async provideRenameEdits(
Expand All @@ -106,14 +115,17 @@ export class MultiplexingJediLanguageServerActivator implements ILanguageServerA
const server = await this.realLanguageServerPromise;
return server.provideRenameEdits(document, position, newName, token);
}

public async provideDefinition(document: TextDocument, position: Position, token: CancellationToken) {
const server = await this.realLanguageServerPromise;
return server.provideDefinition(document, position, token);
}

public async provideHover(document: TextDocument, position: Position, token: CancellationToken) {
const server = await this.realLanguageServerPromise;
return server.provideHover(document, position, token);
}

public async provideReferences(
document: TextDocument,
position: Position,
Expand All @@ -123,6 +135,7 @@ export class MultiplexingJediLanguageServerActivator implements ILanguageServerA
const server = await this.realLanguageServerPromise;
return server.provideReferences(document, position, context, token);
}

public async provideCompletionItems(
document: TextDocument,
position: Position,
Expand All @@ -132,14 +145,17 @@ export class MultiplexingJediLanguageServerActivator implements ILanguageServerA
const server = await this.realLanguageServerPromise;
return server.provideCompletionItems(document, position, token, context);
}

public async provideCodeLenses(document: TextDocument, token: CancellationToken) {
const server = await this.realLanguageServerPromise;
return server.provideCodeLenses(document, token);
}

public async provideDocumentSymbols(document: TextDocument, token: CancellationToken) {
const server = await this.realLanguageServerPromise;
return server.provideDocumentSymbols(document, token);
}

public async provideSignatureHelp(
document: TextDocument,
position: Position,
Expand All @@ -149,6 +165,7 @@ export class MultiplexingJediLanguageServerActivator implements ILanguageServerA
const server = await this.realLanguageServerPromise;
return server.provideSignatureHelp(document, position, token, context);
}

public dispose(): void {
if (this.realLanguageServer) {
this.realLanguageServer.dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Uri } from 'vscode';
Expand Down
15 changes: 9 additions & 6 deletions src/client/common/application/webviews/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,25 @@ export class Webview implements IWebview {

// tslint:disable-next-line:no-any
protected async generateLocalReactHtml(): Promise<string> {
let webview: vscodeWebview;
if (!this.webview) {
throw new Error('WebView not initialized, too early to get a Uri');
} else {
webview = this.webview;
}

const uriBase = this.webview.asWebviewUri(Uri.file(this.options.cwd)).toString();
const uris = this.options.scripts.map((script) => this.webview!.asWebviewUri(Uri.file(script)));
const uris = this.options.scripts.map((script) => webview.asWebviewUri(Uri.file(script))); // NOSONAR
const testFiles = await this.fs.getFiles(this.options.rootPath);

// This method must be called so VSC is aware of files that can be pulled.
// Allow js and js.map files to be loaded by webpack in the webview.
testFiles
.filter((f) => f.toLowerCase().endsWith('.js') || f.toLowerCase().endsWith('.js.map'))
.forEach((f) => this.webview!.asWebviewUri(Uri.file(f)));
.forEach((f) => webview.asWebviewUri(Uri.file(f)));

const rootPath = this.webview.asWebviewUri(Uri.file(this.options.rootPath)).toString();
const fontAwesomePath = this.webview
const rootPath = webview.asWebviewUri(Uri.file(this.options.rootPath)).toString();
const fontAwesomePath = webview
.asWebviewUri(
Uri.file(
path.join(this.options.rootPath, 'node_modules', 'font-awesome', 'css', 'font-awesome.min.css')
Expand All @@ -59,8 +62,8 @@ export class Webview implements IWebview {
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta http-equiv="Content-Security-Policy" content="img-src 'self' data: https: http: blob: ${
this.webview.cspSource
}; default-src 'unsafe-inline' 'unsafe-eval' data: https: http: blob: ${this.webview.cspSource};">
webview.cspSource
}; default-src 'unsafe-inline' 'unsafe-eval' data: https: http: blob: ${webview.cspSource};">
<meta name="theme-color" content="#000000">
<title>VS Code Python React UI</title>
<base href="${uriBase}${uriBase.endsWith('/') ? '' : '/'}"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../../activation/types';
import { ICommandManager } from '../../common/application/types';
import { ContextKey } from '../../common/contextKey';
import { traceError } from '../../common/logger';
import { IExperimentService } from '../../common/types';
import { ICommandManager } from '../application/types';
import { ContextKey } from '../contextKey';
import { traceError } from '../logger';
import { IExperimentService } from '../types';

@injectable()
export class DebuggerDataViewerExperimentEnabler implements IExtensionSingleActivationService {
constructor(
@inject(ICommandManager) private readonly commandManager: ICommandManager,
@inject(IExperimentService) private readonly experimentService: IExperimentService
) {}
public async activate() {

public async activate(): Promise<void> {
this.activateInternal().catch(traceError.bind('Failed to activate debuggerDataViewerExperimentEnabler'));
}
private async activateInternal() {

private async activateInternal(): Promise<void> {
// This context key controls the visibility of the 'View Variable in Data Viewer'
// context menu item from the variable window context menu during a debugging session
const isDataViewerExperimentEnabled = new ContextKey(
Expand Down
Loading