mirror of
https://gitlab.com/aviortheking/code-stats-vscode.git
synced 2025-04-22 10:52:13 +00:00
Add a command to easily set API_KEY
This commit is contained in:
parent
99cc0bf94a
commit
d4fb4fbbef
28
.vscode/tasks.json
vendored
28
.vscode/tasks.json
vendored
@ -8,17 +8,11 @@
|
|||||||
|
|
||||||
// A task runner that calls a custom npm script that compiles the extension.
|
// A task runner that calls a custom npm script that compiles the extension.
|
||||||
{
|
{
|
||||||
"version": "0.1.0",
|
"version": "2.0.0",
|
||||||
|
|
||||||
// we want to run npm
|
// we want to run npm
|
||||||
"command": "npm",
|
"command": "npm",
|
||||||
|
|
||||||
// the command is a shell script
|
|
||||||
"isShellCommand": true,
|
|
||||||
|
|
||||||
// show the output window only if unrecognized errors occur.
|
|
||||||
"showOutput": "silent",
|
|
||||||
|
|
||||||
// we run the custom script "compile" as defined in package.json
|
// we run the custom script "compile" as defined in package.json
|
||||||
"args": ["run", "compile", "--loglevel", "silent"],
|
"args": ["run", "compile", "--loglevel", "silent"],
|
||||||
|
|
||||||
@ -26,5 +20,21 @@
|
|||||||
"isWatching": true,
|
"isWatching": true,
|
||||||
|
|
||||||
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
|
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
|
||||||
"problemMatcher": "$tsc-watch"
|
"problemMatcher": "$tsc-watch",
|
||||||
}
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "npm",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "npm",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"compile",
|
||||||
|
"--loglevel",
|
||||||
|
"silent"
|
||||||
|
],
|
||||||
|
"isBackground": true,
|
||||||
|
"problemMatcher": "$tsc-watch",
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
2826
package-lock.json
generated
2826
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -9,7 +9,8 @@
|
|||||||
"Valentin Ivanov (https://github.com/scout119)",
|
"Valentin Ivanov (https://github.com/scout119)",
|
||||||
"Paul Ryan (https://github.com/sharpred)",
|
"Paul Ryan (https://github.com/sharpred)",
|
||||||
"Mikko Ahlroth (https://github.com/Nicd)",
|
"Mikko Ahlroth (https://github.com/Nicd)",
|
||||||
"Julien Stébenne <julien.stebenne@gmail.com> (https://github.com/thebird956)"
|
"Julien Stébenne <julien.stebenne@gmail.com> (https://github.com/thebird956)",
|
||||||
|
"Avior <contact@avior.me> (https://github.com/aviortheking)"
|
||||||
],
|
],
|
||||||
"icon": "logo.png",
|
"icon": "logo.png",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -23,7 +24,8 @@
|
|||||||
"Other"
|
"Other"
|
||||||
],
|
],
|
||||||
"maintainers": [
|
"maintainers": [
|
||||||
"Juha Ristolainen"
|
"Juha Ristolainen",
|
||||||
|
"Avior"
|
||||||
],
|
],
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"*"
|
"*"
|
||||||
@ -51,21 +53,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"commands": []
|
"commands": [
|
||||||
|
{
|
||||||
|
"title": "Add your Code::Stats API Key",
|
||||||
|
"command": "code-stats.api-key"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"vscode:prepublish": "tsc -p ./",
|
"vscode:prepublish": "tsc -p ./",
|
||||||
"compile": "tsc -watch -p ./",
|
"compile": "tsc -watch -p ./"
|
||||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
|
||||||
"test": "node ./node_modules/vscode/bin/test"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/mocha": "^7.0.2",
|
"@types/mocha": "^7.0.2",
|
||||||
"@types/node": "^13.9.8",
|
"@types/node": "^13.9.8",
|
||||||
|
"@types/vscode": "^1.43.2",
|
||||||
"growl": "^1.10.5",
|
"growl": "^1.10.5",
|
||||||
"mocha": "^7.1.1",
|
"mocha": "^7.1.1",
|
||||||
"typescript": "^3.8.3",
|
"typescript": "^3.8.3",
|
||||||
"vscode": "^1.1.36"
|
"vscode-test": "^1.5.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.2",
|
"axios": "^0.19.2",
|
||||||
|
@ -49,7 +49,7 @@ export class XpCounter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
subscriptions.push(workspace.registerTextDocumentContentProvider('code-stats', new ProfileProvider(context, this.api)));
|
subscriptions.push(workspace.registerTextDocumentContentProvider('code-stats', new ProfileProvider(context, this.api)));
|
||||||
|
|
||||||
subscriptions.push(commands.registerCommand("code-stats.profile", () => {
|
subscriptions.push(commands.registerCommand("code-stats.profile", () => {
|
||||||
|
|
||||||
let config: WorkspaceConfiguration = workspace.getConfiguration(
|
let config: WorkspaceConfiguration = workspace.getConfiguration(
|
||||||
@ -60,12 +60,12 @@ export class XpCounter {
|
|||||||
window.showErrorMessage('codestats.username configuration setting is missing');
|
window.showErrorMessage('codestats.username configuration setting is missing');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( config.get("username") === '' ){
|
if( config.get("username") === '' ){
|
||||||
window.showErrorMessage('codestats.username configuration setting is missing');
|
window.showErrorMessage('codestats.username configuration setting is missing');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const panel = window.createWebviewPanel(
|
const panel = window.createWebviewPanel(
|
||||||
'codeStatsPanel',
|
'codeStatsPanel',
|
||||||
'Code::Stats Profile',
|
'Code::Stats Profile',
|
||||||
@ -79,7 +79,30 @@ export class XpCounter {
|
|||||||
panel.webview.html = value.getText();
|
panel.webview.html = value.getText();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
subscriptions.push(commands.registerCommand('code-stats.api-key', async () => {
|
||||||
|
// Display an input box to allow to change the API key
|
||||||
|
const response = await window.showInputBox({title: 'Enter your Code::Stats API key', placeHolder: 'xxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'})
|
||||||
|
|
||||||
|
// do nothing if nothing was entered
|
||||||
|
if (!response) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the configuration
|
||||||
|
const config = workspace.getConfiguration(
|
||||||
|
"codestats",
|
||||||
|
);
|
||||||
|
|
||||||
|
// Update the apiKey globally
|
||||||
|
// TODO: maybe add some sort of validation
|
||||||
|
config.update('apikey', response, true)
|
||||||
|
|
||||||
|
// Reload the API
|
||||||
|
this.initAPI()
|
||||||
|
window.showInformationMessage('API Key successfully updated!')
|
||||||
|
}))
|
||||||
|
|
||||||
workspace.onDidChangeTextDocument(
|
workspace.onDidChangeTextDocument(
|
||||||
this.onTextDocumentChanged,
|
this.onTextDocumentChanged,
|
||||||
this,
|
this,
|
||||||
@ -156,11 +179,11 @@ export class XpCounter {
|
|||||||
const apiKey: string = config.get("apikey");
|
const apiKey: string = config.get("apikey");
|
||||||
const apiURL: string = config.get("apiurl");
|
const apiURL: string = config.get("apiurl");
|
||||||
const userName: string = config.get("username");
|
const userName: string = config.get("username");
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`code-stats-vscode setting up:
|
`code-stats-vscode setting up:
|
||||||
API URL: ${apiURL}
|
API URL: ${apiURL}
|
||||||
NAME: ${userName}
|
NAME: ${userName}
|
||||||
KEY: ${apiKey}
|
KEY: ${apiKey}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
# Welcome to your first VS Code Extension
|
|
||||||
|
|
||||||
## What's in the folder
|
|
||||||
* This folder contains all of the files necessary for your extension
|
|
||||||
* `package.json` - this is the manifest file in which you declare your extension and command.
|
|
||||||
The sample plugin registers a command and defines its title and command name. With this information
|
|
||||||
VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
|
|
||||||
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
|
|
||||||
The file exports one function, `activate`, which is called the very first time your extension is
|
|
||||||
activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
|
|
||||||
We pass the function containing the implementation of the command as the second parameter to
|
|
||||||
`registerCommand`.
|
|
||||||
|
|
||||||
## Get up and running straight away
|
|
||||||
* press `F5` to open a new window with your extension loaded
|
|
||||||
* run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`
|
|
||||||
* set breakpoints in your code inside `src/extension.ts` to debug your extension
|
|
||||||
* find output from your extension in the debug console
|
|
||||||
|
|
||||||
## Make changes
|
|
||||||
* you can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`
|
|
||||||
* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes
|
|
||||||
|
|
||||||
## Explore the API
|
|
||||||
* you can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`
|
|
||||||
|
|
||||||
## Run tests
|
|
||||||
* open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`
|
|
||||||
* press `F5` to run the tests in a new window with your extension loaded
|
|
||||||
* see the output of the test result in the debug console
|
|
||||||
* make changes to `test/extension.test.ts` or create new test files inside the `test` folder
|
|
||||||
* by convention, the test runner will only consider files matching the name pattern `**.test.ts`
|
|
||||||
* you can create folders inside the `test` folder to structure your tests any way you want
|
|
Loading…
x
Reference in New Issue
Block a user