Skip to content

Commit c621f68

Browse files
committed
Correclty include new methods in tools namespace
Signed-off-by: worksofliam <[email protected]>
1 parent 16b7564 commit c621f68

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

src/api/Tools.ts

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -259,50 +259,51 @@ export namespace Tools {
259259
}
260260
}
261261
}
262-
}
263-
264-
/**
265-
* We do this to find previously opened files with the same path, but different case OR readonly flags.
266-
* Without this, it's possible for the same document to be opened twice simply due to the readonly flag.
267-
*/
268-
export function findExistingDocumentUri(uri: vscode.Uri) {
269-
const bathUriString = uriStringWithoutFragment(uri);
270-
const possibleDoc = vscode.workspace.textDocuments.find(document => uriStringWithoutFragment(document.uri) === bathUriString);
271-
if (possibleDoc) {
272-
return possibleDoc.uri;
273-
}
274262

275-
return uri;
276-
}
277-
278-
/**
279-
* We convert member to lowercase as members are case insensitive.
280-
*/
281-
function uriStringWithoutFragment(uri: vscode.Uri) {
282-
// To lowercase because the URI path is case-insensitive
283-
const baseUri = uri.scheme + `:` + uri.path;
284-
const isCaseSensitive = (uri.scheme === `streamfile` && uri.path.startsWith(`/QOpenSys/`));
285-
return (isCaseSensitive ? baseUri : baseUri.toLowerCase());
286-
}
287-
288-
/**
289-
* Fixes an SQL statement to make it compatible with db2 CLI program QZDFMDB2.
290-
* - Changes `@clCommand` statements into Call `QSYS2.QCMDEX('clCommand')` procedure calls
291-
* - Makes sure each comment (`--`) starts on a new line
292-
* @param statement the statement to fix
293-
* @returns statement compatible with QZDFMDB2
294-
*/
295-
export function fixSQL(statement: string) {
296-
return statement.split("\n").map(line => {
297-
if (line.startsWith('@')) {
298-
//- Escape all '
299-
//- Remove any trailing ;
300-
//- Put the command in a Call QSYS2.QCMDEXC statement
301-
line = `Call QSYS2.QCMDEXC('${line.substring(1, line.endsWith(";") ? line.length - 1 : undefined).replaceAll("'", "''")}');`;
263+
264+
/**
265+
* We do this to find previously opened files with the same path, but different case OR readonly flags.
266+
* Without this, it's possible for the same document to be opened twice simply due to the readonly flag.
267+
*/
268+
export function findExistingDocumentUri(uri: vscode.Uri) {
269+
const bathUriString = uriStringWithoutFragment(uri);
270+
const possibleDoc = vscode.workspace.textDocuments.find(document => uriStringWithoutFragment(document.uri) === bathUriString);
271+
if (possibleDoc) {
272+
return possibleDoc.uri;
302273
}
303274

304-
//Make each comment start on a new line
305-
return line.replaceAll("--", "\n--");
275+
return uri;
276+
}
277+
278+
/**
279+
* We convert member to lowercase as members are case insensitive.
280+
*/
281+
function uriStringWithoutFragment(uri: vscode.Uri) {
282+
// To lowercase because the URI path is case-insensitive
283+
const baseUri = uri.scheme + `:` + uri.path;
284+
const isCaseSensitive = (uri.scheme === `streamfile` && uri.path.startsWith(`/QOpenSys/`));
285+
return (isCaseSensitive ? baseUri : baseUri.toLowerCase());
286+
}
287+
288+
/**
289+
* Fixes an SQL statement to make it compatible with db2 CLI program QZDFMDB2.
290+
* - Changes `@clCommand` statements into Call `QSYS2.QCMDEX('clCommand')` procedure calls
291+
* - Makes sure each comment (`--`) starts on a new line
292+
* @param statement the statement to fix
293+
* @returns statement compatible with QZDFMDB2
294+
*/
295+
export function fixSQL(statement: string) {
296+
return statement.split("\n").map(line => {
297+
if (line.startsWith('@')) {
298+
//- Escape all '
299+
//- Remove any trailing ;
300+
//- Put the command in a Call QSYS2.QCMDEXC statement
301+
line = `Call QSYS2.QCMDEXC('${line.substring(1, line.endsWith(";") ? line.length - 1 : undefined).replaceAll("'", "''")}');`;
302+
}
303+
304+
//Make each comment start on a new line
305+
return line.replaceAll("--", "\n--");
306+
}
307+
).join("\n");
306308
}
307-
).join("\n");
308309
}

src/instantiate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tools, findExistingDocumentUri } from './api/Tools';
1+
import { Tools } from './api/Tools';
22

33
import path, { dirname } from 'path';
44
import * as vscode from "vscode";
@@ -121,7 +121,7 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
121121

122122
const uri = getUriFromPath(path, options);
123123

124-
const existingUri = findExistingDocumentUri(uri);
124+
const existingUri = Tools.findExistingDocumentUri(uri);
125125

126126
if (existingUri) {
127127
const existingOptions = parseFSOptions(existingUri);

0 commit comments

Comments
 (0)