-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathinstantiate.ts
More file actions
159 lines (130 loc) Β· 5.47 KB
/
instantiate.ts
File metadata and controls
159 lines (130 loc) Β· 5.47 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import * as vscode from "vscode";
import { onCodeForIBMiConfigurationChange } from "./config/Configuration";
import Instance from "./Instance";
import { Terminal } from './ui/Terminal';
import { getDebugServiceDetails } from './api/configuration/DebugConfiguration';
import { debugPTFInstalled, isDebugEngineRunning } from './debug/server';
import { setupGitEventHandler } from './filesystems/local/git';
import { registerActionsCommands } from './commands/actions';
import { registerCompareCommands } from './commands/compare';
import { registerConnectionCommands } from './commands/connection';
import { registerOpenCommands } from './commands/open';
import { registerPasswordCommands } from './commands/password';
import { QSysFS } from "./filesystems/qsys/QSysFs";
import { ActionsUI } from './webviews/actions';
import { VariablesUI } from "./webviews/variables";
import IBMi from "./api/IBMi";
export let instance: Instance;
const disconnectBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 12);
disconnectBarItem.command = {
command: `code-for-ibmi.disconnect`,
title: `Disconnect from system`
}
disconnectBarItem.tooltip = `Disconnect from system.`;
disconnectBarItem.text = `$(debug-disconnect)`;
const connectedBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10);
connectedBarItem.command = {
command: `code-for-ibmi.showAdditionalSettings`,
title: `Show connection settings`
};
export async function safeDisconnect(): Promise<boolean> {
let doDisconnect = true;
for (const document of vscode.workspace.textDocuments) {
// This code will check that sources are saved before closing
if (!document.isClosed && [`member`, `streamfile`, `object`].includes(document.uri.scheme)) {
if (document.isDirty) {
if (doDisconnect) {
if (await vscode.window.showTextDocument(document).then(() => vscode.window.showErrorMessage(`Cannot disconnect while files have not been saved.`, 'Disconnect anyway'))) {
break;
}
else {
doDisconnect = false;
}
}
}
}
}
if (doDisconnect) {
await instance.disconnect();
}
return doDisconnect;
}
export async function loadAllofExtension(context: vscode.ExtensionContext) {
// No connection when the extension is first activated
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:connected`, false);
vscode.workspace.getConfiguration().update(`workbench.editor.enablePreview`, false, true);
instance = new Instance(context);
context.subscriptions.push(
connectedBarItem,
disconnectBarItem,
...registerConnectionCommands(context, instance),
onCodeForIBMiConfigurationChange("connectionSettings", updateConnectedBar),
...registerOpenCommands(instance),
...registerCompareCommands(instance),
...registerActionsCommands(instance),
...Terminal.registerTerminalCommands(context),
...registerPasswordCommands(context, instance),
vscode.commands.registerCommand("code-for-ibmi.updateConnectedBar", updateConnectedBar),
);
ActionsUI.initialize(context);
VariablesUI.initialize(context);
instance.subscribe(context, 'connected', 'Load status bars', onConnected);
instance.subscribe(context, 'disconnected', 'Unload status bars', onDisconnected);
context.subscriptions.push(
vscode.workspace.registerFileSystemProvider(`member`, new QSysFS(context), {
isCaseSensitive: false
})
);
// Register git events based on workspace folders
if (vscode.workspace.workspaceFolders) {
setupGitEventHandler(context);
}
}
async function updateConnectedBar() {
const connection = instance.getConnection();
if (connection) {
const config = connection.getConfig();
connectedBarItem.text = `$(${config.readOnlyMode ? "lock" : "settings-gear"}) ${config.name}`;
const debugRunning = await isDebugEngineRunning();
connectedBarItem.tooltip = new vscode.MarkdownString([
`[$(settings-gear) Settings](command:code-for-ibmi.showAdditionalSettings)`,
`[$(file-binary) Actions](command:code-for-ibmi.showActionsMaintenance)`,
`[$(terminal) Terminals](command:code-for-ibmi.launchTerminalPicker)`,
debugPTFInstalled() ?
`[$(${debugRunning ? "bug" : "debug"}) Debugger ${((await getDebugServiceDetails(connection)).version)} (${debugRunning ? "on" : "off"})](command:ibmiDebugBrowser.focus)`
:
`[$(debug) No debug PTF](https://codefori.github.io/docs/developing/debug/#required-ptfs)`
].join(`\n\n---\n\n`), true);
connectedBarItem.tooltip.isTrusted = true;
}
}
async function onConnected() {
const config = instance.getConnection()?.getConfig();
[
connectedBarItem,
disconnectBarItem,
].forEach(barItem => barItem.show());
updateConnectedBar();
// Enable the profile view if profiles exist.
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:hasProfiles`, (config?.connectionProfiles || []).length > 0);
}
async function onDisconnected() {
// Close the tabs with no dirty editors
vscode.window.tabGroups.all
.filter(group => !group.tabs.some(tab => tab.isDirty))
.forEach(group => {
group.tabs.forEach(tab => {
if (tab.input instanceof vscode.TabInputText) {
const uri = tab.input.uri;
if ([`member`, `streamfile`, `object`].includes(uri.scheme)) {
vscode.window.tabGroups.close(tab);
}
}
})
});
// Hide the bar items
[
disconnectBarItem,
connectedBarItem,
].forEach(barItem => barItem.hide())
}