vscode存储
This commit is contained in:
commit
418b618363
43
MementoAPI/extension.ts
Normal file
43
MementoAPI/extension.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import * as vscode from 'vscode'
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
console.log('Congratulations, your extension "jokes" is now active!')
|
||||
let disposable = vscode.commands.registerCommand('extension.saveData', () => {
|
||||
const myData = 'Hello, VSCode!'
|
||||
const storageKey = 'myDataKey'
|
||||
|
||||
// 获取全局存储的 Memento 对象
|
||||
const globalState = context.globalState
|
||||
|
||||
// 存储数据
|
||||
globalState.update(storageKey, myData).then(
|
||||
() => {
|
||||
vscode.window.showInformationMessage('Data saved!')
|
||||
},
|
||||
(error) => {
|
||||
console.error('Failed to save data:', error)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
context.subscriptions.push(disposable)
|
||||
|
||||
disposable = vscode.commands.registerCommand('extension.retrieveData', () => {
|
||||
const storageKey = 'myDataKey'
|
||||
|
||||
// 获取全局存储的 Memento 对象
|
||||
const globalState = context.globalState
|
||||
|
||||
// 检索数据
|
||||
const myData = globalState.get<string>(storageKey)
|
||||
|
||||
if (myData) {
|
||||
vscode.window.showInformationMessage(`Retrieved Data: ${myData}`)
|
||||
} else {
|
||||
vscode.window.showInformationMessage('No data found.')
|
||||
}
|
||||
})
|
||||
|
||||
context.subscriptions.push(disposable)
|
||||
}
|
||||
|
||||
export function deactivate() {}
|
67
MementoAPI/package.json
Normal file
67
MementoAPI/package.json
Normal file
@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "jokes",
|
||||
"displayName": "jokes",
|
||||
"description": "",
|
||||
"version": "0.0.1",
|
||||
"engines": {
|
||||
"vscode": "^1.95.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:extension.saveData",
|
||||
"onCommand:extension.retrieveData"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.saveData",
|
||||
"title": "Save Data to Memento",
|
||||
"category": "My Extension"
|
||||
},
|
||||
{
|
||||
"command": "extension.retrieveData",
|
||||
"title": "Retrieve Data from Memento",
|
||||
"category": "My Extension"
|
||||
}
|
||||
],
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "extension.saveData",
|
||||
"key": "ctrl+alt+s",
|
||||
"mac": "cmd+alt+s",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "extension.retrieveData",
|
||||
"key": "ctrl+alt+r",
|
||||
"mac": "cmd+alt+r",
|
||||
"when": "editorTextFocus"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"lint": "eslint src",
|
||||
"test": "vscode-test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.9",
|
||||
"@types/node": "20.x",
|
||||
"@types/vscode": "^1.95.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.10.0",
|
||||
"@typescript-eslint/parser": "^8.7.0",
|
||||
"@vscode/test-cli": "^0.0.10",
|
||||
"@vscode/test-electron": "^2.4.1",
|
||||
"eslint": "^9.13.0",
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.8"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user