forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
djangoShellCodeExecution.ts
64 lines (57 loc) · 3.09 KB
/
djangoShellCodeExecution.ts
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { Disposable, Uri } from 'vscode';
import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../common/application/types';
import '../../common/extensions';
import { IFileSystem, IPlatformService } from '../../common/platform/types';
import { ITerminalServiceFactory } from '../../common/terminal/types';
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
import { IInterpreterService } from '../../interpreter/contracts';
import { copyPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
import { DjangoContextInitializer } from './djangoContext';
import { TerminalCodeExecutionProvider } from './terminalCodeExecution';
@injectable()
export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvider {
constructor(
@inject(ITerminalServiceFactory) terminalServiceFactory: ITerminalServiceFactory,
@inject(IConfigurationService) configurationService: IConfigurationService,
@inject(IWorkspaceService) workspace: IWorkspaceService,
@inject(IDocumentManager) documentManager: IDocumentManager,
@inject(IPlatformService) platformService: IPlatformService,
@inject(ICommandManager) commandManager: ICommandManager,
@inject(IFileSystem) fileSystem: IFileSystem,
@inject(IDisposableRegistry) disposableRegistry: Disposable[],
@inject(IInterpreterService) interpreterService: IInterpreterService,
) {
super(
terminalServiceFactory,
configurationService,
workspace,
disposableRegistry,
platformService,
interpreterService,
commandManager,
);
this.terminalTitle = 'Django Shell';
disposableRegistry.push(new DjangoContextInitializer(documentManager, workspace, fileSystem, commandManager));
}
public async getExecutableInfo(resource?: Uri, args: string[] = []): Promise<PythonExecInfo> {
const info = await super.getExecutableInfo(resource, args);
const workspaceUri = resource ? this.workspace.getWorkspaceFolder(resource) : undefined;
const defaultWorkspace =
Array.isArray(this.workspace.workspaceFolders) && this.workspace.workspaceFolders.length > 0
? this.workspace.workspaceFolders[0].uri.fsPath
: '';
const workspaceRoot = workspaceUri ? workspaceUri.uri.fsPath : defaultWorkspace;
const managePyPath = workspaceRoot.length === 0 ? 'manage.py' : path.join(workspaceRoot, 'manage.py');
return copyPythonExecInfo(info, [managePyPath.fileToCommandArgumentForPythonExt(), 'shell']);
}
public async getExecuteFileArgs(resource?: Uri, executeArgs: string[] = []): Promise<PythonExecInfo> {
// We need the executable info but not the 'manage.py shell' args
const info = await super.getExecutableInfo(resource);
return copyPythonExecInfo(info, executeArgs);
}
}