mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-23 19:25:51 +00:00
-w- comments enum
This commit is contained in:
parent
8bf9b17efc
commit
80c40fc427
3 changed files with 39 additions and 22 deletions
|
@ -27,9 +27,8 @@ Got a feature request? Chuck it into an Issue!
|
||||||
|
|
||||||
- Visual Studio Code (v1.17.0 or higher - minimum requirement untested)
|
- 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.
|
- 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.
|
- 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?
|
- [MacOS] Not MacOS. Not that you're making MC Shaders on/for MacOS anyways...right?
|
||||||
|
|
||||||
## Extension Settings
|
## Extension Settings
|
||||||
|
|
|
@ -19,5 +19,5 @@
|
||||||
"compile": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -p .",
|
"compile": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -p .",
|
||||||
"watch": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -w -p .",
|
"watch": "installServerIntoExtension ../client ./package.json ./tsconfig.json && tsc -w -p .",
|
||||||
"lint": "tslint -c ../tslint.json 'src/**/*.ts'"
|
"lint": "tslint -c ../tslint.json 'src/**/*.ts'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,12 @@ const tokens = new Map([
|
||||||
['RIGHT_BRACE', '}'],
|
['RIGHT_BRACE', '}'],
|
||||||
])
|
])
|
||||||
|
|
||||||
|
enum Comment {
|
||||||
|
No = 0,
|
||||||
|
Single,
|
||||||
|
Multi
|
||||||
|
}
|
||||||
|
|
||||||
// TODO exclude exts not in ext
|
// TODO exclude exts not in ext
|
||||||
export function preprocess(lines: string[], docURI: string, topLevel: boolean, incStack: string[], num: number) {
|
export function preprocess(lines: string[], docURI: string, topLevel: boolean, incStack: string[], num: number) {
|
||||||
if (topLevel) {
|
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
|
const count = [0] // for each file we need to track the line number
|
||||||
let total = 0
|
let total = 0
|
||||||
const parStack = [uri] // for each include we need to track its parent
|
const parStack = [uri] // for each include we need to track its parent
|
||||||
|
let comment = Comment.No
|
||||||
lines.forEach(line => {
|
lines.forEach(line => {
|
||||||
const match = line.match(reInclude)
|
comment = isInComment(line, comment)
|
||||||
if (line.startsWith('#line')) {
|
if (!comment) {
|
||||||
const inc = line.slice(line.indexOf('"') + 1, line.lastIndexOf('"'))
|
const match = line.match(reInclude)
|
||||||
if (inc === parStack[parStack.length - 2]) {
|
if (line.startsWith('#line')) {
|
||||||
count.pop()
|
const inc = line.slice(line.indexOf('"') + 1, line.lastIndexOf('"'))
|
||||||
parStack.pop()
|
if (inc === parStack[parStack.length - 2]) {
|
||||||
} else {
|
count.pop()
|
||||||
parStack.push(inc)
|
parStack.pop()
|
||||||
count.push(0)
|
} 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]++
|
count[count.length - 1]++
|
||||||
total++
|
total++
|
||||||
|
@ -127,6 +137,14 @@ function getIncludes(uri: string, lines: string[]) {
|
||||||
return out
|
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 {
|
function absPath(currFile: string, includeFile: string): string {
|
||||||
if (!currFile.startsWith(conf.shaderpacksPath)) {
|
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}`)
|
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[]) {
|
function lint(uri: string, lines: string[], includes: string[]) {
|
||||||
|
//console.log(lines.join('\n'))
|
||||||
|
//return
|
||||||
let out: string = ''
|
let out: string = ''
|
||||||
try {
|
try {
|
||||||
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(uri))}`, {input: lines.join('\n')})
|
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>()]])
|
const diagnostics = new Map([[uri, Array<Diagnostic>()]])
|
||||||
includes.forEach(obj => {
|
includes.forEach(obj => diagnostics.set(obj, []))
|
||||||
diagnostics.set(obj, [])
|
|
||||||
})
|
|
||||||
|
|
||||||
const matches = filterMatches(out)
|
const matches = filterMatches(out)
|
||||||
matches.forEach((match) => {
|
matches.forEach((match) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue