mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-04 09:00:18 +00:00
Doing more on the extension side and splitting up the lang server linting more
This commit is contained in:
parent
d7d41985ef
commit
cacfbe7a4e
6 changed files with 120 additions and 40 deletions
39
client/src/config.ts
Normal file
39
client/src/config.ts
Normal 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?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue