mirror of
https://github.com/microsoft/pyright.git
synced 2024-08-17 03:40:44 +03:00
Implemented "Restart Server" command.
This commit is contained in:
parent
d8584313ac
commit
93804d3c07
@ -45,6 +45,11 @@
|
||||
"command": "pyright.organizeimports",
|
||||
"title": "Organize Imports",
|
||||
"category": "Pyright"
|
||||
},
|
||||
{
|
||||
"command": "pyright.restartserver",
|
||||
"title": "Restart Server",
|
||||
"category": "Pyright"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
|
@ -99,7 +99,7 @@ export function activate(context: ExtensionContext) {
|
||||
);
|
||||
});
|
||||
|
||||
const genericCommands = [Commands.createTypeStub];
|
||||
const genericCommands = [Commands.createTypeStub, Commands.restartServer];
|
||||
genericCommands.forEach(command => {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand(command, (...args: any[]) => {
|
||||
|
@ -6,3 +6,6 @@ Pyright offers the following commands, which can be invoked from VS Code’s “
|
||||
This command reorders all imports found in the global (module-level) scope of the source file. As recommended in PEP8, imports are grouped into three groups, each separated by an empty line. The first group includes all built-in modules, the second group includes all third-party modules, and the third group includes all local modules.
|
||||
|
||||
Within each group, imports are sorted alphabetically. And within each “from X import Y” statement, the imported symbols are sorted alphabetically. Pyright also rewraps any imports that don't fit within a single line, switching to multi-line formatting.
|
||||
|
||||
## Restart Server
|
||||
This command forces the type checker to discard all of its cached type information and restart analysis. It is useful in cases where new type stubs or libraries have been installed.
|
||||
|
@ -549,6 +549,12 @@ export class AnalyzerService {
|
||||
this._program.markAllFilesDirty(true);
|
||||
}
|
||||
|
||||
// Forces the service to stop all analysis, discard all its caches,
|
||||
// and research for files.
|
||||
restart() {
|
||||
this._applyConfigOptions();
|
||||
}
|
||||
|
||||
private get _fs() {
|
||||
return this._importResolver.fileSystem;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import { LanguageServerInterface } from '../languageServerBase';
|
||||
import { Commands } from './commands';
|
||||
import { CreateTypeStubCommand } from './createTypeStub';
|
||||
import { QuickActionCommand } from './quickActionCommand';
|
||||
import { RestartServerCommand } from './restartServer';
|
||||
|
||||
export interface ServerCommand {
|
||||
execute(cmdParams: ExecuteCommandParams): Promise<any>;
|
||||
@ -17,20 +18,33 @@ export interface ServerCommand {
|
||||
|
||||
export class CommandController implements ServerCommand {
|
||||
private _createStub: CreateTypeStubCommand;
|
||||
private _restartServer: RestartServerCommand;
|
||||
private _quickAction: QuickActionCommand;
|
||||
|
||||
constructor(ls: LanguageServerInterface) {
|
||||
this._createStub = new CreateTypeStubCommand(ls);
|
||||
this._restartServer = new RestartServerCommand(ls);
|
||||
this._quickAction = new QuickActionCommand(ls);
|
||||
}
|
||||
|
||||
async execute(cmdParams: ExecuteCommandParams): Promise<any> {
|
||||
if (cmdParams.command === Commands.orderImports || cmdParams.command === Commands.addMissingOptionalToParam) {
|
||||
return this._quickAction.execute(cmdParams);
|
||||
switch (cmdParams.command) {
|
||||
case Commands.orderImports:
|
||||
case Commands.addMissingOptionalToParam: {
|
||||
return this._quickAction.execute(cmdParams);
|
||||
}
|
||||
|
||||
case Commands.createTypeStub: {
|
||||
return this._createStub.execute(cmdParams);
|
||||
}
|
||||
|
||||
case Commands.restartServer: {
|
||||
return this._restartServer.execute(cmdParams);
|
||||
}
|
||||
|
||||
default: {
|
||||
return new ResponseError<string>(1, 'Unsupported command');
|
||||
}
|
||||
}
|
||||
if (cmdParams.command === Commands.createTypeStub) {
|
||||
return this._createStub.execute(cmdParams);
|
||||
}
|
||||
return new ResponseError<string>(1, 'Unsupported command');
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
export const enum Commands {
|
||||
createTypeStub = 'pyright.createtypestub',
|
||||
restartServer = 'pyright.restartserver',
|
||||
orderImports = 'pyright.organizeimports',
|
||||
addMissingOptionalToParam = 'pyright.addoptionalforparam'
|
||||
}
|
||||
|
18
server/src/commands/restartServer.ts
Normal file
18
server/src/commands/restartServer.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* restartServer.ts
|
||||
*
|
||||
* Implements 'restart server' command functionality.
|
||||
*/
|
||||
|
||||
import { ExecuteCommandParams } from 'vscode-languageserver';
|
||||
|
||||
import { LanguageServerInterface } from '../languageServerBase';
|
||||
import { ServerCommand } from './commandController';
|
||||
|
||||
export class RestartServerCommand implements ServerCommand {
|
||||
constructor(private _ls: LanguageServerInterface) {}
|
||||
|
||||
async execute(cmdParams: ExecuteCommandParams): Promise<any> {
|
||||
this._ls.restart();
|
||||
}
|
||||
}
|
@ -73,6 +73,7 @@ export interface LanguageServerInterface {
|
||||
getWorkspaceForFile(filePath: string): WorkspaceServiceInstance;
|
||||
getSettings(workspace: WorkspaceServiceInstance): Promise<ServerSettings>;
|
||||
reanalyze(): void;
|
||||
restart(): void;
|
||||
|
||||
readonly rootPath: string;
|
||||
readonly console: ConsoleInterface;
|
||||
@ -174,6 +175,12 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
|
||||
});
|
||||
}
|
||||
|
||||
restart() {
|
||||
this._workspaceMap.forEach(workspace => {
|
||||
workspace.serviceInstance.restart();
|
||||
});
|
||||
}
|
||||
|
||||
private _setupConnection(): void {
|
||||
// After the server has started the client sends an initialize request. The server receives
|
||||
// in the passed params the rootPath of the workspace plus the client capabilities.
|
||||
|
@ -124,6 +124,7 @@ declare namespace Consts {
|
||||
|
||||
export enum Commands {
|
||||
createTypeStub = 'pyright.createtypestub',
|
||||
restartServer = 'pyright.restartserver',
|
||||
orderImports = 'pyright.organizeimports',
|
||||
addMissingOptionalToParam = 'pyright.addoptionalforparam'
|
||||
}
|
||||
|
@ -48,7 +48,11 @@ export class TestLanguageService implements LanguageServerInterface {
|
||||
}
|
||||
|
||||
reanalyze(): void {
|
||||
/* don't do anything */
|
||||
// Don't do anything
|
||||
}
|
||||
|
||||
restart(): void {
|
||||
// Don't do anything
|
||||
}
|
||||
|
||||
readonly rootPath = path.sep;
|
||||
@ -65,6 +69,6 @@ class TestWindow implements WindowInterface {
|
||||
}
|
||||
|
||||
showInformationMessage(message: string): void {
|
||||
/* do not do any thing */
|
||||
// Don't do anything
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ export namespace Consts {
|
||||
// once compiled
|
||||
export enum Commands {
|
||||
createTypeStub = 'pyright.createtypestub',
|
||||
restartServer = 'pyright.restartserver',
|
||||
orderImports = 'pyright.organizeimports',
|
||||
addMissingOptionalToParam = 'pyright.addoptionalforparam'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user