Skip to content

Commit

Permalink
Merge branch 'cleanup/seperate_frontend' into cleanup/seperate_fronte…
Browse files Browse the repository at this point in the history
…nd_vitest
  • Loading branch information
worksofliam committed Jan 17, 2025
2 parents f724d3f + 811c59a commit 342f7d3
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 274 deletions.
40 changes: 28 additions & 12 deletions src/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as vscode from "vscode";
import { ConnectionData, IBMiEvent } from "./typings";
import IBMi, { ConnectionResult } from "./api/IBMi";
import { CodeForIStorage } from "./api/configuration/storage/CodeForIStorage";
import { withContext } from "./ui/tools";
import { handleConnectionResults, messageCallback } from "./ui/connection";
import { VsStorage } from "./config/Storage";
import { VsCodeConfig } from "./config/Configuration";
import { ConnectionConfig } from "./api/configuration/config/ConnectionManager";
import { EventEmitter } from "stream";
import { ConnectionStorage } from "./api/configuration/storage/ConnectionStorage";
import { VscodeTools } from "./ui/vscodeTools";

type IBMiEventSubscription = {
func: Function,
Expand All @@ -26,7 +26,19 @@ export interface ConnectionOptions {

export default class Instance {
private connection: IBMi | undefined;
private outputChannel: vscode.OutputChannel = vscode.window.createOutputChannel(`Code for IBM i`);

private output = {
channel: vscode.window.createOutputChannel(`Code for IBM i`),
content: ``,
writeCount: 0
};

private resetOutput() {
this.output.channel.clear();
this.output.content = ``;
this.output.writeCount = 0;
}

private storage: ConnectionStorage;
private emitter: vscode.EventEmitter<IBMiEvent> = new vscode.EventEmitter();
private subscribers: Map<IBMiEvent, SubscriptionMap> = new Map;
Expand All @@ -45,9 +57,14 @@ export default class Instance {
connect(options: ConnectionOptions): Promise<ConnectionResult> {
const connection = new IBMi();

this.outputChannel.clear();
this.resetOutput();
connection.appendOutput = (message) => {
this.outputChannel.append(message);
if (this.output.writeCount > 150) {
this.resetOutput();
}

this.output.channel.append(message);
this.output.writeCount++;
}

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

// TODO: how to get output channel stuff?
// if (collectLogs) {
// const logs = conn.getOutputChannelContent();
// vscode.workspace.openTextDocument({ content: logs, language: `plaintext` }).then(doc => {
// vscode.window.showTextDocument(doc);
// });
// }
if (collectLogs) {
const logs = this.output.content;
vscode.workspace.openTextDocument({ content: logs, language: `plaintext` }).then(doc => {
vscode.window.showTextDocument(doc);
});
}

this.disconnect();

Expand All @@ -78,7 +94,7 @@ export default class Instance {
}
};

return withContext("code-for-ibmi:connecting", async () => {
return VscodeTools.withContext("code-for-ibmi:connecting", async () => {
while (true) {
let customError: string|undefined;
await vscode.window.withProgress({location: vscode.ProgressLocation.Notification, title: options.data.name, cancellable: true}, async (p, cancelToken) => {
Expand Down
17 changes: 9 additions & 8 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FilterType, parseFilter, singleGenericName } from './Filter';
import { default as IBMi } from './IBMi';
import { Tools } from './Tools';
import { ObjectTypes } from './import/Objects';
import { EditorPath } from '../typings';
const tmpFile = util.promisify(tmp.file);
const readFileAsync = util.promisify(fs.readFile);
const writeFileAsync = util.promisify(fs.writeFile);
Expand Down Expand Up @@ -1043,19 +1044,19 @@ export default class IBMiContent {
}
}

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

async downloadFile(localFile: string, remoteFile: string) {
await this.ibmi.client!.getFile(localFile, remoteFile);
async downloadFile(localFile: EditorPath, remoteFile: string) {
await this.ibmi.client!.getFile(Tools.fileToPath(localFile), remoteFile);
}

async uploadDirectory(localDirectory: string, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
await this.ibmi.client!.putDirectory(localDirectory, remoteDirectory, options);
async uploadDirectory(localDirectory: EditorPath, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
await this.ibmi.client!.putDirectory(Tools.fileToPath(localDirectory), remoteDirectory, options);
}

async downloadDirectory(localDirectory: string, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
await this.ibmi.client!.getDirectory(localDirectory, remoteDirectory, options);
async downloadDirectory(localDirectory: EditorPath, remoteDirectory: string, options?: node_ssh.SSHGetPutDirectoryOptions) {
await this.ibmi.client!.getDirectory(Tools.fileToPath(localDirectory), remoteDirectory, options);
}
}
10 changes: 10 additions & 0 deletions src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os from "os";
import path from "path";
import { IBMiMessage, IBMiMessages, QsysPath } from './types';
import { EditorPath } from "../typings";

export namespace Tools {
export class SqlError extends Error {
Expand Down Expand Up @@ -298,6 +299,15 @@ export namespace Tools {
return statements;
}

export function fileToPath(file: EditorPath): string {
if (typeof file === "string") {
return Tools.fixWindowsPath(file);
}
else {
return file.fsPath;
}
}

export function fixWindowsPath(path: string) {
if (process.platform === `win32` && path[0] === `/`) {
//Issue with getFile not working propertly on Windows
Expand Down
51 changes: 51 additions & 0 deletions src/api/tests/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"connectionSettings": [
{
"name": "testsystem",
"host": "",
"objectFilters": [],
"libraryList": [
"QGPL",
"QTEMP",
"QDEVELOP",
"QBLDSYS",
"QBLDSYSR"
],
"autoClearTempData": false,
"customVariables": [],
"connectionProfiles": [],
"commandProfiles": [],
"ifsShortcuts": [
"/home/LIAMA"
],
"autoSortIFSShortcuts": false,
"homeDirectory": "/home/LIAMA",
"tempLibrary": "ILEDITOR",
"tempDir": "/tmp",
"currentLibrary": "QGPL",
"sourceASP": "",
"sourceFileCCSID": "*FILE",
"autoConvertIFSccsid": false,
"hideCompileErrors": [],
"enableSourceDates": false,
"sourceDateMode": "diff",
"sourceDateGutter": false,
"encodingFor5250": "default",
"terminalFor5250": "default",
"setDeviceNameFor5250": false,
"connectringStringFor5250": "localhost",
"autoSaveBeforeAction": false,
"showDescInLibList": false,
"debugPort": "8005",
"debugSepPort": "8008",
"debugUpdateProductionFiles": false,
"debugEnableDebugTracing": false,
"readOnlyMode": false,
"quickConnect": true,
"defaultDeploymentMethod": "",
"protectedPaths": [],
"showHiddenFiles": true,
"lastDownloadLocation": "/Users/barry"
}
]
}
38 changes: 38 additions & 0 deletions src/api/tests/storage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"serverSettingsCache_testsystem": {
"aspInfo": {},
"qccsid": 65535,
"jobCcsid": 37,
"remoteFeatures": {
"git": "/QOpenSys/pkgs/bin/git",
"grep": "/QOpenSys/pkgs/bin/grep",
"tn5250": "/QOpenSys/pkgs/bin/tn5250",
"setccsid": "/usr/bin/setccsid",
"md5sum": "/QOpenSys/pkgs/bin/md5sum",
"bash": "/QOpenSys/pkgs/bin/bash",
"chsh": "/QOpenSys/pkgs/bin/chsh",
"stat": "/QOpenSys/pkgs/bin/stat",
"sort": "/QOpenSys/pkgs/bin/sort",
"GETNEWLIBL.PGM": "/QSYS.lib/ILEDITOR.lib/GETNEWLIBL.PGM",
"QZDFMDB2.PGM": "/QSYS.LIB/QZDFMDB2.PGM",
"startDebugService.sh": "/QIBM/ProdData/IBMiDebugService/bin/startDebugService.sh",
"attr": "/usr/bin/attr",
"iconv": "/usr/bin/iconv",
"tar": "/QOpenSys/pkgs/bin/tar",
"ls": "/QOpenSys/pkgs/bin/ls",
"find": "/QOpenSys/pkgs/bin/find",
"jdk80": "/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit",
"jdk11": "/QOpenSys/QIBM/ProdData/JavaVM/jdk11/64bit",
"jdk17": "/QOpenSys/QIBM/ProdData/JavaVM/jdk17/64bit",
"openjdk11": "/QOpensys/pkgs/lib/jvm/openjdk-11",
"uname": "/usr/bin/uname"
},
"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",
"badDataAreasChecked": true,
"libraryListValidated": true,
"pathChecked": true,
"userDefaultCCSID": 37,
"debugConfigLoaded": false,
"maximumArgsLength": 4191784
}
}
6 changes: 3 additions & 3 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Instance from "../Instance";
import { Tools } from "../api/Tools";
import { getUriFromPath, parseFSOptions } from "../filesystems/qsys/QSysFs";
import path from "path";
import { findExistingDocument, findExistingDocumentUri } from "../ui/tools";
import { VscodeTools } from "../ui/vscodeTools";
import IBMi from "../api/IBMi";
import { DefaultOpenMode } from "../api/configuration/config/ConnectionManager";

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

const uri = getUriFromPath(path, options);

const existingUri = findExistingDocumentUri(uri);
const existingUri = VscodeTools.findExistingDocumentUri(uri);

if (existingUri) {
const existingOptions = parseFSOptions(existingUri);
Expand Down Expand Up @@ -89,7 +89,7 @@ export function registerOpenCommands(instance: Instance): Disposable[] {
commands.registerCommand("code-for-ibmi.refreshFile", async (uri?: Uri) => {
let doc: TextDocument | undefined;
if (uri) {
doc = findExistingDocument(uri);
doc = VscodeTools.findExistingDocument(uri);
} else {
const editor = window.activeTextEditor;
doc = editor?.document;
Expand Down
4 changes: 2 additions & 2 deletions src/debug/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { instance } from '../instantiate';
import IBMi from "../api/IBMi";
import IBMiContent from '../api/IBMiContent';
import { Tools } from '../api/Tools';
import { fileToPath } from '../ui/tools';
import { VscodeTools } from '../ui/vscodeTools';
import { DebugConfiguration, SERVICE_CERTIFICATE, CLIENT_CERTIFICATE, getDebugServiceDetails, getJavaHome, DEBUG_CONFIG_FILE, LEGACY_CERT_DIRECTORY } from '../api/configuration/DebugConfiguration';

type HostInfo = {
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function setup(connection: IBMi, imported?: ImportedCertificate) {
password = imported.password;
if (imported.localFile) {
setProgress("importing local certificate");
await connection.getContent().uploadFiles([{ local: fileToPath(imported.localFile), remote: debugConfig.getRemoteServiceCertificatePath() }]);
await connection.getContent().uploadFiles([{ local: imported.localFile, remote: debugConfig.getRemoteServiceCertificatePath() }]);
}
else if (imported.remoteFile) {
setProgress("importing remote certificate");
Expand Down
8 changes: 4 additions & 4 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Env, getEnvConfig } from "../filesystems/local/env";
import * as certificates from "./certificates";
import { DEBUG_CONFIG_FILE, DebugConfiguration, getDebugServiceDetails, resetDebugServiceDetails } from "../api/configuration/DebugConfiguration";
import * as server from "./server";
import { withContext } from "../ui/tools";
import { VscodeTools } from "../ui/vscodeTools";
import { getStoredPassword } from "../config/passwords";

const debugExtensionId = `IBM.ibmidebug`;
Expand Down Expand Up @@ -257,7 +257,7 @@ export async function initialize(context: ExtensionContext) {
if (connection) {
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');
if (doSetup) {
withContext("code-for-ibmi:debugWorking", async () => {
VscodeTools.withContext("code-for-ibmi:debugWorking", async () => {
if (!(await server.getDebugServiceJob()) || await server.stopService(connection)) {
const debugConfig = await new DebugConfiguration(connection).load();
const clearResult = await connection.sendCommand({ command: `rm -f ${debugConfig.getRemoteServiceCertificatePath()} ${debugConfig.getRemoteClientCertificatePath()}` });
Expand All @@ -276,7 +276,7 @@ export async function initialize(context: ExtensionContext) {
}
}),
vscode.commands.registerCommand(`code-for-ibmi.debug.setup.remote`, (doSetup?: 'Generate' | 'Import') =>
withContext("code-for-ibmi:debugWorking", async () => {
VscodeTools.withContext("code-for-ibmi:debugWorking", async () => {
const connection = instance.getConnection();
if (connection) {
const ptfInstalled = server.debugPTFInstalled();
Expand Down Expand Up @@ -336,7 +336,7 @@ export async function initialize(context: ExtensionContext) {

vscode.commands.registerCommand(`code-for-ibmi.debug.setup.local`, () =>
vscode.window.withProgress({ title: "Downloading Debug Service Certificate", location: vscode.ProgressLocation.Window }, async () =>
await withContext("code-for-ibmi:debugWorking", async () => {
await VscodeTools.withContext("code-for-ibmi:debugWorking", async () => {
const connection = instance.getConnection();
if (connection) {
const ptfInstalled = server.debugPTFInstalled();
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { SettingsUI } from "./webviews/settings";
import { registerActionTools } from "./ui/actions";
import IBMi from "./api/IBMi";
import path from "path";
import { VscodeTools } from "./ui/vscodeTools";

export async function activate(context: ExtensionContext): Promise<CodeForIBMi> {
// Use the console to output diagnostic information (console.log) and errors (console.error)
Expand Down Expand Up @@ -126,6 +127,7 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
deployTools: DeployTools,
evfeventParser: parseErrors,
tools: Tools,
vscodeTools: VscodeTools,
componentRegistry: extensionComponentRegistry
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/filesystems/local/deployTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import vscode, { Uri, WorkspaceFolder } from 'vscode';
import { instance } from '../../instantiate';
import { LocalLanguageActions } from './LocalLanguageActions';
import { Deployment } from './deployment';
import { getGitAPI, md5Hash } from '../../ui/tools';
import { VscodeTools } from '../../ui/vscodeTools';
import { DeploymentMethod } from '../../api/types';
import { DeploymentParameters } from '../../typings';

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

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

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

if (gitApi && gitApi.repositories.length > 0) {
const repository = gitApi.repositories.find(r => r.rootUri.fsPath === parameters.workspaceFolder.uri.fsPath);
Expand Down Expand Up @@ -274,7 +274,7 @@ export namespace DeployTools {
const uploads: vscode.Uri[] = [];
for await (const file of localFiles) {
const remote = remoteMD5.find(e => e.path === file.path);
const md5 = md5Hash(file.uri);
const md5 = VscodeTools.md5Hash(file.uri);
if (!remote || remote.md5 !== md5) {
uploads.push(file.uri);
}
Expand Down
6 changes: 3 additions & 3 deletions src/filesystems/local/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { getBranchLibraryName } from "./env";
import { instance } from "../../instantiate";
import IBMi from "../../api/IBMi";
import IBMiContent from "../../api/IBMiContent";
import { getGitAPI } from "../../ui/tools";
import { VscodeTools } from "../../ui/vscodeTools";
import { ConnectionConfig } from "../../api/configuration/config/ConnectionManager";

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

export function getGitBranch(workspaceFolder: WorkspaceFolder) {
const gitApi = getGitAPI();
const gitApi = VscodeTools.getGitAPI();
if (gitApi) {
const repo = gitApi.getRepository(workspaceFolder.uri);
if (repo) {
Expand All @@ -19,7 +19,7 @@ export function getGitBranch(workspaceFolder: WorkspaceFolder) {
}

export function setupGitEventHandler(context: ExtensionContext) {
const gitApi = getGitAPI();
const gitApi = VscodeTools.getGitAPI();

if (gitApi) {
gitApi.onDidOpenRepository((repo) => {
Expand Down
Loading

0 comments on commit 342f7d3

Please sign in to comment.