forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathjediLSExtensionManager.ts
More file actions
97 lines (86 loc) · 3.66 KB
/
jediLSExtensionManager.ts
File metadata and controls
97 lines (86 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { JediLanguageServerAnalysisOptions } from '../activation/jedi/analysisOptions';
import { JediLanguageClientFactory } from '../activation/jedi/languageClientFactory';
import { JediLanguageServerProxy } from '../activation/jedi/languageServerProxy';
import { JediLanguageServerManager } from '../activation/jedi/manager';
import { ILanguageServerOutputChannel } from '../activation/types';
import { IWorkspaceService, ICommandManager } from '../common/application/types';
import {
IExperimentService,
IInterpreterPathService,
IConfigurationService,
Resource,
IDisposable,
} from '../common/types';
import { IEnvironmentVariablesProvider } from '../common/variables/types';
import { IInterpreterService } from '../interpreter/contracts';
import { IServiceContainer } from '../ioc/types';
import { traceError } from '../logging';
import { PythonEnvironment } from '../pythonEnvironments/info';
import { ILanguageServerExtensionManager } from './types';
export class JediLSExtensionManager implements IDisposable, ILanguageServerExtensionManager {
private serverProxy: JediLanguageServerProxy;
serverManager: JediLanguageServerManager;
clientFactory: JediLanguageClientFactory;
analysisOptions: JediLanguageServerAnalysisOptions;
constructor(
serviceContainer: IServiceContainer,
outputChannel: ILanguageServerOutputChannel,
_experimentService: IExperimentService,
workspaceService: IWorkspaceService,
configurationService: IConfigurationService,
_interpreterPathService: IInterpreterPathService,
interpreterService: IInterpreterService,
environmentService: IEnvironmentVariablesProvider,
commandManager: ICommandManager,
) {
this.analysisOptions = new JediLanguageServerAnalysisOptions(
environmentService,
outputChannel,
configurationService,
workspaceService,
);
this.clientFactory = new JediLanguageClientFactory(
interpreterService,
workspaceService.getConfiguration('python'),
);
this.serverProxy = new JediLanguageServerProxy(this.clientFactory);
this.serverManager = new JediLanguageServerManager(
serviceContainer,
this.analysisOptions,
this.serverProxy,
commandManager,
);
}
dispose(): void {
this.serverManager.disconnect();
this.serverManager.dispose();
this.serverProxy.dispose();
this.analysisOptions.dispose();
}
async startLanguageServer(resource: Resource, interpreter?: PythonEnvironment): Promise<void> {
await this.serverManager.start(resource, interpreter);
this.serverManager.connect();
}
async stopLanguageServer(): Promise<void> {
this.serverManager.disconnect();
await this.serverProxy.stop();
}
// eslint-disable-next-line class-methods-use-this
canStartLanguageServer(interpreter: PythonEnvironment | undefined): boolean {
if (!interpreter) {
traceError('Unable to start Jedi language server as a valid interpreter is not selected');
return false;
}
// Otherwise return true for now since it's shipped with the extension.
// Update this when JediLSP is pulled in a separate extension.
return true;
}
// eslint-disable-next-line class-methods-use-this
languageServerNotAvailable(): Promise<void> {
// Nothing to do here.
// Update this when JediLSP is pulled in a separate extension.
return Promise.resolve();
}
}