Deriving includes path appears to be working OK. Optimized the includes regex by a factor of ~3 and made it work for relative paths too

This commit is contained in:
Noah Santschi-Cooney 2018-06-19 20:36:41 +01:00
parent 5d53c2020a
commit f4f2b9bf3e
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
5 changed files with 38 additions and 15 deletions

1
.vscode/launch.json vendored
View file

@ -17,7 +17,6 @@
"type": "node",
"request": "attach",
"name": "Attach to Server",
"address": "localhost",
"protocol": "inspector",
"port": 6009,
"sourceMaps": true,

18
.vscode/tasks.json vendored
View file

@ -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"

View file

@ -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'
}
}

View file

@ -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)
}
}

View file

@ -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}`)