A Visual Studio Code extension for Pterodactyl

Working on the panel

+139 -37
+11 -2
package.json
··· 9 9 "categories": [ 10 10 "Other" 11 11 ], 12 - "activationEvents": [], 12 + "activationEvents": [ 13 + ], 13 14 "main": "./out/extension.js", 14 15 "contributes": { 15 16 "commands": [ 16 17 { 17 18 "command": "pterodactyl-language-client.helloWorld", 18 19 "title": "Hello World" 20 + } 21 + ], 22 + "languages": [ 23 + { 24 + "id": "pterodactyl", 25 + "aliases": ["Pterodactyl", "pterodactyl"], 26 + "extensions": [".ptero"], 27 + "configuration": "./language-configuration.json" 19 28 } 20 29 ] 21 30 }, ··· 41 50 "dependencies": { 42 51 "vscode-languageclient": "^9.0.1" 43 52 } 44 - } 53 + }
+56
src/AssistantPanelController.ts
··· 1 + import * as vscode from 'vscode'; 2 + 3 + export class AssistantPanelController { 4 + constructor(private context: vscode.ExtensionContext) { } 5 + 6 + private _panel: vscode.WebviewPanel | undefined; 7 + private getPanel(): vscode.WebviewPanel { 8 + if (this._panel) { return this._panel; } 9 + 10 + const panel = vscode.window.createWebviewPanel( 11 + 'pterodactylProofAssistant', 12 + 'Proof Assistant', 13 + { viewColumn: vscode.ViewColumn.Beside, preserveFocus: true }, 14 + { enableScripts: true, retainContextWhenHidden: true } 15 + ); 16 + 17 + panel.onDidDispose(() => { 18 + this._panel = undefined; 19 + }); 20 + 21 + this._panel = panel; 22 + return panel; 23 + } 24 + 25 + public update(editor?: vscode.TextEditor) { 26 + // Ignore non-text editors (e.g., clicking the panel itself) 27 + if (!editor?.document) { return; } 28 + 29 + const isPtero = editor.document.languageId === 'pterodactyl'; 30 + if (isPtero) { 31 + const panel = this.getPanel(); 32 + panel.webview.html = this.getHtml(editor.document.fileName); 33 + panel.reveal(vscode.ViewColumn.Beside, true); 34 + } else { 35 + this._panel?.dispose(); 36 + } 37 + } 38 + 39 + private getHtml(fileName?: string) { 40 + if (fileName) { 41 + return `<html> 42 + <body> 43 + <h2>Proof Assistant</h2> 44 + <p>Active file: <code>${fileName}</code></p> 45 + </body> 46 + </html>`; 47 + } else { 48 + return `<html> 49 + <body> 50 + <h2>Proof Assistant</h2> 51 + <pre>No <code>.ptero</code> file active</pre> 52 + </body> 53 + </html>`; 54 + } 55 + } 56 + }
+57 -19
src/extension.ts
··· 1 - // The module 'vscode' contains the VS Code extensibility API 2 - // Import the module and reference it with the alias vscode in your code below 1 + import * as path from 'path'; 3 2 import * as vscode from 'vscode'; 3 + import { workspace, ExtensionContext } from 'vscode'; 4 + import { 5 + LanguageClient, 6 + LanguageClientOptions, 7 + ServerOptions, 8 + TransportKind, 9 + Trace 10 + } from 'vscode-languageclient/node'; 4 11 5 - // This method is called when your extension is activated 6 - // Your extension is activated the very first time the command is executed 7 - export function activate(context: vscode.ExtensionContext) { 12 + import { AssistantPanelController } from './AssistantPanelController'; 8 13 9 - // Use the console to output diagnostic information (console.log) and errors (console.error) 10 - // This line of code will only be executed once when your extension is activated 11 - console.log('Congratulations, your extension "pterodactyl-language-client" is now active!'); 14 + let client: LanguageClient | undefined; 12 15 13 - // The command has been defined in the package.json file 14 - // Now provide the implementation of the command with registerCommand 15 - // The commandId parameter must match the command field in package.json 16 - const disposable = vscode.commands.registerCommand('pterodactyl-language-client.helloWorld', () => { 17 - // The code you place here will be executed every time your command is executed 18 - // Display a message box to the user 19 - vscode.window.showInformationMessage('Hello World from pterodactyl-language-client!'); 20 - }); 16 + export function activate(context: ExtensionContext) { 17 + console.log("Jon activate!"); 18 + 19 + let assistantPanelController = new AssistantPanelController(context); 20 + 21 + // Update panel whenever the active editor changes 22 + context.subscriptions.push( 23 + vscode.window.onDidChangeActiveTextEditor(editor => assistantPanelController.update(editor)) 24 + ); 21 25 22 - context.subscriptions.push(disposable); 26 + // Populate panel for the editor open at activation 27 + assistantPanelController.update(vscode.window.activeTextEditor); 28 + 29 + // Path to your language server executable 30 + // If it’s a Swift binary, give the absolute path 31 + const serverCommand = "/Users/jon/Developer/swift-pterodactyl/.build/debug/PterodactylLanguageServer"; 32 + 33 + const serverOptions: ServerOptions = { 34 + command: serverCommand, 35 + args: [], 36 + transport: TransportKind.stdio 37 + }; 38 + 39 + const clientOptions: LanguageClientOptions = { 40 + documentSelector: [{ scheme: 'file', language: 'pterodactyl' }], 41 + synchronize: { 42 + fileEvents: workspace.createFileSystemWatcher('**/*.ptero') 43 + }, 44 + outputChannel: vscode.window.createOutputChannel("Pterodactyl Server"), 45 + traceOutputChannel: vscode.window.createOutputChannel('LSP Trace'), 46 + }; 47 + 48 + client = new LanguageClient( 49 + 'pterodactylLanguageServer', // ID 50 + 'Pterodactyl Language Server', // Name 51 + serverOptions, 52 + clientOptions 53 + ); 54 + 55 + client.setTrace(Trace.Verbose); 56 + client.start(); 23 57 } 24 58 25 - // This method is called when your extension is deactivated 26 - export function deactivate() {} 59 + export function deactivate(): Thenable<void> | undefined { 60 + if (!client) { 61 + return undefined; 62 + } 63 + return client.stop(); 64 + }
+15 -16
tsconfig.json
··· 1 1 { 2 - "compilerOptions": { 3 - "module": "Node16", 4 - "target": "ES2022", 5 - "outDir": "out", 6 - "lib": [ 7 - "ES2022" 8 - ], 9 - "sourceMap": true, 10 - "rootDir": "src", 11 - "strict": true, /* enable all strict type-checking options */ 12 - /* Additional Checks */ 13 - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 14 - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 15 - // "noUnusedParameters": true, /* Report errors on unused parameters. */ 16 - } 17 - } 2 + "compilerOptions": { 3 + "module": "commonjs", // VS Code extensions use CommonJS 4 + "target": "es2020", // Modern enough for Node 14+ 5 + "outDir": "out", // Compiled JS goes here 6 + "lib": ["es2020"], // JS standard library 7 + "sourceMap": true, // Optional, useful for debugging 8 + "rootDir": "src", // Source TypeScript files 9 + "strict": true, // Enable strict type checking 10 + "esModuleInterop": true, // Needed for importing some modules 11 + "resolveJsonModule": true, // Optional, for importing JSON 12 + "skipLibCheck": true // Skip checking node_modules types 13 + }, 14 + "include": ["src"], 15 + "exclude": ["node_modules", "out"] 16 + }