Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local storage sample #6

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/vscode-extension-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- tree-view-sample
- uss-profile-sample
- vue-webview-sample
- local-storage-sample

steps:
- name: Checkout
Expand Down
15 changes: 15 additions & 0 deletions vscode-extension-samples/local-storage-sample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
4 changes: 4 additions & 0 deletions vscode-extension-samples/local-storage-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
out
node_modules
.vscode-test/
*.vsix
18 changes: 18 additions & 0 deletions vscode-extension-samples/local-storage-sample/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
20 changes: 20 additions & 0 deletions vscode-extension-samples/local-storage-sample/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
14 changes: 14 additions & 0 deletions vscode-extension-samples/local-storage-sample/README.md
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions vscode-extension-samples/local-storage-sample/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
28 changes: 28 additions & 0 deletions vscode-extension-samples/local-storage-sample/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
13 changes: 13 additions & 0 deletions vscode-extension-samples/local-storage-sample/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
Loading