Skip to content

Commit

Permalink
Attempt to fix all references to legacy instance methods
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Nov 27, 2024
1 parent 7d46f2b commit 4da6843
Show file tree
Hide file tree
Showing 30 changed files with 258 additions and 239 deletions.
6 changes: 3 additions & 3 deletions src/api/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { GetMemberInfo } from '../components/getMemberInfo';
export namespace Search {
export async function searchMembers(instance: Instance, library: string, sourceFile: string, searchTerm: string, members: string|IBMiMember[], readOnly?: boolean,): Promise<SearchResults> {
const connection = instance.getConnection();
const config = instance.getConfig();
const content = instance.getContent();

if (connection && config && content) {
if (connection) {
const config = connection.getConfig();
const content = connection.getContent();
let detailedMembers: IBMiMember[]|undefined;
let memberFilter: string|undefined;

Expand Down
6 changes: 3 additions & 3 deletions src/api/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export namespace Terminal {
}),

vscode.commands.registerCommand(`code-for-ibmi.openTerminalHere`, async (ifsNode) => {
const content = instance.getContent();
const content = instance.getConnection()?.getContent();
if (content) {
const ifsPath = (await content.isDirectory(ifsNode.path)) ? ifsNode.path : path.dirname(ifsNode.path);
const terminal = await selectAndOpen(context, instance, TerminalType.PASE);
Expand All @@ -73,8 +73,8 @@ export namespace Terminal {

async function selectAndOpen(context: vscode.ExtensionContext, instance: Instance, openType?: TerminalType) {
const connection = instance.getConnection();
const configuration = instance.getConfig();
if (connection && configuration) {
if (connection) {
const configuration = connection.getConfig();
const type = openType || (await vscode.window.showQuickPick(typeItems, {
placeHolder: `Select a terminal type`
}))?.type;
Expand Down
11 changes: 3 additions & 8 deletions src/api/debug/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function setup(connection: IBMi, imported?: ImportedCertificate) {
});

//Check if encryption key exists too...because the encryption script can return 0 and an error in stdout in some cases.
if (!encryptResult.code && await instance.getContent()?.testStreamFile(posix.join(debugConfig.getRemoteServiceWorkDir(), "key.properties"), "r")) {
if (!encryptResult.code && await connection.getContent().testStreamFile(posix.join(debugConfig.getRemoteServiceWorkDir(), "key.properties"), "r")) {
//After the certificates are generated/imported and the password is encrypted, we make a copy of the encryption key
//because it gets deleted each time the service starts. The CODE4IDEBUG variable is here to run the script that will restore the key
//when the service starts.
Expand Down Expand Up @@ -226,13 +226,8 @@ export async function remoteCertificatesExists(debugConfig?: DebugConfiguration)
}

export async function downloadClientCert(connection: IBMi) {
const content = instance.getContent();
if (content) {
await content.downloadStreamfileRaw((await new DebugConfiguration(connection).load()).getRemoteClientCertificatePath(), getLocalCertPath(connection));
}
else {
throw new Error("Not connected to an IBM i");
}
const content = connection.getContent();
await content.downloadStreamfileRaw((await new DebugConfiguration(connection).load()).getRemoteClientCertificatePath(), getLocalCertPath(connection));
}

export function getLocalCertPath(connection: IBMi) {
Expand Down
22 changes: 11 additions & 11 deletions src/api/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export async function initialize(context: ExtensionContext) {
const startDebugging = async (type: DebugType, objectType: DebugObjectType, objectLibrary: string, objectName: string, env?: Env) => {
if (debugExtensionAvailable()) {
const connection = instance.getConnection();
const config = instance.getConfig();
if (connection && config) {
if (connection) {
const config = connection.getConfig();
if (connection.remoteFeatures[`startDebugService.sh`]) {
const password = await getPassword();

Expand Down Expand Up @@ -120,9 +120,9 @@ export async function initialize(context: ExtensionContext) {
if (cachedResolvedTypes[path]) {
return cachedResolvedTypes[path];
} else {
const content = instance.getContent()!;
const connection = instance.getConnection()!;

const [row] = await content.runSQL(`select OBJTYPE from table(qsys2.object_statistics('${library}', '*PGM *SRVPGM', '${objectName}')) X`) as { OBJTYPE: DebugObjectType }[];
const [row] = await connection.runSQL(`select OBJTYPE from table(qsys2.object_statistics('${library}', '*PGM *SRVPGM', '${objectName}')) X`) as { OBJTYPE: DebugObjectType }[];

if (row) {
cachedResolvedTypes[path] = row.OBJTYPE;
Expand All @@ -133,14 +133,14 @@ export async function initialize(context: ExtensionContext) {

const getObjectFromUri = (uri: Uri, env?: Env) => {
const connection = instance.getConnection();
const configuration = instance.getConfig();

const qualifiedPath: {
library: string | undefined,
object: string | undefined
} = { library: undefined, object: undefined };

if (connection && configuration) {
if (connection) {
const configuration = connection.getConfig();

switch (uri.scheme) {
case `member`:
Expand Down Expand Up @@ -278,8 +278,8 @@ export async function initialize(context: ExtensionContext) {
vscode.commands.registerCommand(`code-for-ibmi.debug.setup.remote`, (doSetup?: 'Generate' | 'Import') =>
Tools.withContext("code-for-ibmi:debugWorking", async () => {
const connection = instance.getConnection();
const content = instance.getContent();
if (connection && content) {
if (connection) {
const content = connection.getContent();
const ptfInstalled = server.debugPTFInstalled();

if (ptfInstalled) {
Expand Down Expand Up @@ -379,7 +379,7 @@ export async function initialize(context: ExtensionContext) {
async () => {
activateDebugExtension();
const connection = instance.getConnection();
const content = instance.getContent();
const content = instance.getConnection()?.getContent();
if (connection && content && server.debugPTFInstalled()) {
vscode.commands.executeCommand(`setContext`, ptfContext, true);

Expand Down Expand Up @@ -435,8 +435,8 @@ type DebugType = "batch" | "sep";
type DebugObjectType = "*PGM" | "*SRVPGM";

export async function startDebug(instance: Instance, options: DebugOptions) {
const connection = instance.getConnection();
const config = instance.getConfig();
const connection = instance.getConnection()!;
const config = connection.getConfig();
const storage = instance.getStorage();

const serviceDetails = await getDebugServiceDetails();
Expand Down
4 changes: 2 additions & 2 deletions src/api/errors/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function clearDiagnostic(uri: vscode.Uri, changeRange: vscode.Range) {
}

export async function refreshDiagnosticsFromServer(instance: Instance, evfeventInfo: EvfEventInfo) {
const content = instance.getContent();
const content = instance.getConnection()?.getContent();

if (content) {
const tableData = await content.getTable(evfeventInfo.library, `EVFEVENT`, evfeventInfo.object);
Expand Down Expand Up @@ -102,7 +102,6 @@ export async function refreshDiagnosticsFromLocal(instance: Instance, evfeventIn

export function handleEvfeventLines(lines: string[], instance: Instance, evfeventInfo: EvfEventInfo) {
const connection = instance.getConnection();
const config = instance.getConfig();
const asp = evfeventInfo.asp ? `${evfeventInfo.asp}/` : ``;

const errorsByFiles = parseErrors(lines);
Expand All @@ -129,6 +128,7 @@ export function handleEvfeventLines(lines: string[], instance: Instance, evfeven

diagnostic.code = error.code;

const config = connection?.getConfig();
if (config) {
if (!config.hideCompileErrors.includes(error.code)) {
diagnostics.push(diagnostic);
Expand Down
3 changes: 2 additions & 1 deletion src/api/local/deployTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export namespace DeployTools {

methods.push({ method: "all" as DeploymentMethod, label: `All`, description: `Every file in the local workspace` });

const defaultDeploymentMethod = instance.getConfig()?.defaultDeploymentMethod as DeploymentMethod
const connection = instance.getConnection()!;
const defaultDeploymentMethod = connection.getConfig()?.defaultDeploymentMethod as DeploymentMethod

if (methods.find((element) => element.method === defaultDeploymentMethod)) { // default deploy method is usable
method = defaultDeploymentMethod
Expand Down
6 changes: 3 additions & 3 deletions src/api/local/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export namespace Deployment {
() => {
const workspaces = vscode.workspace.workspaceFolders;
const connection = instance.getConnection();
const config = instance.getConfig();
const storage = instance.getStorage();

if (workspaces && connection && storage && config) {
if (workspaces && connection && storage) {
const config = connection.getConfig();
if (workspaces.length > 0) {
button.show();
}
Expand Down Expand Up @@ -112,7 +112,7 @@ export namespace Deployment {
}

export function getContent() {
const content = instance.getContent();
const content = instance.getConnection()?.getContent();
if (!content) {
throw new Error("Please connect to an IBM i");
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/local/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function setupGitEventHandler(context: ExtensionContext) {

if (currentBranch && currentBranch !== lastBranch[workspaceUri]) {
if (connection) {
const content = instance.getContent()!;
const config = instance.getConfig()!;
const content = connection.getContent()!;
const config = connection.getConfig()!;

if (currentBranch.includes(`/`)) {
setupBranchLibrary(currentBranch, content, connection, config);
Expand Down
14 changes: 7 additions & 7 deletions src/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import Instance from "../api/Instance";
import { BrowserItem, Action, DeploymentMethod } from "../typings";

export function registerActionsCommands(instance: Instance): Disposable[] {
const connection = instance.getConnection()!;

return [
commands.registerCommand(`code-for-ibmi.runAction`, async (target: TreeItem | BrowserItem | Uri, group?: any, action?: Action, method?: DeploymentMethod, workspaceFolder?: WorkspaceFolder) => {
const connection = instance.getConnection()!;
const editor = window.activeTextEditor;
let uri;
let browserItem;
Expand All @@ -29,8 +28,8 @@ export function registerActionsCommands(instance: Instance): Disposable[] {
uri = uri || editor?.document.uri;

if (uri) {
const config = connection.getConfig();
if (config) {
if (connection) {
const config = connection.getConfig();
let canRun = true;
if (editor && uri.path === editor.document.uri.path && editor.document.isDirty) {
if (config.autoSaveBeforeAction) {
Expand Down Expand Up @@ -93,9 +92,10 @@ export function registerActionsCommands(instance: Instance): Disposable[] {

let initialPath = ``;
const editor = window.activeTextEditor;

if (editor) {
const config = instance.getConfig()!;
const connection = instance.getConnection();

if (editor && connection) {
const config = connection.getConfig();
const uri = editor.document.uri;

if ([`member`, `streamfile`].includes(uri.scheme)) {
Expand Down
2 changes: 0 additions & 2 deletions src/commands/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Instance from "../api/Instance";
let selectedForCompare: Uri;

export function registerCompareCommands(instance: Instance): Disposable[] {
const connection = instance.getConnection()!;

return [
commands.registerCommand(`code-for-ibmi.selectForCompare`, async (node) => {
if (node) {
Expand Down
1 change: 0 additions & 1 deletion src/commands/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ConnectionData } from "../typings";
import { safeDisconnect } from "../instantiate";

export function registerConnectionCommands(context: ExtensionContext, instance: Instance): Disposable[] {
const connection = instance.getConnection()!;

return [
commands.registerCommand(`code-for-ibmi.connectDirect`,
Expand Down
18 changes: 10 additions & 8 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const CLEAR_RECENT = `$(trash) Clear recently opened`;
const CLEAR_CACHED = `$(trash) Clear cached`;

export function registerOpenCommands(instance: Instance): Disposable[] {
const connection = instance.getConnection()!;

return [
commands.registerCommand(`code-for-ibmi.openEditable`, async (path: string, options?: OpenEditableOptions) => {
const connection = instance.getConnection()!;
console.log(path);
options = options || {};
options.readonly = options.readonly || connection.getContent()?.isProtectedPath(path);
options.readonly = options.readonly || connection.getContent().isProtectedPath(path);
if (!options.readonly) {
if (path.startsWith('/')) {
options.readonly = !await instance.getContent()?.testStreamFile(path, "w");
options.readonly = !await connection.getContent().testStreamFile(path, "w");
}
else {
const qsysObject = Tools.parseQSysPath(path);
const writable = await instance.getContent()?.checkObject({ library: qsysObject.library, name: qsysObject.name, type: '*FILE' }, ["*UPD"]);
const writable = await connection.getContent().checkObject({ library: qsysObject.library, name: qsysObject.name, type: '*FILE' }, ["*UPD"]);
if (!writable) {
options.readonly = true;
}
Expand All @@ -47,10 +47,10 @@ export function registerOpenCommands(instance: Instance): Disposable[] {

try {
if(options.position){
await commands.executeCommand(`openWith`, uri, 'default', { selection: options.position } as TextDocumentShowOptions);
await commands.executeCommand(`vscode.openWith`, uri, 'default', { selection: options.position } as TextDocumentShowOptions);
}
else{
await commands.executeCommand(`open`, uri);
await commands.executeCommand(`vscode.open`, uri);
}

// Add file to front of recently opened files list.
Expand Down Expand Up @@ -118,9 +118,11 @@ export function registerOpenCommands(instance: Instance): Disposable[] {
};

const LOADING_LABEL = `Please wait`;
const storage = instance.getStorage();
const content = instance.getContent();
const connection = instance.getConnection();
if (!connection) return;

const storage = instance.getStorage();
const content = connection?.getContent();
let starRemoved: boolean = false;

if (!storage && !content && !connection) return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/getNewLibl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class GetNewLibl extends IBMiComponent {

protected update(): Promise<ComponentState> {
const config = this.connection.getConfig()
const content = instance.getContent();
const content = this.connection.getContent();
return this.connection.withTempDirectory(async (tempDir): Promise<ComponentState> => {
const tempSourcePath = posix.join(tempDir, `getnewlibl.sql`);

Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
onCodeForIBMiConfigurationChange("connectionSettings", async () => {
const connection = instance.getConnection();
if (connection) {
const config = instance.getConfig();
const config = connection.getConfig();
if (config) {
Object.assign(config, (await ConnectionConfiguration.load(config.name)));
}
Expand Down
20 changes: 12 additions & 8 deletions src/filesystems/ifsFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export class IFSFS implements vscode.FileSystemProvider {
}

async readFile(uri: vscode.Uri, retrying?: boolean): Promise<Uint8Array> {
const contentApi = instance.getContent();
if (contentApi) {
const connection = instance.getConnection();
if (connection) {
const contentApi = connection.getContent();
const fileContent = await contentApi.downloadStreamfileRaw(uri.path);
return fileContent;
}
Expand All @@ -35,8 +36,9 @@ export class IFSFS implements vscode.FileSystemProvider {
}

async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
const content = instance.getContent();
if (content) {
const connection = instance.getConnection();
if (connection) {
const content = connection.getContent();
const path = uri.path;
if (await content.testStreamFile(path, "e")) {
const attributes = await content.getAttributes(path, "CREATE_TIME", "MODIFY_TIME", "DATA_SIZE", "OBJTYPE");
Expand Down Expand Up @@ -66,8 +68,9 @@ export class IFSFS implements vscode.FileSystemProvider {

async writeFile(uri: vscode.Uri, content: Uint8Array, options: { readonly create: boolean; readonly overwrite: boolean; }) {
const path = uri.path;
const contentApi = instance.getContent();
if (contentApi) {
const connection = instance.getConnection();
if (connection) {
const contentApi = connection.getContent();
if (!content.length) { //Coming from "Save as"
this.savedAsFiles.add(path);
await contentApi.createStreamFile(path);
Expand All @@ -92,8 +95,9 @@ export class IFSFS implements vscode.FileSystemProvider {
}

async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> {
const content = instance.getContent();
if (content) {
const connection = instance.getConnection();
if (connection) {
const content = connection.getContent();
return (await content.getFileList(uri.path)).map(ifsFile => ([ifsFile.name, ifsFile.type === "directory" ? FileType.Directory : FileType.File]));
}
else {
Expand Down
Loading

0 comments on commit 4da6843

Please sign in to comment.