diff --git a/.github/workflows/vscode-extension-samples.yml b/.github/workflows/vscode-extension-samples.yml index f236c55..62d3c9f 100644 --- a/.github/workflows/vscode-extension-samples.yml +++ b/.github/workflows/vscode-extension-samples.yml @@ -23,6 +23,7 @@ jobs: - tree-view-sample - uss-profile-sample - vue-webview-sample + - local-storage-sample steps: - name: Checkout diff --git a/vscode-extension-samples/local-storage-sample/.eslintrc.js b/vscode-extension-samples/local-storage-sample/.eslintrc.js new file mode 100644 index 0000000..5e0416f --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/.eslintrc.js @@ -0,0 +1,15 @@ +/**@type {import('eslint').Linter.Config} */ +// eslint-disable-next-line no-undef +module.exports = { + root: true, + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint"], + extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + rules: { + semi: [2, "always"], + "@typescript-eslint/no-unused-vars": 0, + "@typescript-eslint/no-explicit-any": 0, + "@typescript-eslint/explicit-module-boundary-types": 0, + "@typescript-eslint/no-non-null-assertion": 0, + }, +}; diff --git a/vscode-extension-samples/local-storage-sample/.gitignore b/vscode-extension-samples/local-storage-sample/.gitignore new file mode 100644 index 0000000..5fe00fe --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/.gitignore @@ -0,0 +1,4 @@ +out +node_modules +.vscode-test/ +*.vsix diff --git a/vscode-extension-samples/local-storage-sample/.vscode/launch.json b/vscode-extension-samples/local-storage-sample/.vscode/launch.json new file mode 100644 index 0000000..e3dea5a --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/.vscode/launch.json @@ -0,0 +1,18 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "outFiles": ["${workspaceFolder}/out/**/*.js"], + "preLaunchTask": "npm: watch" + } + ] +} diff --git a/vscode-extension-samples/local-storage-sample/.vscode/tasks.json b/vscode-extension-samples/local-storage-sample/.vscode/tasks.json new file mode 100644 index 0000000..078ff7e --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/.vscode/tasks.json @@ -0,0 +1,20 @@ +// See https://go.microsoft.com/fwlink/?LinkId=733558 +// for the documentation about the tasks.json format +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/vscode-extension-samples/local-storage-sample/README.md b/vscode-extension-samples/local-storage-sample/README.md new file mode 100644 index 0000000..2752ac5 --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/README.md @@ -0,0 +1,14 @@ +# Local Storage Sample + +Demonstrates accessing local storage using the `LocalStorageAccess` facility, exposed through Zowe Explorer's extender API. + +- Displays your data set history as a notification (if you have data set history defined in Zowe Explorer's local storage) +- Displays list of readable and writable keys as a notification +- Displays the error received when trying to access a value for a key w/ no access permissions + +## Running the sample + +- Open this sample in VS Code +- `npm install` +- `npm run compile` +- `F5` to start debugging diff --git a/vscode-extension-samples/local-storage-sample/package.json b/vscode-extension-samples/local-storage-sample/package.json new file mode 100644 index 0000000..e3ff657 --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/package.json @@ -0,0 +1,37 @@ +{ + "name": "local-storage-sample", + "displayName": "local-storage-sample", + "description": "Local storage sample for Zowe Explorer", + "version": "0.0.1", + "publisher": "Zowe", + "repository": "https://github.com/zowe/zowe-client-samples/tree/main/vscode-extension-samples", + "engines": { + "vscode": "^1.79.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "onStartupFinished" + ], + "main": "./out/extension.js", + "extensionDependencies": [ + "Zowe.vscode-extension-for-zowe" + ], + "scripts": { + "vscode:prepublish": "npm run compile", + "compile": "tsc -p ./", + "lint": "eslint \"src/**/*.ts\"", + "watch": "tsc -watch -p ./" + }, + "dependencies": {}, + "devDependencies": { + "@types/node": "^18.19.14", + "@types/vscode": "^1.53.2", + "@typescript-eslint/eslint-plugin": "^5.42.0", + "@typescript-eslint/parser": "^5.42.0", + "@zowe/zowe-explorer-api": "^3.0.0", + "eslint": "^8.26.0", + "typescript": "^5.1.3" + } +} diff --git a/vscode-extension-samples/local-storage-sample/src/extension.ts b/vscode-extension-samples/local-storage-sample/src/extension.ts new file mode 100644 index 0000000..1357d0c --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/src/extension.ts @@ -0,0 +1,28 @@ +// The module 'vscode' contains the VS Code extensibility API +// Import the module and reference it with the alias vscode in your code below +import * as vscode from "vscode"; + +// 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) { + // 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 + console.log('Congratulations, your extension "local-storage-sample" is now active!'); + + const zeApi = vscode.extensions.getExtension("Zowe.vscode-extension-for-zowe")?.exports; + const localStorage = zeApi.getExplorerExtenderApi().getLocalStorage(); + + // access readable and writable keys within local storage: + vscode.window.showInformationMessage(localStorage.getWritableKeys().join(",")); + vscode.window.showInformationMessage(localStorage.getReadableKeys().join(",")); + + vscode.window.showInformationMessage(JSON.stringify(localStorage.getValue("zowe.ds.history"))); + try { + // trying to access a key with insufficient perms will throw an error + localStorage.getValue("zowe.v1MigrationStatus"); + } catch (err) { + if (err instanceof Error) { + vscode.window.showErrorMessage(err.message); + } + } +} diff --git a/vscode-extension-samples/local-storage-sample/tsconfig.json b/vscode-extension-samples/local-storage-sample/tsconfig.json new file mode 100644 index 0000000..52cbd38 --- /dev/null +++ b/vscode-extension-samples/local-storage-sample/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2020", + "lib": ["es2020"], + "outDir": "out", + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "rootDir": "src" + }, + "exclude": ["node_modules", ".vscode-test"] +}