Skip to content

Commit 8e572c5

Browse files
committed
Working on integrating the include graph properly. Need to make some changes including possibly storing line nums for each include. Was currently only deal with some includes as if they only have one parent. wut ze fuk
1 parent c953677 commit 8e572c5

File tree

5 files changed

+45
-30
lines changed

5 files changed

+45
-30
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@
7878
"@types/node": "^8.0.0",
7979
"concurrently": "^3.5.1",
8080
"tslint": "^5.10.0",
81-
"typescript": "2.8.3"
81+
"typescript": "^3.0.1"
8282
}
8383
}

server/src/config.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ export const onConfigChange = async (change) => {
2323
const temp = change.settings.mcglsl as Config
2424
conf = {shaderpacksPath: temp['shaderpacksPath'].replace(/\\/g, '/'), glslangPath: temp['glslangValidatorPath'].replace(/\\/g, '/')}
2525

26-
if (!execSync(conf.glslangPath).toString().startsWith('Usage')) {
27-
documents.all().forEach(onEvent)
28-
} else {
29-
promptDownloadGlslang()
26+
try {
27+
if (!execSync(conf.glslangPath).toString().startsWith('Usage')) {
28+
documents.all().forEach(onEvent)
29+
} else {
30+
promptDownloadGlslang()
31+
}
32+
} catch (e) {
33+
if ((e.stdout.toString() as string).startsWith('Usage')) {
34+
documents.all().forEach(onEvent)
35+
} else {
36+
promptDownloadGlslang()
37+
}
3038
}
3139
}
3240

server/src/linter.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function preprocess(lines: string[], docURI: string) {
9494
allIncludes.forEach(inc => allFiles.add(inc.path))
9595

9696
const includeMap = new Map<string, IncludeObj>(allIncludes.map(obj => [obj.path, obj]) as [string, IncludeObj][])
97-
97+
9898
lint(docURI, lines, includeMap, diagnostics)
9999
}
100100

@@ -159,7 +159,8 @@ export function getIncludes(uri: string, lines: string[]) {
159159
}
160160

161161
function ifInvalidFile(inc: IncludeObj, lines: string[], incStack: string[], diagnostics: Map<string, Diagnostic[]>) {
162-
const range = calcRange(inc.lineNumTopLevel - (win ? 1 : 0), incStack[0])
162+
const file = incStack[incStack.length - 1]
163+
const range = calcRange(inc.lineNum - (win ? 1 : 0), file)
163164
diagnostics.set(
164165
inc.parent,
165166
[
@@ -173,6 +174,8 @@ function ifInvalidFile(inc: IncludeObj, lines: string[], incStack: string[], dia
173174
]
174175
)
175176
lines[inc.lineNumTopLevel] = ''
177+
// TODO fill in the actual data
178+
propogateDiagnostic(file, 'ERROR', inc.lineNum.toString(), `${inc.path.replace(conf.shaderpacksPath, '')} is missing or an invalid file.`, diagnostics, null)
176179
}
177180

178181
function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
@@ -210,16 +213,16 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
210213
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum + 1} "${inc.parent}"`)
211214
}
212215

213-
function lint(uri: string, lines: string[], includes: Map<string, IncludeObj>, diagnostics: Map<string, Diagnostic[]>) {
216+
function lint(docURI: string, lines: string[], includes: Map<string, IncludeObj>, diagnostics: Map<string, Diagnostic[]>) {
214217
console.log(lines.join('\n'))
215218
let out: string = ''
216219
try {
217-
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(uri))}`, {input: lines.join('\n')})
220+
execSync(`${conf.glslangPath} --stdin -S ${ext.get(path.extname(docURI))}`, {input: lines.join('\n')})
218221
} catch (e) {
219222
out = e.stdout.toString()
220223
}
221224

222-
if (!diagnostics.has(uri)) diagnostics.set(uri, [])
225+
if (!diagnostics.has(docURI)) diagnostics.set(docURI, [])
223226
includes.forEach(obj => {
224227
if (!diagnostics.has(obj.path)) diagnostics.set(obj.path, [])
225228
})
@@ -229,28 +232,15 @@ function lint(uri: string, lines: string[], includes: Map<string, IncludeObj>, d
229232
let diag: Diagnostic = {
230233
severity: errorType(type),
231234
// had to do - 2 here instead of - 1, windows only perhaps?
232-
range: calcRange(parseInt(line) - (win ? 2 : 1), file.length - 1 ? file : uri),
235+
range: calcRange(parseInt(line) - (win ? 2 : 1), file.length - 1 ? file : docURI),
233236
message: `Line ${line} ${replaceWords(msg)}`,
234237
source: 'mc-glsl'
235238
}
236239

237-
diagnostics.get(file.length - 1 ? file : uri).push(diag)
240+
diagnostics.get(file.length - 1 ? file : docURI).push(diag)
238241

239242
// if is an include, highlight an error in the parents line of inclusion
240-
let nextFile = file
241-
while (nextFile !== '0' && nextFile !== uri) {
242-
// TODO what if we dont know the top level parent? Feel like thats a non-issue given that we have uri
243-
diag = {
244-
severity: errorType(type),
245-
range: calcRange(includes.get(nextFile).lineNum, includes.get(nextFile).parent),
246-
message: `Line ${line} ${includes.get(file).path.replace(conf.shaderpacksPath, '')} ${replaceWords(msg)}`,
247-
source: 'mc-glsl'
248-
}
249-
250-
diagnostics.get(includes.get(nextFile).parent).push(diag)
251-
252-
nextFile = includes.get(nextFile).parent
253-
}
243+
propogateDiagnostic(file, type, line, msg, diagnostics, includes)
254244
})
255245

256246
daigsArray(diagnostics).forEach(d => {
@@ -259,6 +249,23 @@ function lint(uri: string, lines: string[], includes: Map<string, IncludeObj>, d
259249
})
260250
}
261251

252+
function propogateDiagnostic(errorFile: string, type: string, line: string, msg: string, diagnostics: Map<string, Diagnostic[]>, includes: Map<string, IncludeObj>) {
253+
let nextFile = errorFile
254+
while (nextFile !== '0') {
255+
// TODO this doesnt deal with the fact that an include can have multiple parents :(
256+
const diag = {
257+
severity: errorType(type),
258+
range: calcRange(includes.get(nextFile).lineNum, includes.get(nextFile).parent),
259+
message: `Line ${line} ${includes.get(errorFile).path.replace(conf.shaderpacksPath, '')} ${replaceWords(msg)}`,
260+
source: 'mc-glsl'
261+
}
262+
263+
diagnostics.get(includes.get(nextFile).parent).push(diag)
264+
265+
nextFile = includes.get(nextFile).parent
266+
}
267+
}
268+
262269
export const replaceWords = (msg: string) => Array.from(tokens.entries()).reduce((acc, [key, value]) => acc.replace(key, value), msg)
263270

264271
const errorType = (error: string) => error === 'ERROR' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning

server/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vsclang from 'vscode-languageserver'
22
import * as vsclangproto from 'vscode-languageserver-protocol'
33
import { completions } from './completionProvider'
4-
import { preprocess, ext, includeToParent, includeGraph } from './linter'
4+
import { preprocess, ext, includeGraph } from './linter'
55
import { extname } from 'path'
66

77
const reVersion = /#version [\d]{3}/

0 commit comments

Comments
 (0)