-w- comments enum

This commit is contained in:
Noah Santschi-Cooney 2018-07-11 00:30:50 +01:00
parent 8bf9b17efc
commit 80c40fc427
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
3 changed files with 39 additions and 22 deletions

View file

@ -27,9 +27,8 @@ Got a feature request? Chuck it into an Issue!
- Visual Studio Code (v1.17.0 or higher - minimum requirement untested)
- The [Shader languages support for VS Code](https://marketplace.visualstudio.com/items?itemName=slevesque.shader) extension. This should automatically install when you install this extension.
- That the shader you're editing is in the `shaderpacks` folder in `.minecraft`.
- That the shader(s) you're editing are in the `shaderpacks` folder in `.minecraft`.
- The [OpenGL / OpenGL ES Reference Compiler](https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang/Install/) (for convenience, put it in your PATH, this is the assumed location if not specified). If, for some reason, you're using MacOS, there are no pre-compiled binaries of this.
- [Windows] An up to date version of Windows with Developer mode enabled for symlink support. (May not always work, I've gotten inconsistent results).
- [MacOS] Not MacOS. Not that you're making MC Shaders on/for MacOS anyways...right?
## Extension Settings

View file

@ -50,6 +50,12 @@ const tokens = new Map([
['RIGHT_BRACE', '}'],
])
enum Comment {
No = 0,
Single,
Multi
}
// TODO exclude exts not in ext
export function preprocess(lines: string[], docURI: string, topLevel: boolean, incStack: string[], num: number) {
if (topLevel) {
@ -102,7 +108,10 @@ function getIncludes(uri: string, lines: string[]) {
const count = [0] // for each file we need to track the line number
let total = 0
const parStack = [uri] // for each include we need to track its parent
let comment = Comment.No
lines.forEach(line => {
comment = isInComment(line, comment)
if (!comment) {
const match = line.match(reInclude)
if (line.startsWith('#line')) {
const inc = line.slice(line.indexOf('"') + 1, line.lastIndexOf('"'))
@ -110,8 +119,8 @@ function getIncludes(uri: string, lines: string[]) {
count.pop()
parStack.pop()
} else {
parStack.push(inc)
count.push(0)
parStack.push(inc)
}
} else if (match) {
out.push({
@ -121,12 +130,21 @@ function getIncludes(uri: string, lines: string[]) {
match
})
}
}
count[count.length - 1]++
total++
})
return out
}
function isInComment(line: string, state: Comment): Comment {
const indexOf = line.indexOf('#include')
if (indexOf > -1 && line.indexOf('//') < indexOf) {
return Comment.No
}
return Comment.No
}
function absPath(currFile: string, includeFile: string): string {
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}`)
@ -142,6 +160,8 @@ function absPath(currFile: string, includeFile: string): string {
}
function lint(uri: string, lines: string[], includes: string[]) {
//console.log(lines.join('\n'))
//return
let out: string = ''
try {
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(uri))}`, {input: lines.join('\n')})
@ -150,9 +170,7 @@ function lint(uri: string, lines: string[], includes: string[]) {
}
const diagnostics = new Map([[uri, Array<Diagnostic>()]])
includes.forEach(obj => {
diagnostics.set(obj, [])
})
includes.forEach(obj => diagnostics.set(obj, []))
const matches = filterMatches(out)
matches.forEach((match) => {