From 80c40fc427e24ae6a2aeb009be49196698a4f8dd Mon Sep 17 00:00:00 2001 From: Noah Santschi-Cooney Date: Wed, 11 Jul 2018 00:30:50 +0100 Subject: [PATCH] -w- comments enum --- README.md | 3 +-- server/package.json | 2 +- server/src/linter.ts | 56 +++++++++++++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b1606a9..ce16861 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/server/package.json b/server/package.json index fe060b7..54072bc 100644 --- a/server/package.json +++ b/server/package.json @@ -19,5 +19,5 @@ "compile": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -p .", "watch": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -w -p .", "lint": "tslint -c ../tslint.json 'src/**/*.ts'" - } + } } diff --git a/server/src/linter.ts b/server/src/linter.ts index d15d930..97427dc 100644 --- a/server/src/linter.ts +++ b/server/src/linter.ts @@ -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,24 +108,28 @@ 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 => { - const match = line.match(reInclude) - if (line.startsWith('#line')) { - const inc = line.slice(line.indexOf('"') + 1, line.lastIndexOf('"')) - if (inc === parStack[parStack.length - 2]) { - count.pop() - parStack.pop() - } else { - parStack.push(inc) - count.push(0) + comment = isInComment(line, comment) + if (!comment) { + const match = line.match(reInclude) + if (line.startsWith('#line')) { + const inc = line.slice(line.indexOf('"') + 1, line.lastIndexOf('"')) + if (inc === parStack[parStack.length - 2]) { + count.pop() + parStack.pop() + } else { + count.push(0) + parStack.push(inc) + } + } else if (match) { + out.push({ + lineNum: count[count.length - 1], + lineNumParent: total, + parent: parStack[parStack.length - 1], + match + }) } - } else if (match) { - out.push({ - lineNum: count[count.length - 1], - lineNumParent: total, - parent: parStack[parStack.length - 1], - match - }) } count[count.length - 1]++ total++ @@ -127,6 +137,14 @@ function getIncludes(uri: string, lines: string[]) { 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()]]) - includes.forEach(obj => { - diagnostics.set(obj, []) - }) + includes.forEach(obj => diagnostics.set(obj, [])) const matches = filterMatches(out) matches.forEach((match) => {