Skip to content

Commit 5fe911e

Browse files
committed
More lines bs. Big heck and darnit
1 parent c3acbcb commit 5fe911e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-mc-shader",
33
"displayName": "Minecraft GLSL Shaders",
44
"description": "A Visual Studio Code extension for linting/etc Minecraft GLSL Shaders",
5-
"version": "0.8.4",
5+
"version": "0.8.5",
66
"publisher": "Strum355",
77
"author": "Noah Santschi-Cooney (Strum355)",
88
"license": "MIT",

server/src/linter.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ const errorFilters = [
2222
/(No code generated)/,
2323
/(compilation terminated)/,
2424
/Could not process include directive for header name:/,
25-
/global const initializers must be constant/,
26-
]
27-
28-
const codeFilters = [
29-
/#extension GL_EXT_gpu_shader4 : require/,
3025
]
3126

3227
export const includeGraph = new Graph()
@@ -154,10 +149,10 @@ function processIncludes(lines: string[], incStack: string[], allIncludes: Set<I
154149

155150
function getIncludes(uri: string, lines: string[]) {
156151
const lineInfo: LinesProcessingInfo = {
157-
total: -1,
152+
total: 0,
158153
comment: Comment.State.No,
159154
parStack: [uri],
160-
count: [-1],
155+
count: [0],
161156
}
162157

163158
return lines.reduce<Map<string, IncludeObj>>((out, line, i) => processLine(out, line, lines, i, lineInfo), new Map())
@@ -180,11 +175,12 @@ function processLine(includes: Map<string, IncludeObj>, line: string, lines: str
180175

181176
if (line.startsWith('#line')) {
182177
const inc = line.slice(line.indexOf('"') + 1, line.lastIndexOf('"'))
178+
if (inc.length + 1 === line.length) lines[i] = ''
183179
if (inc === linesInfo.parStack[linesInfo.parStack.length - 2]) {
184180
linesInfo.count.pop()
185181
linesInfo.parStack.pop()
186182
} else {
187-
linesInfo.count.push(-1)
183+
linesInfo.count.push(0)
188184
linesInfo.parStack.push(inc)
189185
}
190186
return includes
@@ -197,8 +193,8 @@ function processLine(includes: Map<string, IncludeObj>, line: string, lines: str
197193
formatURI(absPath(linesInfo.parStack[linesInfo.parStack.length - 1], match[1])),
198194
{
199195
path: formatURI(absPath(linesInfo.parStack[linesInfo.parStack.length - 1], match[1])),
200-
lineNum: linesInfo.count[linesInfo.count.length - 1],
201-
lineNumTopLevel: linesInfo.total,
196+
lineNum: linesInfo.count[linesInfo.count.length - 1] - 1,
197+
lineNumTopLevel: linesInfo.total - 1,
202198
parent: formatURI(linesInfo.parStack[linesInfo.parStack.length - 1]),
203199
match
204200
}
@@ -260,11 +256,11 @@ function mergeInclude(inc: IncludeObj, lines: string[], incStack: string[], diag
260256
// merge the lines of the file into the current document
261257
lines.splice(inc.lineNumTopLevel + 1, 0, ...dataLines)
262258
// add the closing #line indicating we're re-entering a block a level up
263-
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum} "${inc.parent}"`)
259+
lines.splice(inc.lineNumTopLevel + 1 + dataLines.length, 0, `#line ${inc.lineNum + 1} "${inc.parent}"`)
264260
}
265261

266262
function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
267-
lines.forEach((l, i) => {if (codeFilters.some(r => r.test(l))) lines[i] = ''})
263+
//console.log(lines.join('\n'))
268264

269265
let out: string = ''
270266
try {
@@ -282,20 +278,25 @@ function lint(docURI: string, lines: string[], diagnostics: Map<string, Diagnost
282278

283279
diagnostics.forEach((diags, uri) => {
284280
if (diags.length === 0) return
285-
linterLog.info(() => `found ${diags.length} error(s) for ${trimPath(uri)}`)
281+
const errors = diags.filter(d => d.severity === DiagnosticSeverity.Error)
282+
const warnings = diags.filter(d => d.severity === DiagnosticSeverity.Warning)
283+
linterLog.info(() => `found ${errors.length} error(s) and ${warnings.length} warning(s) for ${trimPath(uri)}`)
286284
})
287285

288286
const diagsList = daigsArray(diagnostics)
289287

290288
if (diagsList.filter(d => d.diag.length > 0).length === 0) linterLog.info(() => 'no errors found')
291289

290+
//console.log(JSON.stringify(diagsList.filter(d => d.diag.length > 0), null, 2))
291+
292292
diagsList.forEach(d => {
293293
if (win) d.uri = d.uri.replace('file://C:', 'file:///c%3A')
294294
connection.sendDiagnostics({uri: d.uri, diagnostics: d.diag})
295295
})
296296
}
297297

298298
function processErrors(out: string, docURI: string, diagnostics: Map<string, Diagnostic[]>, hasDirective: boolean) {
299+
linterLog.debug(() => out.split('\n').filter(s => s.length > 2).join('\n'))
299300
filterMatches(out).forEach(match => {
300301
const error: ErrorMatch = {
301302
type: errorType(match[1]),
@@ -308,9 +309,9 @@ function processErrors(out: string, docURI: string, diagnostics: Map<string, Dia
308309

309310
const diag: Diagnostic = {
310311
severity: error.type,
311-
range: calcRange(error.line, fileName),
312-
//range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
313-
message: `Line ${error.line + 1} ${replaceWords(error.msg)}`,
312+
//range: calcRange(error.line - 1, fileName),
313+
range: calcRange(error.line - ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1), fileName),
314+
message: `Line ${error.line + ((!hasDirective && includeGraph.get(fileName).parents.size === 0) ? 2 : 1)} ${replaceWords(error.msg)}`,
314315
source: 'mc-glsl'
315316
}
316317

@@ -353,7 +354,7 @@ const filterMatches = (output: string) => output
353354
.filter(match => match && match.length === 5)
354355

355356
function calcRange(lineNum: number, uri: string): Range {
356-
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum + 1}`)
357+
linterLog.debug(() => `calculating range for ${trimPath(uri)} at L${lineNum + 1}, index ${lineNum}`)
357358

358359
const lines = getDocumentContents(uri).split('\n')
359360
const line = lines[Math.min(Math.max(lineNum, 0), lines.length - 1)]

0 commit comments

Comments
 (0)