Skip to content

Commit

Permalink
chore: prettier 3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbehr1 committed Jan 7, 2024
1 parent d8fb59f commit 536517d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 134 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,23 @@
"glob": "^10.3.4",
"husky": "^8.0.1",
"mocha": "^10.0.0",
"prettier": "^3.1.1",
"semantic-release": "^21.0.1",
"semantic-release-vsce": "^5.5.6",
"typescript": "^5.2.2",
"vsce": "^2.15.0",
"vscode-test": "^1.6.1"
},
"dependencies": {
"dlt-logs-utils": "0.0.2",
"tslib": "2.6.2",
"@vscode/extension-telemetry": "^0.8.4",
"dlt-logs-utils": "0.0.2",
"jju": "github:mbehr1/jju#3aa4169df926e99083fdd511d7c20b5bd9ba789f",
"js-yaml": "^4.1.0",
"json5": "2.2.3",
"jsonpath": "^1.1.1",
"request": "^2.88.2",
"short-unique-id": "4.4.4"
"short-unique-id": "4.4.4",
"tslib": "2.6.2"
},
"commitlint": {
"extends": [
Expand Down
10 changes: 5 additions & 5 deletions src/extension/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* --------------------
* Copyright (C) Matthias Behr, 2021-2023
*/
* Copyright (C) Matthias Behr, 2021-2024
*/

export const extensionId = 'mbehr1.fishbone';
export const extensionId = 'mbehr1.fishbone'

export enum GlobalState {
Version = 'fishbone:version',
PendingWhatNewOnFocus = 'fishbone:pendingWhatsNewOnFocus'
Version = 'fishbone:version',
PendingWhatNewOnFocus = 'fishbone:pendingWhatsNewOnFocus',
}
238 changes: 123 additions & 115 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
@@ -1,136 +1,144 @@
// todo add copyright, 2020 - 2023 Matthias Behr
// todo add copyright, 2020 - 2024 Matthias Behr
// - inform webview of extension (restquery provider or document changes)
// - use Secrets API from 1.53 for https auth info?

import * as fs from 'fs';
import * as vscode from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';
import { extensionId, GlobalState } from './constants';
import { FBAEditorProvider } from './fbaEditor';
import * as fs from 'fs'
import * as vscode from 'vscode'
import TelemetryReporter from '@vscode/extension-telemetry'
import { extensionId, GlobalState } from './constants'
import { FBAEditorProvider } from './fbaEditor'

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

let reporter: TelemetryReporter | undefined = undefined;
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
const extension = vscode.extensions.getExtension(extensionId);

const prevVersion = context.globalState.get<string>(GlobalState.Version);
let extensionVersion = '0.0.0'; // default value for unlikely case
if (extension) {
extensionVersion = extension.packageJSON.version;

// the aik is not really sec_ret. but lets avoid bo_ts finding it too easy:
const strKE = 'ZjJlMDA4NTQtNmU5NC00ZDVlLTkxNDAtOGFiNmIzNTllODBi';
const strK = Buffer.from(strKE, "base64").toString();
reporter = new TelemetryReporter(strK)
context.subscriptions.push(reporter);
reporter?.sendTelemetryEvent('activate');
} else {
console.error(`${extensionId}: not found as extension!`);
}
console.log(`extension ${extensionId} v${extensionVersion} ${prevVersion !== extensionVersion ? `prevVersion: ${prevVersion} ` : ''}is now active!`);

FBAEditorProvider.register(context, reporter);

context.subscriptions.push(vscode.commands.registerCommand("fishbone.addNewFile", async () => {
console.log(`fishbone.addNewFile...`);
vscode.window.showSaveDialog({
filters: {
'Fishbone analysis': ['fba']
},
saveLabel: 'New fishbone analysis'
}).then(async (uri) => {
if (uri) {
console.log(`got uri scheme='${uri.scheme}' fspath=${uri.fsPath} path=${uri.path}`);
// if file exists, open directly: (the overwrite warning was there already)
if (fs.existsSync(uri.fsPath)) {
fs.unlinkSync(uri.fsPath);
}
// lets create the file here already empty to avoid running into issue #7.
fs.writeFileSync(uri.fsPath, '');
//const newFileUri = vscode.Uri.parse(`untitled:${uri.fsPath}`);
//await vscode.workspace.openTextDocument(newFileUri);
//await vscode.commands.executeCommand('vscode.openWith', newFileUri, 'fishbone.fba');
await vscode.commands.executeCommand('vscode.openWith', uri, 'fishbone.fba', { preview: false });
}
});
}));

void showWelcomeOrWhatsNew(context, extensionVersion, prevVersion);

void context.globalState.update(GlobalState.Version, extensionVersion);
let reporter: TelemetryReporter | undefined = undefined
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
const extension = vscode.extensions.getExtension(extensionId)

const prevVersion = context.globalState.get<string>(GlobalState.Version)
let extensionVersion = '0.0.0' // default value for unlikely case
if (extension) {
extensionVersion = extension.packageJSON.version

// the aik is not really sec_ret. but lets avoid bo_ts finding it too easy:
const strKE = 'ZjJlMDA4NTQtNmU5NC00ZDVlLTkxNDAtOGFiNmIzNTllODBi'
const strK = Buffer.from(strKE, 'base64').toString()
reporter = new TelemetryReporter(strK)
context.subscriptions.push(reporter)
reporter?.sendTelemetryEvent('activate')
} else {
console.error(`${extensionId}: not found as extension!`)
}
console.log(
`extension ${extensionId} v${extensionVersion} ${prevVersion !== extensionVersion ? `prevVersion: ${prevVersion} ` : ''}is now active!`,
)

FBAEditorProvider.register(context, reporter)

context.subscriptions.push(
vscode.commands.registerCommand('fishbone.addNewFile', async () => {
console.log(`fishbone.addNewFile...`)
vscode.window
.showSaveDialog({
filters: {
'Fishbone analysis': ['fba'],
},
saveLabel: 'New fishbone analysis',
})
.then(async (uri) => {
if (uri) {
console.log(`got uri scheme='${uri.scheme}' fspath=${uri.fsPath} path=${uri.path}`)
// if file exists, open directly: (the overwrite warning was there already)
if (fs.existsSync(uri.fsPath)) {
fs.unlinkSync(uri.fsPath)
}
// lets create the file here already empty to avoid running into issue #7.
fs.writeFileSync(uri.fsPath, '')
//const newFileUri = vscode.Uri.parse(`untitled:${uri.fsPath}`);
//await vscode.workspace.openTextDocument(newFileUri);
//await vscode.commands.executeCommand('vscode.openWith', newFileUri, 'fishbone.fba');
await vscode.commands.executeCommand('vscode.openWith', uri, 'fishbone.fba', { preview: false })
}
})
}),
)

void showWelcomeOrWhatsNew(context, extensionVersion, prevVersion)

void context.globalState.update(GlobalState.Version, extensionVersion)
}

// this method is called when your extension is deactivated
export function deactivate() {
console.log('extension "fishbone" is now deactive!');
console.log('extension "fishbone" is now deactive!')
}

async function showWelcomeOrWhatsNew(context: vscode.ExtensionContext, version: string, prevVersion: string | undefined) {

let showFunction: undefined | ((version: string) => Promise<void>) = undefined;

if (!prevVersion) {
// first time install... point to docs todo
showFunction = showWelcomeMessage;
} else if (prevVersion !== version) {
const [major, minor] = version.split('.').map(v => parseInt(v, 10));
const [prevMajor, prevMinor] = prevVersion.split('.').map(v => parseInt(v, 10));
if ((major === prevMajor && minor === prevMinor) ||
(major < prevMajor) || // ignore downgrades
(major === prevMajor && minor < prevMinor)) {
return;
}
// major/minor version is higher
showFunction = showWhatsNewMessage;
}
if (showFunction) {
if (vscode.window.state.focused) {
await context.globalState.update(GlobalState.PendingWhatNewOnFocus, undefined);
void showFunction(version);
} else {
await context.globalState.update(GlobalState.PendingWhatNewOnFocus, true);
const disposable = vscode.window.onDidChangeWindowState(e => {
if (!e.focused) { return; }
disposable.dispose();

if (context.globalState.get(GlobalState.PendingWhatNewOnFocus) === true) {
void context.globalState.update(GlobalState.PendingWhatNewOnFocus, undefined);
if (showFunction) {
void showFunction(version);
}
}
});
context.subscriptions.push(disposable);
}
}
let showFunction: undefined | ((version: string) => Promise<void>) = undefined

if (!prevVersion) {
// first time install... point to docs todo
showFunction = showWelcomeMessage
} else if (prevVersion !== version) {
const [major, minor] = version.split('.').map((v) => parseInt(v, 10))
const [prevMajor, prevMinor] = prevVersion.split('.').map((v) => parseInt(v, 10))
if (
(major === prevMajor && minor === prevMinor) ||
major < prevMajor || // ignore downgrades
(major === prevMajor && minor < prevMinor)
) {
return
}
// major/minor version is higher
showFunction = showWhatsNewMessage
}
if (showFunction) {
if (vscode.window.state.focused) {
await context.globalState.update(GlobalState.PendingWhatNewOnFocus, undefined)
void showFunction(version)
} else {
await context.globalState.update(GlobalState.PendingWhatNewOnFocus, true)
const disposable = vscode.window.onDidChangeWindowState((e) => {
if (!e.focused) {
return
}
disposable.dispose()

if (context.globalState.get(GlobalState.PendingWhatNewOnFocus) === true) {
void context.globalState.update(GlobalState.PendingWhatNewOnFocus, undefined)
if (showFunction) {
void showFunction(version)
}
}
})
context.subscriptions.push(disposable)
}
}
}

async function showWhatsNewMessage(version: string) {
const message = `Fishbone has been updated to v${version} - check out what's new!`;
const actions: vscode.MessageItem[] = [{ title: "What's New" }, { title: '❤ Sponsor' }];
const result = await vscode.window.showInformationMessage(message, ...actions);
if (result !== undefined) {
if (result === actions[0]) {
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/mbehr1/fishbone/blob/master/CHANGELOG.md'));
} else if (result === actions[1]) {
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/mbehr1'));
}
}
const message = `Fishbone has been updated to v${version} - check out what's new!`
const actions: vscode.MessageItem[] = [{ title: "What's New" }, { title: '❤ Sponsor' }]
const result = await vscode.window.showInformationMessage(message, ...actions)
if (result !== undefined) {
if (result === actions[0]) {
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/mbehr1/fishbone/blob/master/CHANGELOG.md'))
} else if (result === actions[1]) {
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/mbehr1'))
}
}
}

async function showWelcomeMessage(version: string) {
const message = `Fishbone v${version} has been installed - check out the docs!`;
const actions: vscode.MessageItem[] = [{ title: "Docs" }, { title: '❤ Sponsor' }];
const result = await vscode.window.showInformationMessage(message, ...actions);
if (result !== undefined) {
if (result === actions[0]) {
await vscode.env.openExternal(vscode.Uri.parse('https://mbehr1.github.io/fishbone/docs/#first-use'));
} else if (result === actions[1]) {
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/mbehr1'));
}
}
const message = `Fishbone v${version} has been installed - check out the docs!`
const actions: vscode.MessageItem[] = [{ title: 'Docs' }, { title: '❤ Sponsor' }]
const result = await vscode.window.showInformationMessage(message, ...actions)
if (result !== undefined) {
if (result === actions[0]) {
await vscode.env.openExternal(vscode.Uri.parse('https://mbehr1.github.io/fishbone/docs/#first-use'))
} else if (result === actions[1]) {
await vscode.env.openExternal(vscode.Uri.parse('https://github.com/sponsors/mbehr1'))
}
}
}
5 changes: 4 additions & 1 deletion src/extension/fbaEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class FBAEditorProvider implements vscode.CustomTextEditorProvider, vscod

private _fsProvider: FBAFSProvider

constructor(private readonly context: vscode.ExtensionContext, private readonly reporter?: TelemetryReporter) {
constructor(
private readonly context: vscode.ExtensionContext,
private readonly reporter?: TelemetryReporter,
) {
console.log(`FBAEditorProvider constructor() called...`)

this._fsProvider = new FBAFSProvider(this)
Expand Down
6 changes: 3 additions & 3 deletions src/extension/fbaNBRQRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ export class FBANBRestQueryRenderer {
resJson.data.length > msgs.length
? `. Unfold to see first ${msgs.length}`
: resJson.data.length > 0
? ':'
: ''
? ':'
: ''
}`,
texts: msgs.map((msg) => codeBlock(JSON.stringify(msg, undefined, 2), 'json')).flat(),
},
Expand Down Expand Up @@ -760,7 +760,7 @@ export class FBANBRestQueryRenderer {
let convResult: string | number | undefined
switch (convType) {
case 'length':
convResult = Array.isArray(result) ? result.length : 0
convResult = Array.isArray(result) ? result.length : Array.isArray(result.data) ? result.data.length : 0
break
case 'index':
convResult =
Expand Down
6 changes: 5 additions & 1 deletion src/extension/fbaNotebookProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export class FBANotebookProvider implements Disposable {

private selectedNotebooks: vscode.NotebookDocument[] = []

constructor(context: vscode.ExtensionContext, private editorProvider: FBAEditorProvider, private fsProvider: FBAFSProvider) {
constructor(
context: vscode.ExtensionContext,
private editorProvider: FBAEditorProvider,
private fsProvider: FBAFSProvider,
) {
// console.log(`FBANotebookProvider()...`)

this.nbController = vscode.notebooks.createNotebookController('fba-nb-controller-1', 'fba-nb', 'Fishbone Notebook')
Expand Down
12 changes: 6 additions & 6 deletions src/extension/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as request from 'request';
import { extensionId } from './constants';
import { URL } from 'url';
import * as vscode from 'vscode'
import * as request from 'request'
import { extensionId } from './constants'
import { URL } from 'url'
import { Token, tokenize } from 'jju'

export function getNonce() {
Expand Down Expand Up @@ -156,9 +156,9 @@ export const isEqualUint8Array = (a: Uint8Array, b: Uint8Array): boolean => {
* @returns true if both are equal, e.g. have same length and same ('===') items
*/
export const arrayEquals = <T>(a: T[], b: T[]) => {
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((val, idx) => val === b[idx])
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((val, idx) => val === b[idx])
}

/**
* return a Uri that executes the command with the arguments.
* @param cmd - vscode command that will be called if the Uri is clicked (e.g. from hover text). Needs to be a registered command.
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5200,6 +5200,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=

prettier@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.1.tgz#6ba9f23165d690b6cbdaa88cb0807278f7019848"
integrity sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==

proc-log@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/proc-log/-/proc-log-3.0.0.tgz"
Expand Down

0 comments on commit 536517d

Please sign in to comment.