From ef643d8cdba3fa3ab2a54be8852ebf7addeccde2 Mon Sep 17 00:00:00 2001 From: Noah Santschi-Cooney Date: Fri, 15 Jun 2018 22:59:59 +0100 Subject: [PATCH] Proper errors if glslangValidator isnt found, woop --- server/src/config.ts | 6 +++--- server/src/linter.ts | 3 +-- server/src/server.ts | 17 +++++++++-------- server/tslint.json | 1 + 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/server/src/config.ts b/server/src/config.ts index 6d375fa..73c454d 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -1,11 +1,11 @@ import { join } from 'path' export class Config { - public readonly minecraftPath: string - public readonly glslangPath: string + public minecraftPath: string + public glslangValidatorPath: string constructor(mcPath: string, glslangPath: string) { this.minecraftPath = join(mcPath, 'shaderpacks') - this.glslangPath = glslangPath || 'glslangValidator' + this.glslangValidatorPath = glslangPath || 'glslangValidator' } } \ No newline at end of file diff --git a/server/src/linter.ts b/server/src/linter.ts index bd2282f..f709a10 100644 --- a/server/src/linter.ts +++ b/server/src/linter.ts @@ -75,8 +75,7 @@ export function preprocess(document: TextDocument) { } function lint(text: string, uri: string) { - const child = exec(`${conf.glslangPath} --stdin -S frag`, (error, out, err) => { - if (error) return + const child = exec(`${conf.glslangValidatorPath} --stdin -S frag`, (error, out, err) => { const diagnostics: Diagnostic[] = [] const matches = filterMatches(out) as RegExpMatchArray[] matches.forEach((match) => { diff --git a/server/src/server.ts b/server/src/server.ts index bbb7e20..c5e99da 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -2,7 +2,7 @@ import * as vsclang from 'vscode-languageserver' import { Config } from './config' import { completions } from './completionProvider'; import { preprocess } from './linter'; -import { stat } from 'fs'; +import { exec } from 'child_process'; export const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process)); @@ -32,17 +32,18 @@ documents.onDidSave((event) => { /* documents.onDidChangeContent((change) => { preprocess(change.document); -}); - */ +});*/ + connection.onDidChangeConfiguration((change) => { const temp = change.settings.mcglsl as Config - conf = new Config(temp.minecraftPath, temp.glslangPath) - stat(conf.glslangPath, (error) => { - if (error) { - connection.window.showErrorMessage('glslangValidator not found') + conf = new Config(temp.minecraftPath, temp.glslangValidatorPath) + exec(conf.glslangValidatorPath, (error) => { + if (error['code'] !== 1) { + connection.window.showErrorMessage(`[mc-glsl] glslangValidator not found at: ${conf.glslangValidatorPath}`) + return } + documents.all().forEach(preprocess); }) - documents.all().forEach(preprocess); }); connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams): vsclang.CompletionItem[] => { diff --git a/server/tslint.json b/server/tslint.json index f2c4a5a..512c445 100644 --- a/server/tslint.json +++ b/server/tslint.json @@ -7,6 +7,7 @@ "semicolon": false, "ordered-imports": false, "object-literal-sort-keys": false, + "no-string-literal": false, "interface-name": false, "indent": [true, "spaces", 2], "arrow-parens": false,