Moved to vscode provided global file storage path to DL glslangValidator

This commit is contained in:
Noah Santschi-Cooney 2020-07-18 23:11:26 +01:00
parent 39143aefc7
commit f7310c1573
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
11 changed files with 62 additions and 150 deletions

View file

@ -1,23 +1,20 @@
import * as vscode from 'vscode'
import * as lsp from 'vscode-languageclient'
import * as commands from './commands'
import { promptDownload, testExecutable } from './glslangValidator'
import { bootstrapGLSLangValidator } from './glslangValidator'
import { log } from './log'
import { LanguageClient } from './lspClient'
export const glslConfigParam = 'mcglsl.glslangValidatorPath'
export let statusBarItem: vscode.StatusBarItem | null = null
export class Extension {
private statusBarItem: vscode.StatusBarItem | null = null
private extensionContext: vscode.ExtensionContext | null = null
private client: lsp.LanguageClient
public get context() : vscode.ExtensionContext {
public get context(): vscode.ExtensionContext {
return this.extensionContext
}
public get lspClient() : lsp.LanguageClient {
public get lspClient(): lsp.LanguageClient {
return this.client
}
@ -26,17 +23,14 @@ export class Extension {
this.registerCommand('graphDot', commands.generateGraphDot)
this.registerCommand('restart', commands.restartExtension)
if (!testExecutable(vscode.workspace.getConfiguration().get(glslConfigParam) as string)) {
if(!await promptDownload(this)) return
}
if(!await bootstrapGLSLangValidator(this)) return
log.info('starting language server...')
this.client = await new LanguageClient(this).startServer()
log.info('language server started!')
}
registerCommand = (name: string, f: (e: Extension) => commands.Command) => {
@ -52,17 +46,16 @@ export class Extension {
}
public updateStatus = (icon: string, text: string) => {
statusBarItem?.dispose()
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left)
statusBarItem.text = icon + ' [mc-shader] ' + text
statusBarItem.show()
this.context.subscriptions.push(statusBarItem)
this.statusBarItem?.dispose()
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left)
this.statusBarItem.text = icon + ' [mc-shader] ' + text
this.statusBarItem.show()
this.context.subscriptions.push(this.statusBarItem)
}
public clearStatus = () => {
statusBarItem?.dispose()
this.statusBarItem?.dispose()
}
}
export const activate = new Extension().activate

View file

@ -1,10 +1,11 @@
import * as unzip from 'adm-zip'
import { execSync } from 'child_process'
import * as fs from 'fs'
import { writeFileSync } from 'fs'
import fetch from 'node-fetch'
import { platform } from 'os'
import * as vscode from 'vscode'
import { Extension, glslConfigParam } from './extension'
import { Extension } from './extension'
import { log } from './log'
const url = {
@ -15,9 +16,17 @@ const url = {
const config = vscode.workspace.getConfiguration()
export async function promptDownload(e: Extension): Promise<boolean> {
export async function bootstrapGLSLangValidator(e: Extension): Promise<boolean> {
const glslangValidatorPath = config.get('mcglsl.glslangValidatorPath') as string
if (!testExecutable(glslangValidatorPath)) {
if(!await promptDownload(e, glslangValidatorPath)) return false
}
return true
}
async function promptDownload(e: Extension, glslangValidatorPath: string): Promise<boolean> {
const chosen = await vscode.window.showErrorMessage(
`[mc-glsl] glslangValidator not found at: '${config.get(glslConfigParam)}'.`,
`[mc-glsl] glslangValidator not found at: '${glslangValidatorPath}'.`,
{title: 'Download'},
{title: 'Cancel'}
)
@ -40,10 +49,12 @@ async function tryInstallExecutable(e: Extension): Promise<boolean> {
}
async function installExecutable(e: Extension) {
fs.mkdirSync(e.context.globalStoragePath, { recursive: true })
e.updateStatus('$(cloud-download)', 'Downloading glslangValidator')
const glslangBin = '/glslangValidator' + (platform() === 'win32' ? '.exe' : '')
const glslangPath = config.get('mcglsl.shaderpacksPath') + glslangBin
const glslangPath = e.context.globalStoragePath + glslangBin
const response = await fetch(url[platform()])
log.info('glslangValidator download response status: ' + response.status)
@ -64,12 +75,11 @@ async function installExecutable(e: Extension) {
vscode.window.showInformationMessage(
`glslangValidator has been downloaded to ${glslangPath}. Your config should be updated automatically.`
)
config.update('mcglsl.glslangValidatorPath', glslangPath, vscode.ConfigurationTarget.Global)
await config.update('mcglsl.glslangValidatorPath', glslangPath, vscode.ConfigurationTarget.Global)
e.clearStatus()
}
export function testExecutable(glslangPath?: string): boolean {
glslangPath = glslangPath || config.get(glslConfigParam)
function testExecutable(glslangPath: string): boolean {
let stdout = ''
try {
stdout = execSync(glslangPath, {

View file

@ -1,5 +1,7 @@
import { inspect } from 'util'
import * as vscode from 'vscode'
import { inspect } from 'util';
import * as vscode from 'vscode';
export const lspOutputChannel = vscode.window.createOutputChannel('Minecraft Shaders Language Server')
// from rust-analyzer https://github.com/rust-analyzer/rust-analyzer/blob/ef223b9e6439c228e0be49861efd2067c0b22af4/editors/code/src/util.ts
export const log = new class {
@ -37,30 +39,3 @@ export const log = new class {
}
}
export const lspExceptionLogger = new class implements vscode.OutputChannel {
name: string
append(value: string): void {
log.write('LSP-F', value)
}
appendLine(value: string): void {
log.write('LSP-F', value)
}
clear(): void {
log.output.clear()
}
show(column?: any, preserveFocus?: any) {
log.output.show(column, preserveFocus)
}
hide(): void {
log.output.hide()
}
dispose(): void {
log.output.dispose()
}
}

View file

@ -2,7 +2,7 @@ import * as path from 'path'
import { ConfigurationTarget, workspace } from 'vscode'
import * as lsp from 'vscode-languageclient'
import { Extension } from './extension'
import { lspExceptionLogger } from './log'
import { lspOutputChannel } from './log'
import { ConfigUpdateParams, statusMethod, StatusParams, updateConfigMethod } from './lspExt'
export class LanguageClient extends lsp.LanguageClient {
@ -13,7 +13,7 @@ export class LanguageClient extends lsp.LanguageClient {
command: ext.context.asAbsolutePath(path.join('server', 'target', 'debug', 'vscode-mc-shader')),
}, {
documentSelector: [{scheme: 'file', language: 'glsl'}],
outputChannel: lspExceptionLogger,
outputChannel: lspOutputChannel,
synchronize: {
configurationSection: 'mcglsl',
fileEvents: workspace.createFileSystemWatcher('**/*.{fsh,gsh,vsh,glsl}')