Skip to content

Commit 98468ef

Browse files
committed
add: style & javascript
1 parent 124f22e commit 98468ef

File tree

11 files changed

+10598
-832
lines changed

11 files changed

+10598
-832
lines changed

prova_test/es2/nucleo/myfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"command": "process_list", "process": [{"pid": 0, "livello": "sistema", "corpo": "sistema:dummy(0)", "rip": " 0x20019a <halt+1>", "campi_aggiuntivi": {"barrier_id": ["4294967295"]}}, {"pid": 3, "livello": "sistema", "corpo": "io:estern_kbd(0)", "rip": " 0x1000000062b <estern_kbd(int)>", "campi_aggiuntivi": {"barrier_id": ["4294967295"]}}, {"pid": 4, "livello": "sistema", "corpo": "io:estern_hd(0)", "rip": " 0x10000000f3f <estern_hd(int)>", "campi_aggiuntivi": {"barrier_id": ["4294967295"]}}, {"pid": 6, "livello": "utente", "corpo": "utente:main_body(0)", "rip": "0xffff800000001c15 <sem_wait+2>", "campi_aggiuntivi": {"barrier_id": ["4294967295"]}}, {"pid": 12, "livello": "utente", "corpo": "utente:t03p0b(3)", "rip": "0xffff800000001c3f <barrier+2>", "campi_aggiuntivi": {"barrier_id": ["2"]}}]}
1+
{"command": "process_list", "process": []}

vscode-cpptools/Extension/package-lock.json

Lines changed: 9519 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode-cpptools/Extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6539,6 +6539,7 @@
65396539
"editorconfig": "^2.0.0",
65406540
"escape-string-regexp": "^2.0.0",
65416541
"glob": "^7.2.3",
6542+
"handlebars": "^4.7.8",
65426543
"minimatch": "^3.0.5",
65436544
"mkdirp": "^3.0.1",
65446545
"node-fetch": "^2.7.0",

vscode-cpptools/Extension/src/main.ts

Lines changed: 20 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ import { logMachineIdMappings } from './id';
2626
import { disposeOutputChannels, log } from './logger';
2727
import { PlatformInformation } from './platform';
2828
// load the custom webview
29-
import { getWebviewContent } from './nucleoweb';
30-
31-
//webview variables
32-
let panel: vscode.WebviewPanel;
33-
29+
import { NucleoInfo } from './nucleoweb';
3430

3531
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
3632
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
@@ -149,84 +145,32 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
149145
}
150146
});
151147

152-
vscode.debug.onDidChangeActiveDebugSession((event) =>{
153-
console.log("----------------CHANGE----------------");
154-
console.log(event);
155-
console.log("--------------END CHANGE--------------");
156-
});
157-
158-
vscode.debug.onDidReceiveDebugSessionCustomEvent((event) =>{
159-
console.log("----------------EVENT----------------");
160-
console.log(event);
161-
console.log("--------------END EVENT--------------");
162-
});
148+
// vscode.debug.onDidChangeActiveDebugSession((event) =>{
149+
// console.log("----------------CHANGE----------------");
150+
// console.log(event);
151+
// console.log("--------------END CHANGE--------------");
152+
// });
153+
154+
// vscode.debug.onDidReceiveDebugSessionCustomEvent((event) =>{
155+
// console.log("----------------EVENT----------------");
156+
// console.log(event);
157+
// console.log("--------------END EVENT--------------");
158+
// });
163159

164160

165161
vscode.debug.onDidStartDebugSession( async ()=>{
166-
panel = vscode.window.createWebviewPanel(
167-
'customCommand', // Identifies the type of the webview. Used internally
168-
'Nucleo Infos', // Title of the panel displayed to the user
169-
vscode.ViewColumn.Beside, // Editor column to show the new webview panel in.
170-
{
171-
enableScripts: true
172-
} // Webview options. More on these later.
173-
);
174-
175-
await new Promise(resolve => setImmediate(resolve));
176-
const session = vscode.debug.activeDebugSession;
177-
178-
panel.webview.html = getWebviewContent('<img src="https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif" width="300" />');
179-
// console.log("------------------START----------------");
180-
// console.log(session);
181-
// console.log("----------------END START--------------");
182-
const updateWebview = async () => {
183-
if (session) {
184-
const sTrace = await session.customRequest('stackTrace', { threadId: 1 });
185-
if(sTrace.stackFrames[0].id === undefined){
186-
return;
187-
}
188-
const frameId = sTrace.stackFrames[0].id;
189-
190-
// build and exec the command, in this case info registers
191-
const text = '-exec process list';
192-
console.log(sTrace);
193-
// const arg : DebugProtocol.EvaluateArguments = {expression: text, frameId: frameId, context:'hover'};
194-
session.customRequest('evaluate', {expression: text, frameId: frameId, context:'hover'}).then((response) => {
195-
// console.log("------------------EVAL----------------");
196-
// console.log(response.result);
197-
// console.log("----------------END EVAL--------------");
198-
// panel.webview.html = getWebviewContent(response.result);
199-
panel.webview.postMessage({ command: response.result });
200-
});
201-
}
202-
};
203-
204-
// Set initial content
205-
updateWebview();
206-
207-
// And schedule updates to the content every second
208-
const interval = setInterval(updateWebview, 500);
209-
210-
panel.onDidDispose(
211-
() => {
212-
// When the panel is closed, cancel any future updates to the webview content
213-
clearInterval(interval);
214-
},
215-
null,
216-
context.subscriptions
217-
);
218-
162+
NucleoInfo.createInfoPanel(context.extensionUri);
219163
});
220164

