Gonna be using seperate regex for linux and windows for error parsing. Need to investigate errors not being thrown

This commit is contained in:
Noah Santschi-Cooney 2018-06-01 00:32:01 +01:00
parent 3b4ee25a86
commit cefd0e2e67
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
3 changed files with 22 additions and 16 deletions

View file

@ -1,16 +1,18 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as os from 'os'
import { regLinuxOutput } from './linter/glslProvider'
// glslangPath: Path to glslangValidator (assumed in PATH by default)
// workDir: the directory in which all the files should be, ending in /shaders
// tmpdir: the directory into which the symlinks are stored, should be the OS's temp dir
// isWin: are we on Windows?
export class Config {
public readonly minecraftPath: string
public readonly glslangPath: string
public readonly workDir: string
public readonly tmpdir: string
public readonly isWin: boolean
public readonly outputMatch: RegExp
constructor() {
const c = vscode.workspace.getConfiguration('mcglsl')
@ -19,11 +21,13 @@ export class Config {
console.log('[MC-GLSL] temp directory root set to', path.join(os.tmpdir(), vscode.workspace.name!, 'shaders'))
this.glslangPath = c.get('glslangValidatorPath') as string
this.minecraftPath = c.get('minecraftPath') as string
this.isWin = os.platform() === 'win32'
this.tmpdir = path.join(os.tmpdir(), vscode.workspace.name!, 'shaders')
this.outputMatch = regLinuxOutput
this.workDir = path.basename(vscode.workspace.rootPath!) === 'shaders' ?
vscode.workspace.rootPath! :
path.join(vscode.workspace.rootPath!, 'shaders')
this.tmpdir = path.join(os.tmpdir(), vscode.workspace.name!, 'shaders')
this.isWin = os.platform() === 'win32'
}
public onChange(e: vscode.ConfigurationChangeEvent) {

View file

@ -1,7 +1,7 @@
import * as vscode from 'vscode'
import * as cp from 'child_process'
import * as shell from 'shelljs'
import * as path from 'path'
import { runLinter } from '../asyncSpawn'
import '../global'
import { Config } from '../config'
@ -21,9 +21,8 @@ const filters: RegExp[] = [
/\/\w*.(vert|frag)$/
]
const regSyntaxError = /(syntax error)/
const regOutputMatch = /^(WARNING|ERROR): ([.\/\\\w]+):(\d+): ((?:'[\w\W]*'){1} :[\w ]+)/
const regInclude = /^(?: |\t)*(?:#include) "((?:\/[\S]+)+\.(?:glsl))"$/
export const regLinuxOutput = /^(WARNING|ERROR): ((?:\/[^/\n]*)+\/*):(\d+): ((?:'[\w\W]*'){1} :[\w ]+)/
export default class GLSLProvider implements vscode.CodeActionProvider {
private diagnosticCollection: vscode.DiagnosticCollection // where errors/warnings/hints are pushed to be displayed
@ -80,24 +79,26 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
private filterMessages = (res: string) => res
.split('\n')
.filter(s => s.length > 1 && !this.matchesFilters(s))
.map(s => s.match(regOutputMatch))
.map(s => s.match(this.config.outputMatch))
.filter(match => match && match.length > 3)
private filterPerLine(matches: RegExpMatchArray[], document: vscode.TextDocument) {
return matches.filter(match => {
const line = document.lineAt(parseInt(match![2]))
return !(regSyntaxError.test(match[0]) && line.text.leftTrim().startsWith('#include'))
})
}
// The big boi that does all the shtuff
private lint(document: vscode.TextDocument) {
private async lint(document: vscode.TextDocument) {
if (document.languageId !== 'glsl') return
const ext = extensions[path.extname(document.fileName)]
const root = '-I'
let res = ''
const res = cp.spawnSync(this.config.glslangPath, ['-S', ext, document.uri.path]).output[1].toString()
try {
res = await runLinter(this.config.glslangPath, ['-E', '-S', ext, document.uri.path])
} catch (e) {
console.error(e)
return
}
console.log(res)
const messageMatches = this.filterMessages(res) as RegExpMatchArray[]
console.log(messageMatches)
const diags: vscode.Diagnostic[] = []

View file

@ -15,6 +15,7 @@
"eofline": false,
"member-ordering": false,
"trailing-comma": false,
"no-var-requires": false,
"max-line-length": {
"severity": "warning",
"options": [170]