Added "Show flattened file" command to display a fully flattened top-level file in vscode virtual doc

execute_command now returns content to the client on success, any valid json value
This commit is contained in:
Noah Santschi-Cooney 2021-01-10 23:39:27 +00:00
parent 49324cfb04
commit 26c855f016
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
8 changed files with 224 additions and 109 deletions

View file

@ -1,7 +1,6 @@
import * as vscode from 'vscode'
import * as lsp from 'vscode-languageclient'
import { Extension } from './extension'
import { tryInstallExecutable } from './glslangValidator'
import { log } from './log'
export type Command = (...args: any[]) => unknown
@ -23,8 +22,31 @@ export function restartExtension(e: Extension): Command {
}
}
export function downloadValidator(e: Extension): Command {
export function virtualMergedDocument(e: Extension): Command {
const getVirtualDocument = async (path: string): Promise<string> => {
const content = await e.lspClient.sendRequest<string>(lsp.ExecuteCommandRequest.type.method, {
command: 'virtualMerge',
arguments: [path]
})
return content
}
const docProvider = new class implements vscode.TextDocumentContentProvider {
onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
onDidChange = this.onDidChangeEmitter.event;
provideTextDocumentContent(uri: vscode.Uri, __: vscode.CancellationToken): vscode.ProviderResult<string> {
return getVirtualDocument(uri.path)
}
}
e.context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('mcglsl', docProvider))
return async () => {
await tryInstallExecutable(e)
const uri = vscode.window.activeTextEditor.document.uri
const path = vscode.Uri.parse('mcglsl:' + uri.path)
const doc = await vscode.workspace.openTextDocument(path)
await vscode.window.showTextDocument(doc, {preview: true})
}
}

View file

@ -1,7 +1,6 @@
import * as vscode from 'vscode'
import * as lsp from 'vscode-languageclient'
import * as commands from './commands'
import { bootstrapGLSLangValidator } from './glslangValidator'
import { log } from './log'
import { LanguageClient } from './lspClient'
@ -23,10 +22,8 @@ export class Extension {
this.registerCommand('graphDot', commands.generateGraphDot)
this.registerCommand('restart', commands.restartExtension)
this.registerCommand('downlaod', commands.downloadValidator)
this.registerCommand('virtualMerge', commands.virtualMergedDocument)
if(!await bootstrapGLSLangValidator(this)) return
log.info('starting language server...')
this.client = await new LanguageClient(this).startServer()