Output c pane
This commit is contained in:
@@ -54,12 +54,12 @@ public class WorkspaceManager(DiagnosticsPublisher diagnosticsPublisher, ILangua
|
|||||||
{
|
{
|
||||||
var modules = Module.Collect(_syntaxTrees.Select(x => x.Value).ToList());
|
var modules = Module.Collect(_syntaxTrees.Select(x => x.Value).ToList());
|
||||||
|
|
||||||
foreach (var (documentUri, syntaxTree) in _syntaxTrees)
|
foreach (var (fsPath, syntaxTree) in _syntaxTrees)
|
||||||
{
|
{
|
||||||
var typeChecker = new TypeChecker(syntaxTree, modules);
|
var typeChecker = new TypeChecker(syntaxTree, modules);
|
||||||
var result = typeChecker.Check();
|
var result = typeChecker.Check();
|
||||||
diagnosticsPublisher.Publish(documentUri, typeChecker.Diagnostics);
|
diagnosticsPublisher.Publish(fsPath, typeChecker.Diagnostics);
|
||||||
_compilationUnits[documentUri] = result;
|
_compilationUnits[fsPath] = result;
|
||||||
|
|
||||||
var generator = new Generator(result);
|
var generator = new Generator(result);
|
||||||
var c = generator.Emit();
|
var c = generator.Emit();
|
||||||
@@ -67,7 +67,7 @@ public class WorkspaceManager(DiagnosticsPublisher diagnosticsPublisher, ILangua
|
|||||||
server.SendNotification("nub/output", new
|
server.SendNotification("nub/output", new
|
||||||
{
|
{
|
||||||
content = c,
|
content = c,
|
||||||
uri = documentUri
|
path = fsPath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -3,6 +3,8 @@ import vscode from 'vscode';
|
|||||||
import { LanguageClient, TransportKind } from 'vscode-languageclient/node';
|
import { LanguageClient, TransportKind } from 'vscode-languageclient/node';
|
||||||
|
|
||||||
let client: LanguageClient;
|
let client: LanguageClient;
|
||||||
|
let outputPanel: vscode.WebviewPanel | undefined;
|
||||||
|
const outputCache = new Map<string, string>();
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
const serverExecutable = path.join(context.asAbsolutePath('server'), "nublsp");
|
const serverExecutable = path.join(context.asAbsolutePath('server'), "nublsp");
|
||||||
@@ -33,16 +35,128 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
client.onNotification("nub/output", (params: { path: string, content: string }) => {
|
client.onNotification("nub/output", (params: { path: string, content: string }) => {
|
||||||
|
const normalizedPath = vscode.Uri.file(params.path).fsPath;
|
||||||
|
outputCache.set(normalizedPath, params.content);
|
||||||
|
|
||||||
|
if (outputPanel && vscode.window.activeTextEditor) {
|
||||||
|
const activePath = vscode.window.activeTextEditor.document.uri.fsPath;
|
||||||
|
if (activePath === normalizedPath) {
|
||||||
|
updateOutputPanel(params.content);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
vscode.commands.registerCommand('nub.openOutput', async () => {
|
const openOutputCommand = vscode.commands.registerCommand('nub.openOutput', async () => {
|
||||||
|
const editor = vscode.window.activeTextEditor;
|
||||||
|
|
||||||
|
if (!editor) {
|
||||||
|
vscode.window.showWarningMessage('No active editor found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filePath = editor.document.uri.fsPath;
|
||||||
|
const cachedOutput = outputCache.get(filePath);
|
||||||
|
|
||||||
|
if (outputPanel) {
|
||||||
|
outputPanel.reveal(vscode.ViewColumn.Beside);
|
||||||
|
} else {
|
||||||
|
outputPanel = vscode.window.createWebviewPanel(
|
||||||
|
'nubOutput',
|
||||||
|
'C Output',
|
||||||
|
vscode.ViewColumn.Beside,
|
||||||
|
{
|
||||||
|
enableScripts: true,
|
||||||
|
retainContextWhenHidden: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
outputPanel.onDidDispose(() => {
|
||||||
|
outputPanel = undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cachedOutput) {
|
||||||
|
updateOutputPanel(cachedOutput);
|
||||||
|
} else {
|
||||||
|
updateOutputPanel('// Waiting for C output...');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const changeEditorSubscription = vscode.window.onDidChangeActiveTextEditor(editor => {
|
||||||
|
if (outputPanel && editor) {
|
||||||
|
const filePath = editor.document.uri.fsPath;
|
||||||
|
const cachedOutput = outputCache.get(filePath);
|
||||||
|
|
||||||
|
if (cachedOutput) {
|
||||||
|
updateOutputPanel(cachedOutput);
|
||||||
|
} else {
|
||||||
|
updateOutputPanel('// No C output available for this file');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
context.subscriptions.push(openOutputCommand, changeEditorSubscription);
|
||||||
|
|
||||||
client.start();
|
client.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateOutputPanel(content: string) {
|
||||||
|
if (!outputPanel) return;
|
||||||
|
|
||||||
|
outputPanel.webview.html = getWebviewContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWebviewContent(content: string): string {
|
||||||
|
const escapedContent = content
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''');
|
||||||
|
|
||||||
|
return `<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Nub C Output</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/vs2015.min.css">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 16px;
|
||||||
|
font-family: 'Consolas', 'Courier New', monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.5;
|
||||||
|
background-color: var(--vscode-editor-background);
|
||||||
|
color: var(--vscode-editor-foreground);
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
margin: 0;
|
||||||
|
background-color: transparent !important;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
code {
|
||||||
|
font-family: 'Consolas', 'Courier New', monospace;
|
||||||
|
background-color: transparent !important;
|
||||||
|
}
|
||||||
|
.hljs {
|
||||||
|
background-color: transparent;
|
||||||
|
color: var(--vscode-editor-foreground);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<pre><code class="language-c" id="code-content">${escapedContent}</code></pre>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/c.min.js"></script>
|
||||||
|
<script>
|
||||||
|
hljs.highlightAll();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
}
|
||||||
|
|
||||||
export function deactivate(): Thenable<void> | undefined {
|
export function deactivate(): Thenable<void> | undefined {
|
||||||
if (!client) {
|
if (!client) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user