221-
vscode.debug.onDidTerminateDebugSession(() => {
222-
panel.dispose();
223-
})
224-
225-
//A custom VSCode command to retrieve information on nucleo
226-
const disposable = vscode.commands.registerCommand("C_Cpp.nucleoInfo", async ()=>{
165+
vscode.debug.onDidTerminateDebugSession(() =>{
166+
NucleoInfo.currentPanel?.dispose();
227167
});
168+
169+
// Register a custom VSCode command to retrieve information on nucleo
170+
// const disposable = vscode.commands.registerCommand("C_Cpp.nucleoInfo", async ()=>{
171+
// });
172+
// context.subscriptions.push(disposable);
228173

229-
context.subscriptions.push(disposable);
230174

231175
if (shouldActivateLanguageServer) {
232176
await LanguageServer.activate();
Lines changed: 175 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,177 @@
1-
// create a webpage and return it
2-
export function getWebviewContent(boiler: any) {
3-
return `<!DOCTYPE html>
4-
<html lang="en">
5-
<head>
6-
<meta charset="UTF-8">
7-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8-
<title>Cat Coding</title>
9-
</head>
10-
<body>
11-
Processi in Esecuzione:</br>
12-
<p id="lines-of-code-counter">0</p>
13-
14-
15-
//git rebase
16-
<script>
17-
const counter = document.getElementById('lines-of-code-counter');
18-
19-
// Handle the message inside the webview
20-
window.addEventListener('message', event => {
21-
counter.textContent = event.data.command;
22-
const message = event.data; // The JSON data our extension sent
23-
24-
});
25-
</script>
26-
</body>
27-
</html>`;
1+
import * as vscode from 'vscode';
2+
const Handlebars = require('handlebars');
3+
4+
let interval: NodeJS.Timeout;
5+
6+
export class NucleoInfo {
7+
public static currentPanel: NucleoInfo | undefined;
8+
9+
public static readonly viewType = 'nucleoInfo';
10+
11+
public process_list: any | undefined;
12+
private readonly _extensionUri: vscode.Uri;
13+
// delare you new variable
14+
// public VAR: any | undefined;
15+
16+
private readonly _panel: vscode.WebviewPanel;
17+
private _disposables: vscode.Disposable[] = [];
18+
private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
19+
this._panel = panel;
20+
this._extensionUri = extensionUri;
21+
// Set the webview's initial html content
22+
this._update();
23+
24+
// Listen for when the panel is disposed
25+
// This happens when the user closes the panel or when the panel is closed programmatically
26+
this._panel.onDidDispose(() => this.dispose(), null, this._disposables);
27+
28+
// Update the content based on view changes (moved around the window)
29+
// this._panel.onDidChangeViewState(
30+
// e => {
31+
// if (this._panel.visible) {
32+
// this._update();
33+
// }
34+
// },
35+
// null,
36+
// this._disposables
37+
// );
38+
39+
// This can be useful if you need to handle input from the webview
40+
// Handle messages from the webview
41+
// this._panel.webview.onDidReceiveMessage(
42+
// message => {
43+
// switch (message.command) {
44+
// case 'alert':
45+
// vscode.window.showErrorMessage(message.text);
46+
// return;
47+
// }
48+
// },
49+
// null,
50+
// this._disposables
51+
// );
52+
53+
54+
const session = vscode.debug.activeDebugSession;
55+
const updateInfo = async () => {
56+
this.process_list = await this.customCommand(session, "process list");
57+
// Insert you command
58+
// this.VAR = this.customCommand(session, "COMMAND");
59+
60+
const infoPanel = this._panel.webview;
61+
62+
63+
infoPanel.html = this._getHtmlForWebview();
64+
};
65+
66+
interval = setInterval(updateInfo, 500);
67+
}
68+
69+
public dispose() {
70+
// Clean up our resources
71+
NucleoInfo.currentPanel = undefined;
72+
clearInterval(interval);
73+
this._panel.dispose();
74+
}
75+
76+
// Update the webview
77+
private _update() {
78+
// const infoPanel = this._panel.webview;
79+
// infoPanel.html = this._getHtmlForWebview();
80+
}
81+
82+
83+
public static createInfoPanel(extensionUri: vscode.Uri) {
84+
// Otherwise, create a new panel.
85+
const panel = vscode.window.createWebviewPanel(
86+
NucleoInfo.viewType,
87+
'Info Nucleo',
88+
vscode.ViewColumn.Beside,
89+
getWebviewOptions(extensionUri),
90+
);
91+
NucleoInfo.currentPanel = new NucleoInfo(panel, extensionUri);
92+
}
93+
94+
// execute custom command
95+
private async customCommand(session: typeof vscode.debug.activeDebugSession, command: string, arg?: any){
96+
if(session) {
97+
const sTrace = await session.customRequest('stackTrace', { threadId: 1 });
98+
if(sTrace.stackFrames[0] === undefined){
99+
return;
100+
}
101+
const frameId = sTrace.stackFrames[0].id;
102+
103+
// Build and exec the command
104+
const text = '-exec ' + command;
105+
let result = session.customRequest('evaluate', {expression: text, frameId: frameId, context:'hover'}).then((response) => {
106+
return response.result;
107+
});
108+
return result
109+
}
110+
}
111+
112+
private formatProcessList(){
113+
let processListJson = JSON.parse(this.process_list);
114+
115+
let source = `
116+
<div>
117+
<h3 id="palle">Processi in esecuzione:</h3>
118+
{{#each process}}
119+
{{#each this}}
120+
<p>{{@key}}: {{this}}</p>
121+
{{/each}}
122+
{{/each}}
123+
</div>
124+
`;
125+
126+
let template = Handlebars.compile(source);
127+
return template(processListJson);
128+
}
129+
130+
private _getHtmlForWebview() {
131+
const scriptPathOnDisk = vscode.Uri.joinPath(this._extensionUri, 'src/webview', 'main.js');
132+
133+
// And the uri we use to load this script in the webview
134+
const scriptUri = this._panel.webview.asWebviewUri(scriptPathOnDisk);
135+
136+
137+
// Local path to css styles
138+
const styleResetPath = vscode.Uri.joinPath(this._extensionUri, 'src/webview', 'reset.css');
139+
const stylesPathMainPath = vscode.Uri.joinPath(this._extensionUri, 'src/webview', 'vscode.css');
140+
141+
// Uri to load styles into webview
142+
const stylesResetUri = this._panel.webview.asWebviewUri(styleResetPath);
143+
const stylesMainUri = this._panel.webview.asWebviewUri(stylesPathMainPath);
144+
145+
console.log("uwu");
146+
console.log(scriptUri);
147+
let sourceDocument = `
148+
<!DOCTYPE html>
149+
<html lang="en">
150+
<head>
151+
<meta charset="UTF-8">
152+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
153+
<link href="${stylesResetUri}" rel="stylesheet">
154+
<link href="${stylesMainUri}" rel="stylesheet">
155+
<title>Info Nucleo</title>
156+
</head>
157+
<body>
158+
{{{processList}}}
159+
160+
<script src="${scriptUri}"></script>
161+
</body>
162+
</html>
163+
`;
164+
165+
let template = Handlebars.compile(sourceDocument);
166+
return template({ processList: this.formatProcessList() });
167+
}
28168
}
29169

30-
// execute custom command
31-
// export async function executeCustomCommand(session: typeof vscode.debug.activeDebugSession, command: string, arg?: any){
32-
// if(session === undefined){
33-
// console.log("session not valid or undefined");
34-
// return;
35-
// }
36-
// const sTrace = await session.customRequest('stackTrace', { threadId: 1 });
37-
// const frameId = sTrace.stackFrames[0].id;
38-
39-
// // build and exec the command, in this case info registers
40-
// const text = '-exec ' + command;
41-
// // const arg : DebugProtocol.EvaluateArguments = {expression: text, frameId: frameId, context:'hover'};
42-
// session.customRequest('evaluate', {expression: text, frameId: frameId, context:'hover'}).then((response) => {
43-
// console.log("------------------EVAL----------------");
44-
// console.log(response.result);
45-
// console.log("----------------END EVAL--------------");
46-
// return response.result;
47-
// });
48-
// }
170+
171+
172+
function getWebviewOptions(extensionUri: vscode.Uri): vscode.WebviewOptions {
173+
return {
174+
// Enable javascript in the webview
175+
enableScripts: true,
176+
};
177+
}
7.36 MB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es2020",
5+
"jsx": "preserve",
6+
"checkJs": true,
7+
"strict": true,
8+
"strictFunctionTypes": true,
9+
"lib": [
10+
"dom"
11+
]
12+
},
13+
"exclude": [
14+
"node_modules",
15+
"**/node_modules/*"
16+
],
17+
"typeAcquisition": {
18+
"include": [
19+
"@types/vscode-webview"
20+
]
21+
}
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This script will be run within the webview itself
2+
// It cannot access the main VS Code APIs directly.
3+
4+
(function () {
5+
document.addEventListener("DOMContentLoaded", function(){
6+
7+
});
8+
}());

0 commit comments

Comments
 (0)