Skip to content

Commit 342f7d3

Browse files
committed
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_frontend_vitest
2 parents f724d3f + 811c59a commit 342f7d3

23 files changed

+389
-274
lines changed

src/Instance.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import * as vscode from "vscode";
22
import { ConnectionData, IBMiEvent } from "./typings";
33
import IBMi, { ConnectionResult } from "./api/IBMi";
44
import { CodeForIStorage } from "./api/configuration/storage/CodeForIStorage";
5-
import { withContext } from "./ui/tools";
65
import { handleConnectionResults, messageCallback } from "./ui/connection";
76
import { VsStorage } from "./config/Storage";
87
import { VsCodeConfig } from "./config/Configuration";
98
import { ConnectionConfig } from "./api/configuration/config/ConnectionManager";
109
import { EventEmitter } from "stream";
1110
import { ConnectionStorage } from "./api/configuration/storage/ConnectionStorage";
11+
import { VscodeTools } from "./ui/vscodeTools";
1212

1313
type IBMiEventSubscription = {
1414
func: Function,
@@ -26,7 +26,19 @@ export interface ConnectionOptions {
2626

2727
export default class Instance {
2828
private connection: IBMi | undefined;
29-
private outputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(`Code for IBM i`);
29+
30+
private output = {
31+
channel: vscode.window.createOutputChannel(`Code for IBM i`),
32+
content: ``,
33+
writeCount: 0
34+
};
35+
36+
private resetOutput() {
37+
this.output.channel.clear();
38+
this.output.content = ``;
39+
this.output.writeCount = 0;
40+
}
41+
3042
private storage: ConnectionStorage;
3143
private emitter: vscode.EventEmitter<IBMiEvent> = new vscode.EventEmitter();
3244
private subscribers: Map<IBMiEvent, SubscriptionMap> = new Map;
@@ -45,9 +57,14 @@ export default class Instance {
4557
connect(options: ConnectionOptions): Promise<ConnectionResult> {
4658
const connection = new IBMi();
4759

48-
this.outputChannel.clear();
60+
this.resetOutput();
4961
connection.appendOutput = (message) => {
50-
this.outputChannel.append(message);
62+
if (this.output.writeCount > 150) {
63+
this.resetOutput();
64+
}
65+
66+
this.output.channel.append(message);
67+
this.output.writeCount++;
5168
}
5269

5370
let result: ConnectionResult;
@@ -62,13 +79,12 @@ export default class Instance {
6279
let reconnect = choice === `Yes`;
6380
let collectLogs = choice === `No, get logs`;
6481

65-
// TODO: how to get output channel stuff?
66-
// if (collectLogs) {
67-
// const logs = conn.getOutputChannelContent();
68-
// vscode.workspace.openTextDocument({ content: logs, language: `plaintext` }).then(doc => {
69-
// vscode.window.showTextDocument(doc);
70-
// });
71-
// }
82+
if (collectLogs) {
83+
const logs = this.output.content;
84+
vscode.workspace.openTextDocument({ content: logs, language: `plaintext` }).then(doc => {
85+
vscode.window.showTextDocument(doc);
86+
});
87+
}
7288

7389
this.disconnect();
7490

@@ -78,7 +94,7 @@ export default class Instance {
7894
}
7995
};
8096

81-
return withContext("code-for-ibmi:connecting", async () => {
97+
return VscodeTools.withContext("code-for-ibmi:connecting", async () => {
8298
while (true) {
8399
let customError: string|undefined;
84100
await vscode.window.withProgress({location: vscode.ProgressLocation.Notification, title: options.data.name, cancellable: true}, async (p, cancelToken) => {

src/api/IBMiContent.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FilterType, parseFilter, singleGenericName } from './Filter';
1010
import { default as IBMi } from './IBMi';
1111
import { Tools } from './Tools';
1212
import { ObjectTypes } from './import/Objects';
13+
import { EditorPath } from '../typings';
1314
const tmpFile = util.promisify(tmp.file);
1415
const readFileAsync = util.promisify(fs.readFile);
1516
const writeFileAsync = util.promisify(fs.writeFile);
@@ -1043,19 +1044,19 @@ export default class IBMiContent {
10431044
}
10441045
}
10451046

1046-
async uploadFiles(files: { local: string, remote: string }[], options?: node_ssh.SSHPutFilesOptions) {
1047-
await this.ibmi.client!.putFiles(files.map(f => { return { local: f.local, remote: f.remote } }), options);
1047+
async uploadFiles(files: { local: EditorPath, remote: string }[], options?: node_ssh.SSHPutFilesOptions) {
1048+
await this.ibmi.client!.putFiles(files.map(f => { return { local: Tools.fileToPath(f.local), remote: f.remote } }), options);
10481049
}
10491050

1050-
async downloadFile(localFile: string, remoteFile: string) {
1051-
await this.ibmi.client!.getFile(localFile, remoteFile);
1051+
async downloadFile(localFile: EditorPath, remoteFile: string) {
1052+
await this.ibmi.client!.getFile(Tools.fileToPath(localFile), remoteFile);
10521053
}
10531054

1054-
async uploadDirectory(localDirectory: string, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
1055-
await this.ibmi.client!.putDirectory(localDirectory, remoteDirectory, options);
1055+
async uploadDirectory(localDirectory: EditorPath, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
1056+
await this.ibmi.client!.putDirectory(Tools.fileToPath(localDirectory), remoteDirectory, options);
10561057
}
10571058

1058-
async downloadDirectory(localDirectory: string, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
1059-
await this.ibmi.client!.getDirectory(localDirectory, remoteDirectory, options);
1059+
async downloadDirectory(localDirectory: EditorPath, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
1060+
await this.ibmi.client!.getDirectory(Tools.fileToPath(localDirectory), remoteDirectory, options);
10601061
}
10611062
}

src/api/Tools.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os from "os";
33
import path from "path";
44
import { IBMiMessage, IBMiMessages, QsysPath } from './types';
5+
import { EditorPath } from "../typings";
56

67
export namespace Tools {
78
export class SqlError extends Error {
@@ -298,6 +299,15 @@ export namespace Tools {
298299
return statements;
299300
}
300301

302+
export function fileToPath(file: EditorPath): string {
303+
if (typeof file === "string") {
304+
return Tools.fixWindowsPath(file);
305+
}
306+
else {
307+
return file.fsPath;
308+
}
309+
}
310+
301311
export function fixWindowsPath(path: string) {
302312
if (process.platform === `win32` && path[0] === `/`) {
303313
//Issue with getFile not working propertly on Windows

src/api/tests/config.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"connectionSettings": [
3+
{
4+
"name": "testsystem",
5+
"host": "",
6+
"objectFilters": [],
7+
"libraryList": [
8+
"QGPL",
9+
"QTEMP",
10+
"QDEVELOP",
11+
"QBLDSYS",
12+
"QBLDSYSR"
13+
],
14+
"autoClearTempData": false,
15+
"customVariables": [],
16+
"connectionProfiles": [],
17+
"commandProfiles": [],
18+
"ifsShortcuts": [
19+
"/home/LIAMA"
20+
],
21+
"autoSortIFSShortcuts": false,
22+
"homeDirectory": "/home/LIAMA",
23+
"tempLibrary": "ILEDITOR",
24+
"tempDir": "/tmp",
25+
"currentLibrary": "QGPL",
26+
"sourceASP": "",
27+
"sourceFileCCSID": "*FILE",
28+
"autoConvertIFSccsid": false,
29+
"hideCompileErrors": [],
30+
"enableSourceDates": false,
31+
"sourceDateMode": "diff",
32+
"sourceDateGutter": false,
33+
"encodingFor5250": "default",
34+
"terminalFor5250": "default",
35+
"setDeviceNameFor5250": false,
36+
"connectringStringFor5250": "localhost",
37+
"autoSaveBeforeAction": false,
38+
"showDescInLibList": false,
39+
"debugPort": "8005",
40+
"debugSepPort": "8008",
41+
"debugUpdateProductionFiles": false,
42+
"debugEnableDebugTracing": false,
43+
"readOnlyMode": false,
44+
"quickConnect": true,
45+
"defaultDeploymentMethod": "",
46+
"protectedPaths": [],
47+
"showHiddenFiles": true,
48+
"lastDownloadLocation": "/Users/barry"
49+
}
50+
]
51+
}

src/api/tests/storage.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"serverSettingsCache_testsystem": {
3+
"aspInfo": {},
4+
"qccsid": 65535,
5+
"jobCcsid": 37,
6+
"remoteFeatures": {
7+
"git": "/QOpenSys/pkgs/bin/git",
8+
"grep": "/QOpenSys/pkgs/bin/grep",
9+
"tn5250": "/QOpenSys/pkgs/bin/tn5250",
10+
"setccsid": "/usr/bin/setccsid",
11+
"md5sum": "/QOpenSys/pkgs/bin/md5sum",
12+
"bash": "/QOpenSys/pkgs/bin/bash",
13+
"chsh": "/QOpenSys/pkgs/bin/chsh",
14+
"stat": "/QOpenSys/pkgs/bin/stat",
15+
"sort": "/QOpenSys/pkgs/bin/sort",
16+
"GETNEWLIBL.PGM": "/QSYS.lib/ILEDITOR.lib/GETNEWLIBL.PGM",
17+
"QZDFMDB2.PGM": "/QSYS.LIB/QZDFMDB2.PGM",
18+
"startDebugService.sh": "/QIBM/ProdData/IBMiDebugService/bin/startDebugService.sh",
19+
"attr": "/usr/bin/attr",
20+
"iconv": "/usr/bin/iconv",
21+
"tar": "/QOpenSys/pkgs/bin/tar",
22+
"ls": "/QOpenSys/pkgs/bin/ls",
23+
"find": "/QOpenSys/pkgs/bin/find",
24+
"jdk80": "/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit",
25+
"jdk11": "/QOpenSys/QIBM/ProdData/JavaVM/jdk11/64bit",
26+
"jdk17": "/QOpenSys/QIBM/ProdData/JavaVM/jdk17/64bit",
27+
"openjdk11": "/QOpensys/pkgs/lib/jvm/openjdk-11",
28+
"uname": "/usr/bin/uname"
29+
},
30+
"remoteFeaturesKeys": "GETMBRINFO.SQL,GETNEWLIBL.PGM,QZDFMDB2.PGM,attr,bash,chsh,find,git,grep,iconv,jdk11,jdk17,jdk80,ls,md5sum,openjdk11,setccsid,sort,startDebugService.sh,stat,tar,tn5250,uname",
31+
"badDataAreasChecked": true,
32+
"libraryListValidated": true,
33+
"pathChecked": true,
34+
"userDefaultCCSID": 37,
35+
"debugConfigLoaded": false,
36+
"maximumArgsLength": 4191784
37+
}
38+
}

src/commands/open.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Instance from "../Instance";
44
import { Tools } from "../api/Tools";
55
import { getUriFromPath, parseFSOptions } from "../filesystems/qsys/QSysFs";
66
import path from "path";
7-
import { findExistingDocument, findExistingDocumentUri } from "../ui/tools";
7+
import { VscodeTools } from "../ui/vscodeTools";
88
import IBMi from "../api/IBMi";
99
import { DefaultOpenMode } from "../api/configuration/config/ConnectionManager";
1010

@@ -36,7 +36,7 @@ export function registerOpenCommands(instance: Instance): Disposable[] {
3636

3737
const uri = getUriFromPath(path, options);
3838

39-
const existingUri = findExistingDocumentUri(uri);
39+
const existingUri = VscodeTools.findExistingDocumentUri(uri);
4040

4141
if (existingUri) {
4242
const existingOptions = parseFSOptions(existingUri);
@@ -89,7 +89,7 @@ export function registerOpenCommands(instance: Instance): Disposable[] {
8989
commands.registerCommand("code-for-ibmi.refreshFile", async (uri?: Uri) => {
9090
let doc: TextDocument | undefined;
9191
if (uri) {
92-
doc = findExistingDocument(uri);
92+
doc = VscodeTools.findExistingDocument(uri);
9393
} else {
9494
const editor = window.activeTextEditor;
9595
doc = editor?.document;

src/debug/certificates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { instance } from '../instantiate';
88
import IBMi from "../api/IBMi";
99
import IBMiContent from '../api/IBMiContent';
1010
import { Tools } from '../api/Tools';
11-
import { fileToPath } from '../ui/tools';
11+
import { VscodeTools } from '../ui/vscodeTools';
1212
import { DebugConfiguration, SERVICE_CERTIFICATE, CLIENT_CERTIFICATE, getDebugServiceDetails, getJavaHome, DEBUG_CONFIG_FILE, LEGACY_CERT_DIRECTORY } from '../api/configuration/DebugConfiguration';
1313

1414
type HostInfo = {
@@ -106,7 +106,7 @@ export async function setup(connection: IBMi, imported?: ImportedCertificate) {
106106
password = imported.password;
107107
if (imported.localFile) {
108108
setProgress("importing local certificate");
109-
await connection.getContent().uploadFiles([{ local: fileToPath(imported.localFile), remote: debugConfig.getRemoteServiceCertificatePath() }]);
109+
await connection.getContent().uploadFiles([{ local: imported.localFile, remote: debugConfig.getRemoteServiceCertificatePath() }]);
110110
}
111111
else if (imported.remoteFile) {
112112
setProgress("importing remote certificate");

src/debug/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Env, getEnvConfig } from "../filesystems/local/env";
1111
import * as certificates from "./certificates";
1212
import { DEBUG_CONFIG_FILE, DebugConfiguration, getDebugServiceDetails, resetDebugServiceDetails } from "../api/configuration/DebugConfiguration";
1313
import * as server from "./server";
14-
import { withContext } from "../ui/tools";
14+
import { VscodeTools } from "../ui/vscodeTools";
1515
import { getStoredPassword } from "../config/passwords";
1616

1717
const debugExtensionId = `IBM.ibmidebug`;
@@ -257,7 +257,7 @@ export async function initialize(context: ExtensionContext) {
257257
if (connection) {
258258
const doSetup = await vscode.window.showWarningMessage(`Do you confirm you want to generate or import a new certificate for the Debug Service?`, { modal: true }, 'Generate', 'Import');
259259
if (doSetup) {
260-
withContext("code-for-ibmi:debugWorking", async () => {
260+
VscodeTools.withContext("code-for-ibmi:debugWorking", async () => {
261261
if (!(await server.getDebugServiceJob()) || await server.stopService(connection)) {
262262
const debugConfig = await new DebugConfiguration(connection).load();
263263
const clearResult = await connection.sendCommand({ command: `rm -f ${debugConfig.getRemoteServiceCertificatePath()} ${debugConfig.getRemoteClientCertificatePath()}` });
@@ -276,7 +276,7 @@ export async function initialize(context: ExtensionContext) {
276276
}
277277
}),
278278
vscode.commands.registerCommand(`code-for-ibmi.debug.setup.remote`, (doSetup?: 'Generate' | 'Import') =>
279-
withContext("code-for-ibmi:debugWorking", async () => {
279+
VscodeTools.withContext("code-for-ibmi:debugWorking", async () => {
280280
const connection = instance.getConnection();
281281
if (connection) {
282282
const ptfInstalled = server.debugPTFInstalled();
@@ -336,7 +336,7 @@ export async function initialize(context: ExtensionContext) {
336336

337337
vscode.commands.registerCommand(`code-for-ibmi.debug.setup.local`, () =>
338338
vscode.window.withProgress({ title: "Downloading Debug Service Certificate", location: vscode.ProgressLocation.Window }, async () =>
339-
await withContext("code-for-ibmi:debugWorking", async () => {
339+
await VscodeTools.withContext("code-for-ibmi:debugWorking", async () => {
340340
const connection = instance.getConnection();
341341
if (connection) {
342342
const ptfInstalled = server.debugPTFInstalled();

src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { SettingsUI } from "./webviews/settings";
3434
import { registerActionTools } from "./ui/actions";
3535
import IBMi from "./api/IBMi";
3636
import path from "path";
37+
import { VscodeTools } from "./ui/vscodeTools";
3738

3839
export async function activate(context: ExtensionContext): Promise<CodeForIBMi> {
3940
// Use the console to output diagnostic information (console.log) and errors (console.error)
@@ -126,6 +127,7 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
126127
deployTools: DeployTools,
127128
evfeventParser: parseErrors,
128129
tools: Tools,
130+
vscodeTools: VscodeTools,
129131
componentRegistry: extensionComponentRegistry
130132
};
131133
}

src/filesystems/local/deployTools.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import vscode, { Uri, WorkspaceFolder } from 'vscode';
44
import { instance } from '../../instantiate';
55
import { LocalLanguageActions } from './LocalLanguageActions';
66
import { Deployment } from './deployment';
7-
import { getGitAPI, md5Hash } from '../../ui/tools';
7+
import { VscodeTools } from '../../ui/vscodeTools';
88
import { DeploymentMethod } from '../../api/types';
99
import { DeploymentParameters } from '../../typings';
1010

@@ -68,7 +68,7 @@ export namespace DeployTools {
6868
const changes = Deployment.workspaceChanges.get(folder)?.size || 0;
6969
methods.push({ method: "changed" as DeploymentMethod, label: `Changes`, description: `${changes} change${changes > 1 ? `s` : ``} detected since last upload. ${!changes ? `Will skip deploy step.` : ``}` });
7070

71-
if (getGitAPI()) {
71+
if (VscodeTools.getGitAPI()) {
7272
methods.push(
7373
{ method: "unstaged" as DeploymentMethod, label: `Working Changes`, description: `Unstaged changes in git` },
7474
{ method: "staged" as DeploymentMethod, label: `Staged Changes`, description: `` }
@@ -216,7 +216,7 @@ export namespace DeployTools {
216216

217217
export async function getDeployGitFiles(parameters: DeploymentParameters, changeType: 'staged' | 'working'): Promise<vscode.Uri[]> {
218218
const useStagedChanges = (changeType == 'staged');
219-
const gitApi = getGitAPI();
219+
const gitApi = VscodeTools.getGitAPI();
220220

221221
if (gitApi && gitApi.repositories.length > 0) {
222222
const repository = gitApi.repositories.find(r => r.rootUri.fsPath === parameters.workspaceFolder.uri.fsPath);
@@ -274,7 +274,7 @@ export namespace DeployTools {
274274
const uploads: vscode.Uri[] = [];
275275
for await (const file of localFiles) {
276276
const remote = remoteMD5.find(e => e.path === file.path);
277-
const md5 = md5Hash(file.uri);
277+
const md5 = VscodeTools.md5Hash(file.uri);
278278
if (!remote || remote.md5 !== md5) {
279279
uploads.push(file.uri);
280280
}

src/filesystems/local/git.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { getBranchLibraryName } from "./env";
33
import { instance } from "../../instantiate";
44
import IBMi from "../../api/IBMi";
55
import IBMiContent from "../../api/IBMiContent";
6-
import { getGitAPI } from "../../ui/tools";
6+
import { VscodeTools } from "../../ui/vscodeTools";
77
import { ConnectionConfig } from "../../api/configuration/config/ConnectionManager";
88

99
const lastBranch: { [workspaceUri: string]: string } = {};
1010

1111
export function getGitBranch(workspaceFolder: WorkspaceFolder) {
12-
const gitApi = getGitAPI();
12+
const gitApi = VscodeTools.getGitAPI();
1313
if (gitApi) {
1414
const repo = gitApi.getRepository(workspaceFolder.uri);
1515
if (repo) {
@@ -19,7 +19,7 @@ export function getGitBranch(workspaceFolder: WorkspaceFolder) {
1919
}
2020

2121
export function setupGitEventHandler(context: ExtensionContext) {
22-
const gitApi = getGitAPI();
22+
const gitApi = VscodeTools.getGitAPI();
2323

2424
if (gitApi) {
2525
gitApi.onDidOpenRepository((repo) => {

0 commit comments

Comments
 (0)