import { CancellationToken , ExecuteCommandParams , ResponseError } from 'vscode-languageserver' ; import { ServerCommand } from 'pyright-internal/commands/commandController' ; import { convertUriToPath } from 'pyright-internal/common/pathUtils' ; import { PyteaCommands } from './commands' ; import { PyteaServer } from './server' ; export class RestartServerCommand implements ServerCommand { constructor ( private _ls ) { } async execute ( cmdParams ) { this . _ls . restart ( ) ; } } export class AnalyzeFileCommand implements ServerCommand { constructor ( private _ls ) { } async execute ( cmdParams ) { const args = cmdParams . arguments ; if ( args && args [ 0 ] ) { const entryPath = convertUriToPath ( args [ 0 ] ) ; return this . _ls . analyze ( entryPath ) ; } } } export class PyteaCommandController implements ServerCommand { private _restartServer : RestartServerCommand ; private _analyzeFile : AnalyzeFileCommand ; constructor ( private ls ) { this . _restartServer = new RestartServerCommand ( ls ) ; this . _analyzeFile = new AnalyzeFileCommand ( ls ) ; } async execute ( cmdParams , token ) { switch ( cmdParams . command ) { case PyteaCommands . restartServer : { return this . _restartServer . execute ( cmdParams ) ; } case PyteaCommands . analyzeFile : { return this . _analyzeFile . execute ( cmdParams ) ; } case PyteaCommands . selectPath : { return this . ls . selectPath ( cmdParams . arguments ! [ 0 ] ) ; } default : { return new ResponseError < string > ( 1 , 'Unsupported command' ) ; } } } }