mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-03 00:23:07 +00:00
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:
parent
5d53c2020a
commit
f4f2b9bf3e
5 changed files with 38 additions and 15 deletions
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -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
18
.vscode/tasks.json
vendored
|
@ -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"
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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}`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue