From 5d53c2020a4700e87ed3a4340e35bb2138f2a76e Mon Sep 17 00:00:00 2001 From: Noah Santschi-Cooney Date: Sun, 17 Jun 2018 22:40:48 +0100 Subject: [PATCH] Did something to do with includes and a stack i guess --- package.json | 4 ++-- server/src/config.ts | 4 +--- server/src/linter.ts | 51 ++++++++++++++++++++++++++++++-------------- server/src/server.ts | 6 +++--- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 1b4c5e9..3838c86 100644 --- a/package.json +++ b/package.json @@ -55,10 +55,10 @@ "default": false, "description": "Whether or not to lint while typing. Can decrease performance." }, - "mcglsl.minecraftPath": { + "mcglsl.shaderpacksPath": { "type": "string", "default": "", - "description": "Absolute path to your Minecraft installation folder. The shaderpacks folder will be derived from this." + "description": "Absolute path to your Minecraft's shaderpacks folder." } } } diff --git a/server/src/config.ts b/server/src/config.ts index 6d375fa..6fed682 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -1,11 +1,9 @@ -import { join } from 'path' - export class Config { public readonly minecraftPath: string public readonly glslangPath: string constructor(mcPath: string, glslangPath: string) { - this.minecraftPath = join(mcPath, 'shaderpacks') + this.minecraftPath = mcPath this.glslangPath = glslangPath || 'glslangValidator' } } \ No newline at end of file diff --git a/server/src/linter.ts b/server/src/linter.ts index 47dd76b..143ba19 100644 --- a/server/src/linter.ts +++ b/server/src/linter.ts @@ -1,8 +1,9 @@ import { conf, connection, documents } from './server' import './global' -import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver'; +import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver' import { exec } from 'child_process' import * as path from 'path' +import { open } from 'fs'; const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)$/ const reVersion = /#version [\d]{3}/ @@ -14,11 +15,13 @@ const filters = [ /(compilation terminated)/, ] +const files: {[uri: string]: number} = {} + const ext = { '.fsh': 'frag', '.gsh': 'geom', '.vsh': 'vert', - '.glsl': 'frag' + //'.glsl': 'frag' //excluding non standard files, need to be treated differently } const tokens: {[key: string]: string} = { @@ -63,24 +66,29 @@ const replaceWord = (msg: string) => { return msg } -export function preprocess(document: TextDocument) { +export function preprocess(document: TextDocument, topLevel: boolean, incStack: string[]) { const lines = document.getText().split('\n').map(s => s.replace(/^\s+|\s+$/g, '')) - const includes = getIncludes(lines) - let inComment = false - for (let i = 0; i < lines.length; i++) { - const line = lines[i] - if (line.includes('/*')) inComment = true - if (line.includes('*/')) inComment = false - if (line.trim().startsWith('//')) continue - if (!inComment && reVersion.test(line)) { - lines.splice(i + 1, 0, include) - break + shaderpackRoot(document.uri) + if (topLevel) { + let inComment = false + for (let i = 0; i < lines.length; i++) { + const line = lines[i] + if (line.includes('/*')) inComment = true + if (line.includes('*/')) inComment = false + if (line.trim().startsWith('//')) continue + if (!inComment && reVersion.test(line)) { + lines.splice(i + 1, 0, include) + break + } + if (i === lines.length - 1) lines.splice(0, 0, include) } - if (i === lines.length - 1) lines.splice(0, 0, include) } + const includes = getIncludes(lines) + if (includes.length > 0) {} + const root = document.uri.replace(/^file:\/\//, '').replace(path.basename(document.uri), '') - lint(path.extname(document.uri.replace(/^file:\/\//, '')), lines.join('\n'), document.uri) + //lint(path.extname(document.uri.replace(/^file:\/\//, '')), lines.join('\n'), document.uri) } function lint(extension: string, text: string, uri: string) { @@ -112,5 +120,16 @@ function prepareLine(line: string): string { } function getIncludes(lines: string[]): {lineNum: number, match: RegExpMatchArray}[] { - return lines.map((line, i) => ({num: i, line})).filter((obj) => reInclude.test(obj.line)).map((obj) => ({lineNum: obj.num, match: obj.line.match(reInclude)})) + return lines + .map((line, i) => ({num: i, line})) + .filter((obj) => reInclude.test(obj.line)) + .map((obj) => ({lineNum: obj.num, match: obj.line.match(reInclude)})) +} + +function shaderpackRoot(uri: string) { + uri = uri.replace(/^file:\/\//, '') + console.log(uri, conf.minecraftPath, !uri.startsWith(conf.minecraftPath)) + if (!uri.startsWith(conf.minecraftPath)) { + connection.window.showErrorMessage(`Shaderpacks path may not be correct. Current file is in ${uri} but the path is set to ${conf.minecraftPath}`) + } } \ No newline at end of file diff --git a/server/src/server.ts b/server/src/server.ts index 6754dd9..1c64555 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -27,11 +27,11 @@ connection.onExit(() => { }) documents.onDidOpen((event) => { - preprocess(event.document) + preprocess(event.document, true, [event.document.uri.replace(/^file:\/\//, '')]) }) documents.onDidSave((event) => { - preprocess(event.document) + preprocess(event.document, true, [event.document.uri.replace(/^file:\/\//, '')]) }) /* documents.onDidChangeContent((change) => { @@ -46,7 +46,7 @@ connection.onDidChangeConfiguration((change) => { connection.window.showErrorMessage(`[mc-glsl] glslangValidator not found at: ${conf.glslangPath}`) return } - documents.all().forEach(preprocess); + documents.all().forEach((document) => preprocess(document, true, [document.uri.replace(/^file:\/\//, '')])); }) });