Skip to content

Add restart language server command #12952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions news/1 Enhancements/3073.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add "Restart Language Server" command
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,11 @@
"command": "python.datascience.latestExtension",
"title": "DataScience.latestExtension",
"category": "Python"
},
{
"command": "python.analysis.restartLanguageServer",
"title": "%python.command.python.analysis.restartLanguageServer.title%",
"category": "Python"
}
],
"menus": {
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"python.command.python.datascience.selectJupyterInterpreter.title": "Select Interpreter to start Jupyter server",
"Datascience.currentlySelectedJupyterInterpreterForPlaceholder": "current: {0}",
"python.command.python.analysis.clearCache.title": "Clear Module Analysis Cache",
"python.command.python.analysis.restartLanguageServer.title": "Restart Language Server",
"python.snippet.launch.standard.label": "Python: Current File",
"python.snippet.launch.module.label": "Python: Module",
"python.snippet.launch.module.default": "enter-your-module-name",
Expand Down
2 changes: 1 addition & 1 deletion src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import { IServiceContainer } from '../ioc/types';
import { PythonInterpreter } from '../pythonEnvironments/info';
import { sendTelemetryEvent } from '../telemetry';
import { EventName } from '../telemetry/constants';
import { Commands } from './commands';
import { LanguageServerChangeHandler } from './common/languageServerChangeHandler';
import { Commands } from './languageServer/constants';
import { RefCountedLanguageServer } from './refCountedLanguageServer';
import {
IExtensionActivationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

export namespace Commands {
export const ClearAnalyisCache = 'python.analysis.clearCache';
export const RestartLS = 'python.analysis.restartLanguageServer';
}
13 changes: 11 additions & 2 deletions src/client/activation/languageServer/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import '../../common/extensions';

import { inject, injectable, named } from 'inversify';

import { ICommandManager } from '../../common/application/types';
import { traceDecorators } from '../../common/logger';
import { IConfigurationService, IDisposable, IExperimentsManager, Resource } from '../../common/types';
import { debounceSync } from '../../common/utils/decorators';
import { IServiceContainer } from '../../ioc/types';
import { PythonInterpreter } from '../../pythonEnvironments/info';
import { captureTelemetry } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { Commands } from '../commands';
import { LanguageClientMiddleware } from '../languageClientMiddleware';
import {
ILanguageServerAnalysisOptions,
Expand Down Expand Up @@ -39,8 +41,15 @@ export class DotNetLanguageServerManager implements ILanguageServerManager {
@inject(ILanguageServerExtension) private readonly lsExtension: ILanguageServerExtension,
@inject(ILanguageServerFolderService) private readonly folderService: ILanguageServerFolderService,
@inject(IExperimentsManager) private readonly experimentsManager: IExperimentsManager,
@inject(IConfigurationService) private readonly configService: IConfigurationService
) {}
@inject(IConfigurationService) private readonly configService: IConfigurationService,
@inject(ICommandManager) commandManager: ICommandManager
) {
this.disposables.push(
commandManager.registerCommand(Commands.RestartLS, () => {
this.restartLanguageServer().ignoreErrors();
})
);
}

private static versionTelemetryProps(instance: DotNetLanguageServerManager) {
return {
Expand Down
13 changes: 11 additions & 2 deletions src/client/activation/node/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import '../../common/extensions';

import { inject, injectable, named } from 'inversify';

import { ICommandManager } from '../../common/application/types';
import { traceDecorators } from '../../common/logger';
import { IConfigurationService, IDisposable, IExperimentsManager, Resource } from '../../common/types';
import { debounceSync } from '../../common/utils/decorators';
import { IServiceContainer } from '../../ioc/types';
import { PythonInterpreter } from '../../pythonEnvironments/info';
import { captureTelemetry } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { Commands } from '../commands';
import { LanguageClientMiddleware } from '../languageClientMiddleware';
import {
ILanguageServerAnalysisOptions,
Expand Down Expand Up @@ -38,8 +40,15 @@ export class NodeLanguageServerManager implements ILanguageServerManager {
@inject(ILanguageServerFolderService)
private readonly folderService: ILanguageServerFolderService,
@inject(IExperimentsManager) private readonly experimentsManager: IExperimentsManager,
@inject(IConfigurationService) private readonly configService: IConfigurationService
) {}
@inject(IConfigurationService) private readonly configService: IConfigurationService,
@inject(ICommandManager) commandManager: ICommandManager
) {
this.disposables.push(
commandManager.registerCommand(Commands.RestartLS, () => {
this.restartLanguageServer().ignoreErrors();
})
);
}

private static versionTelemetryProps(instance: NodeLanguageServerManager) {
return {
Expand Down
3 changes: 2 additions & 1 deletion src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

import { CancellationToken, Position, TextDocument, Uri } from 'vscode';
import { Commands as LSCommands } from '../../activation/languageServer/constants';
import { Commands as LSCommands } from '../../activation/commands';
import { Commands as DSCommands } from '../../datascience/constants';
import { KernelSpecInterpreter } from '../../datascience/jupyter/kernels/kernelSelector';
import { INotebookModel, ISwitchKernelOptions } from '../../datascience/types';
Expand Down Expand Up @@ -77,6 +77,7 @@ interface ICommandNameWithoutArgumentTypeMapping {
[DSCommands.CreateNewNotebook]: [];
[Commands.OpenStartPage]: [];
[LSCommands.ClearAnalyisCache]: [];
[LSCommands.RestartLS]: [];
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/test/activation/languageServer/manager.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Licensed under the MIT License.
import { expect, use } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { instance, mock, verify, when } from 'ts-mockito';
import { Uri } from 'vscode';
import { anything, instance, mock, verify, when } from 'ts-mockito';
import { Disposable, Uri } from 'vscode';
import { LanguageClientOptions } from 'vscode-languageclient/node';
import { Commands } from '../../../client/activation/commands';
import { DotNetLanguageServerAnalysisOptions } from '../../../client/activation/languageServer/analysisOptions';
import { LanguageServerExtension } from '../../../client/activation/languageServer/languageServerExtension';
import { DotNetLanguageServerFolderService } from '../../../client/activation/languageServer/languageServerFolderService';
Expand All @@ -16,6 +17,8 @@ import {
ILanguageServerFolderService,
ILanguageServerProxy
} from '../../../client/activation/types';
import { CommandManager } from '../../../client/common/application/commandManager';
import { ICommandManager } from '../../../client/common/application/types';
import { ConfigurationService } from '../../../client/common/configuration/service';
import { ExperimentsManager } from '../../../client/common/experiments/manager';
import { IConfigurationService, IExperimentsManager } from '../../../client/common/types';
Expand All @@ -37,6 +40,7 @@ suite('Language Server - Manager', () => {
let folderService: ILanguageServerFolderService;
let experimentsManager: IExperimentsManager;
let configService: IConfigurationService;
let commandManager: ICommandManager;
const languageClientOptions = ({ x: 1 } as any) as LanguageClientOptions;
setup(() => {
serviceContainer = mock(ServiceContainer);
Expand All @@ -46,13 +50,19 @@ suite('Language Server - Manager', () => {
folderService = mock(DotNetLanguageServerFolderService);
experimentsManager = mock(ExperimentsManager);
configService = mock(ConfigurationService);

commandManager = mock(CommandManager);
const disposable = mock(Disposable);
when(commandManager.registerCommand(Commands.RestartLS, anything())).thenReturn(instance(disposable));

manager = new DotNetLanguageServerManager(
instance(serviceContainer),
instance(analysisOptions),
instance(lsExtension),
instance(folderService),
instance(experimentsManager),
instance(configService)
instance(configService),
instance(commandManager)
);
});

Expand Down