Merge branch 'thebird956/code-stats-vscode-update-to-webview'

This commit is contained in:
Juha Ristolainen 2019-04-04 19:48:59 +01:00
commit a2ddfbea59
7 changed files with 2715 additions and 2700 deletions

View File

@ -2,6 +2,13 @@
All notable changes to the "code-stats-vscode" extension will be documented in this file.
## [1.0.15] - 2019-04-04
### Changed
Merged PR from thebird956:
Replaced deprecated 'vscode.previewHtml' command to the webview API.
## [1.0.14] - 2019-04-04
### Changed

View File

@ -24,6 +24,11 @@ This extension contributes the following settings:
## Release Notes
### 1.0.15
Merged PR from thebird956:
Replaced deprecated 'vscode.previewHtml' command to the webview API.
### 1.0.14
Updated deps and moved to latest VS code engine.

View File

@ -1,4 +1,4 @@
<link rel="stylesheet" href="file:///${style}">
<link rel="stylesheet" href="${style}">
<div class="profile">
<h3> ${profile.user} <sup>${profile.level}</sup> ${profile.total_xp} xp
<% if( profile.new_xp > 0 ) { %>

View File

@ -2,13 +2,14 @@
"name": "code-stats-vscode",
"displayName": "Code::Stats",
"description": "Code::Stats package for Visual Studio Code",
"version": "1.0.14",
"version": "1.0.15",
"license": "MIT",
"publisher": "riussi",
"contributors": [
"Valentin Ivanov (https://github.com/scout119)",
"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)"
],
"icon": "logo.png",
"repository": {

View File

@ -2,6 +2,7 @@
import * as fs from 'fs';
import { CancellationToken, Event, ExtensionContext, TextDocumentContentProvider, Uri } from "vscode";
import { CodeStatsAPI } from "./code-stats-api";
import * as path from 'path';
import template = require('lodash.template');
@ -88,7 +89,10 @@ export class ProfileProvider implements TextDocumentContentProvider {
let html = template(htmlTemplate);
return html({profile: profile, languages: languages, machines: machines, style: this.context.asAbsolutePath("assets/profile.css")});
const stylePath = Uri.file(path.join(this.context.extensionPath, 'assets', 'profile.css'));
const styleSrc = stylePath.with({scheme: 'vscode-resource'});
return html({profile: profile, languages: languages, machines: machines, style: styleSrc});
});
}

View File

@ -1,4 +1,3 @@
// tslint:disable-next-line:max-line-length
import {
Disposable,
workspace,
@ -10,13 +9,13 @@ import {
TextDocument,
StatusBarAlignment,
TextDocumentChangeEvent,
Range,
WorkspaceConfiguration,
ExtensionContext
} from "vscode";
import { Pulse } from "./pulse";
import { CodeStatsAPI } from "./code-stats-api";
import { ProfileProvider } from "./profile-provider";
import * as path from 'path';
export class XpCounter {
private combinedDisposable: Disposable;
@ -25,23 +24,11 @@ export class XpCounter {
private api: CodeStatsAPI;
private updateTimeout: any;
// private languages: Array<string> = ["typescript", "javascript"];
// wait 10s after each change in the document before sending an update
private UPDATE_DELAY = 10000;
constructor(context: ExtensionContext) {
this.pulse = new Pulse();
/* // print out supported language names
let allLanguages = languages.getLanguages().then(
(result => {
console.log(JSON.stringify(result));
})
);
*/
this.initAPI();
let subscriptions: Disposable[] = [];
@ -69,7 +56,18 @@ export class XpCounter {
return;
}
commands.executeCommand('vscode.previewHtml', Uri.parse('code-stats://profile'), ViewColumn.Two, 'Code::Stats Profile');
const panel = window.createWebviewPanel(
'codeStatsPanel',
'Code::Stats Profile',
ViewColumn.Two,
{
localResourceRoots: [Uri.file(path.join(context.extensionPath, 'assets'))]
}
);
workspace.openTextDocument(Uri.parse('code-stats://profile')).then((value) => {
panel.webview.html = value.getText();
});
}));
workspace.onDidChangeTextDocument(
@ -154,7 +152,7 @@ export class XpCounter {
`
);
if( this.api != null )
if(this.api != null )
this.api.updateSettings(apiKey, apiURL, userName);
else
this.api = new CodeStatsAPI(apiKey,apiURL,userName);