diff --git a/.vscode/launch.json b/.vscode/launch.json index ded2955..133a149 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,7 +17,6 @@ "type": "node", "request": "attach", "name": "Attach to Server", - "address": "localhost", "protocol": "inspector", "port": 6009, "sourceMaps": true, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7d0916a..9c9d2fa 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -28,6 +28,12 @@ "type": "npm", "script": "watch:client", "isBackground": true, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" + }, "problemMatcher": [ "$tsc-watch" ] @@ -37,8 +43,10 @@ "script": "watch:server", "isBackground": true, "presentation": { - "reveal": "never", - "panel": "dedicated" + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" }, "problemMatcher": [ "$tsc-watch" @@ -47,6 +55,12 @@ { "label": "watch", "isBackground": true, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" + }, "dependsOn": [ "npm: watch:server", "npm: watch:client" diff --git a/server/src/config.ts b/server/src/config.ts index 6fed682..be19647 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -1,9 +1,9 @@ export class Config { - public readonly minecraftPath: string + public readonly shaderpacksPath: string public readonly glslangPath: string - constructor(mcPath: string, glslangPath: string) { - this.minecraftPath = mcPath + constructor(shaderpacksPath: string, glslangPath: string) { + this.shaderpacksPath = shaderpacksPath this.glslangPath = glslangPath || 'glslangValidator' } } \ No newline at end of file diff --git a/server/src/linter.ts b/server/src/linter.ts index 143ba19..0160df1 100644 --- a/server/src/linter.ts +++ b/server/src/linter.ts @@ -7,7 +7,7 @@ import { open } from 'fs'; const reDiag = /^(ERROR|WARNING): ([^?<>:*|"]+?):(\d+): (?:'.*?' : )?(.+)$/ const reVersion = /#version [\d]{3}/ -const reInclude = /^(?: |\t)*(?:#include) "((?:\/[\S]+)+\.(?:glsl))"$/ +const reInclude = /^(?:\s)*?(?:#include) "((?:\/?[^?<>:*|"]+?)+?\.(?:[a-zA-Z]+?))"$/ const include = '#extension GL_GOOGLE_include_directive : require' const filters = [ @@ -68,7 +68,6 @@ const replaceWord = (msg: string) => { export function preprocess(document: TextDocument, topLevel: boolean, incStack: string[]) { const lines = document.getText().split('\n').map(s => s.replace(/^\s+|\s+$/g, '')) - shaderpackRoot(document.uri) if (topLevel) { let inComment = false for (let i = 0; i < lines.length; i++) { @@ -85,7 +84,9 @@ export function preprocess(document: TextDocument, topLevel: boolean, incStack: } const includes = getIncludes(lines) - if (includes.length > 0) {} + includes.forEach((inc) => { + console.log(absPath(document.uri, inc.match[1])) + }) const root = document.uri.replace(/^file:\/\//, '').replace(path.basename(document.uri), '') //lint(path.extname(document.uri.replace(/^file:\/\//, '')), lines.join('\n'), document.uri) @@ -126,10 +127,19 @@ function getIncludes(lines: string[]): {lineNum: number, match: RegExpMatchArray .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}`) +function absPath(currFile: string, includeFile: string): string { + currFile = currFile.replace(/^file:\/\//, '') + if (!currFile.startsWith(conf.shaderpacksPath)) { + connection.window.showErrorMessage(`Shaderpacks path may not be correct. Current file is in ${currFile} but the path is set to ${conf.shaderpacksPath}`) + return + } + + if (includeFile.charAt(0) === '/') { + console.log('no') + const shaderPath = currFile.replace(conf.shaderpacksPath, '').split('/').slice(0, 3).join('/') + return path.join(conf.shaderpacksPath, shaderPath, includeFile) + } else { + console.log('hi') + return path.join(currFile, includeFile) } } \ No newline at end of file diff --git a/server/src/server.ts b/server/src/server.ts index 1c64555..938747d 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -40,7 +40,7 @@ documents.onDidSave((event) => { connection.onDidChangeConfiguration((change) => { const temp = change.settings.mcglsl as Config - conf = new Config(temp['minecraftPath'], temp['glslangValidatorPath']) + conf = new Config(temp['shaderpacksPath'], temp['glslangValidatorPath']) exec(conf.glslangPath, (error) => { if (error['code'] !== 1) { connection.window.showErrorMessage(`[mc-glsl] glslangValidator not found at: ${conf.glslangPath}`)