101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
import {
|
|
LanguageClient,
|
|
LanguageClientOptions,
|
|
ServerOptions,
|
|
TransportKind,
|
|
} from 'vscode-languageclient/node'
|
|
import * as vscode from 'vscode'
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
const serverModule = context.asAbsolutePath('server/dist/server.js')
|
|
|
|
const serverOptions: ServerOptions = {
|
|
run: { module: serverModule, transport: TransportKind.ipc },
|
|
debug: { module: serverModule, transport: TransportKind.ipc },
|
|
}
|
|
|
|
const clientOptions: LanguageClientOptions = {
|
|
documentSelector: [{ scheme: 'file', language: 'shrimp' }],
|
|
}
|
|
|
|
const client = new LanguageClient(
|
|
'shrimpLanguageServer',
|
|
'Shrimp Language Server',
|
|
serverOptions,
|
|
clientOptions,
|
|
)
|
|
|
|
client.start()
|
|
context.subscriptions.push(client)
|
|
|
|
// Command: Show Parse Tree
|
|
context.subscriptions.push(
|
|
vscode.commands.registerCommand('shrimp.showParseTree', async () => {
|
|
const editor = vscode.window.activeTextEditor
|
|
if (!editor || editor.document.languageId !== 'shrimp') {
|
|
vscode.window.showErrorMessage('No active Shrimp file')
|
|
return
|
|
}
|
|
|
|
const result = await client.sendRequest<string>('shrimp/parseTree', {
|
|
uri: editor.document.uri.toString(),
|
|
})
|
|
|
|
const doc = await vscode.workspace.openTextDocument({
|
|
content: result,
|
|
language: 'text',
|
|
})
|
|
await vscode.window.showTextDocument(doc, { preview: false })
|
|
}),
|
|
)
|
|
|
|
// Command: Show Bytecode
|
|
context.subscriptions.push(
|
|
vscode.commands.registerCommand('shrimp.showBytecode', async () => {
|
|
const editor = vscode.window.activeTextEditor
|
|
if (!editor || editor.document.languageId !== 'shrimp') {
|
|
vscode.window.showErrorMessage('No active Shrimp file')
|
|
return
|
|
}
|
|
|
|
const result = await client.sendRequest<string>('shrimp/bytecode', {
|
|
uri: editor.document.uri.toString(),
|
|
})
|
|
|
|
const doc = await vscode.workspace.openTextDocument({
|
|
content: result,
|
|
language: 'text',
|
|
})
|
|
await vscode.window.showTextDocument(doc, { preview: false })
|
|
}),
|
|
)
|
|
|
|
// Command: Run File
|
|
context.subscriptions.push(
|
|
vscode.commands.registerCommand('shrimp.run', async () => {
|
|
const editor = vscode.window.activeTextEditor
|
|
if (!editor || editor.document.languageId !== 'shrimp') {
|
|
vscode.window.showErrorMessage('No active Shrimp file')
|
|
return
|
|
}
|
|
|
|
// Auto-save before running
|
|
await editor.document.save()
|
|
|
|
// Get binary path from settings
|
|
const config = vscode.workspace.getConfiguration('shrimp')
|
|
const binaryPath = config.get<string>('binaryPath', 'shrimp')
|
|
|
|
// Get the file path
|
|
const filePath = editor.document.uri.fsPath
|
|
|
|
// Create or show terminal
|
|
const terminal = vscode.window.createTerminal('Shrimp')
|
|
terminal.show()
|
|
terminal.sendText(`${binaryPath} "${filePath}"`)
|
|
}),
|
|
)
|
|
}
|
|
|
|
export function deactivate() {}
|