Doing more on the extension side and splitting up the lang server linting more

This commit is contained in:
Noah Santschi-Cooney 2018-07-13 18:16:50 +01:00
parent d7d41985ef
commit cacfbe7a4e
6 changed files with 120 additions and 40 deletions

39
client/src/config.ts Normal file
View file

@ -0,0 +1,39 @@
import * as vscode from 'vscode'
import { execSync } from 'child_process'
import * as vscodeLang from 'vscode-languageclient'
export class Config {
public readonly shaderpacksPath: string
public readonly glslangPath: string
constructor(shaderpacksPath: string, glslangPath: string) {
this.shaderpacksPath = shaderpacksPath
this.glslangPath = glslangPath || 'glslangValidator'
}
}
let conf = new Config('', '')
export async function configChangeHandler(langServer: vscodeLang.LanguageClient, event?: vscode.ConfigurationChangeEvent) {
if (event && !event.affectsConfiguration('mcglsl')) return
const temp = vscode.workspace.getConfiguration('mcglsl')
conf = new Config(temp.get('shaderpacksPath'), temp.get('glslangValidatorPath'))
try {
execSync(conf.glslangPath)
langServer.sendNotification(vscodeLang.DidChangeConfigurationNotification.type)
} catch (e) {
if (e.status !== 1) {
const selected = await vscode.window.showErrorMessage(
`[mc-glsl] glslangValidator not found at: '${conf.glslangPath}' or returned non-0 code`,
'Download',
'Cancel'
)
if (selected === 'Download') {
//TODO can i use the python script?
}
}
}
}

View file

@ -1,6 +1,7 @@
import * as vscode from 'vscode'
import * as vscodeLang from 'vscode-languageclient'
import * as path from 'path'
import { Config, configChangeHandler } from './config'
export function activate(context: vscode.ExtensionContext) {
const serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'))
@ -19,12 +20,17 @@ export function activate(context: vscode.ExtensionContext) {
const clientOpts: vscodeLang.LanguageClientOptions = {
documentSelector: [{scheme: 'file', language: 'glsl'}],
synchronize: {
configurationSection: 'mcglsl',
//configurationSection: 'mcglsl',
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.{fsh,gsh,vsh,glsl}')
}
}
const disposable = new vscodeLang.LanguageClient('vscode-mc-shader', serverOpts, clientOpts)
const langServer = new vscodeLang.LanguageClient('vscode-mc-shader', serverOpts, clientOpts)
context.subscriptions.push(disposable.start())
configChangeHandler(langServer)
vscode.workspace.onDidChangeConfiguration((e) => {
configChangeHandler(langServer, e)
})
context.subscriptions.push(langServer.start())
}