import * as path from 'path' ; import { CancellationToken , CodeAction , ExecuteCommandParams } from 'vscode-languageserver' ; import { ImportResolverFactory } from '../../../analyzer/importResolver' ; import { AnalyzerService } from '../../../analyzer/service' ; import { BackgroundAnalysisBase } from '../../../backgroundAnalysisBase' ; import { CommandController } from '../../../commands/commandController' ; import { ConfigOptions } from '../../../common/configOptions' ; import { ConsoleInterface } from '../../../common/console' ; import * as debug from '../../../common/debug' ; import { createDeferred } from '../../../common/deferred' ; import { FileSystem } from '../../../common/fileSystem' ; import { Range } from '../../../common/textRange' ; import { UriParser } from '../../../common/uriParser' ; import { LanguageServerInterface , MessageAction , ServerSettings , WindowInterface , WorkspaceServiceInstance , } from '../../../languageServerBase' ; import { CodeActionProvider } from '../../../languageService/codeActionProvider' ; import { TestAccessHost } from '../testAccessHost' ; import { HostSpecificFeatures } from './testState' ; export class TestFeatures implements HostSpecificFeatures { importResolverFactory : ImportResolverFactory = AnalyzerService . createImportResolver ; runIndexer ( workspace , noStdLib ) { } getCodeActionsForPosition ( workspace , filePath , range , token ) { return CodeActionProvider . getCodeActionsForPosition ( workspace , filePath , range , token ) ; } execute ( ls , params , token ) { const controller = new CommandController ( ls ) ; return controller . execute ( params , token ) ; } } export class TestLanguageService implements LanguageServerInterface { private readonly _workspace : WorkspaceServiceInstance ; private readonly _defaultWorkspace : WorkspaceServiceInstance ; private readonly _uriParser : UriParser ; constructor ( workspace , readonly console , readonly fs ) { this . _workspace = workspace ; this . _uriParser = new UriParser ( this . fs ) ; this . _defaultWorkspace = { workspaceName : '' , rootPath : '' , rootUri : '' , serviceInstance : new AnalyzerService ( 'test service' , this . fs , this . console , ( ) => new TestAccessHost ( ) , AnalyzerService . createImportResolver , new ConfigOptions ( '.' ) ) , disableLanguageServices : false , disableOrganizeImports : false , isInitialized : createDeferred < boolean > ( ) , } ; } decodeTextDocumentUri ( uriString ) { return this . _uriParser . decodeTextDocumentUri ( uriString ) ; } getWorkspaceForFile ( filePath ) { if ( filePath . startsWith ( this . _workspace . rootPath ) ) { return Promise . resolve ( this . _workspace ) ; } return Promise . resolve ( this . _defaultWorkspace ) ; } getSettings ( workspace ) { const settings = { venvPath : this . _workspace . serviceInstance . getConfigOptions ( ) . venvPath , pythonPath : this . _workspace . serviceInstance . getConfigOptions ( ) . pythonPath , typeshedPath : this . _workspace . serviceInstance . getConfigOptions ( ) . typeshedPath , openFilesOnly : this . _workspace . serviceInstance . getConfigOptions ( ) . checkOnlyOpenFiles , useLibraryCodeForTypes : this . _workspace . serviceInstance . getConfigOptions ( ) . useLibraryCodeForTypes , disableLanguageServices : this . _workspace . disableLanguageServices , autoImportCompletions : this . _workspace . serviceInstance . getConfigOptions ( ) . autoImportCompletions , } ; return Promise . resolve ( settings ) ; } createBackgroundAnalysis ( ) { return undefined ; } reanalyze ( ) { } restart ( ) { } readonly rootPath = path . sep ; readonly window = new TestWindow ( ) ; readonly supportAdvancedEdits = true ; } class TestWindow implements WindowInterface { showErrorMessage ( message ) ; showErrorMessage ( message , ... actions ) ; showErrorMessage ( message , ... actions ) { debug . fail ( "shouldn't be called" ) ; } showWarningMessage ( message ) ; showWarningMessage ( message , ... actions ) ; showWarningMessage ( message , ... actions ) { debug . fail ( "shouldn't be called" ) ; } showInformationMessage ( message ) ; showInformationMessage ( message , ... actions ) ; showInformationMessage ( message , ... actions ) { } }