Removed file descriptor and include manager as we will hopefully be using shaderc/glslc from google which has support for includes

This commit is contained in:
Noah Santschi-Cooney 2018-05-29 23:37:45 +01:00
parent 9955958481
commit 87f76782c1
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
4 changed files with 9 additions and 85 deletions

View file

@ -1,22 +0,0 @@
import * as fs from 'fs'
import * as vscode from 'vscode'
import GLSLProvider from './linter/glslProvider'
export class DescriptorHolder {
private holder: {[path: string]: number} = {}
public add(path: vscode.Uri) {
fs.open(GLSLProvider.getTempFilePath(path.path), 'r', (err, fd) => {
this.holder[path.path] = fd
})
}
public clear = () => {
for (const path in this.holder) {
if (this.holder.hasOwnProperty(path)) {
fs.close(this.holder[path])
delete this.holder[path]
}
}
}
}

View file

@ -6,14 +6,13 @@ import * as path from 'path'
import '../global'
import { Config } from '../config'
import { glslProv } from '../extension'
import { IncludeHolder, IncludeManager } from './includeManager'
// These are used for symlinking as glslangValidator only accepts files in these formats
const extensions: { [id: string]: string } = {
'.fsh': '.frag',
'.vsh': '.vert',
'.gsh': '.geom',
'.glsl': '.frag',
'.fsh': 'frag',
'.vsh': 'vert',
'.gsh': 'geom',
'.glsl': 'frag',
}
// These will be used to filter out error messages that are irrelevant/incorrect for us
@ -36,7 +35,6 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
private diagnosticCollection: vscode.DiagnosticCollection // where errors/warnings/hints are pushed to be displayed
private config: Config
private onTypeDisposable?: vscode.Disposable
private includesHolder: IncludeHolder
constructor(subs: vscode.Disposable[]) {
this.diagnosticCollection = vscode.languages.createDiagnosticCollection()
@ -44,7 +42,6 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
subs.push(this)
this.config = new Config()
this.includesHolder = new IncludeHolder()
const c = vscode.workspace.getConfiguration('mcglsl')
if (c.get('lintOnType') as boolean) {
@ -115,14 +112,9 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
private lint(document: vscode.TextDocument) {
if (document.languageId !== 'glsl') return
this.includesHolder.add(document.uri)
this.includesHolder.get(document.uri).push()
const ext = extensions[path.extname(document.fileName)]
const linkname = path.join(this.config.tmpdir, `${path.basename(document.fileName, path.extname(document.fileName))}${extensions[path.extname(document.fileName)]}`)
this.createSymlinks(linkname, document)
const res = cp.spawnSync(this.config.glslangPath, [linkname]).output[1].toString()
const res = cp.spawnSync(this.config.glslangPath, ['-S', ext, document.uri.path]).output[1].toString()
const messageMatches = this.filterPerLine(this.filterMessages(res) as RegExpMatchArray[], document)
const diags: vscode.Diagnostic[] = []
@ -157,6 +149,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
const includes = this.findIncludes(document)
}
// Finds all lines that contain #include
private findIncludes = (document: vscode.TextDocument) => this.filter(document, line => regInclude.test(line.text))
private filter(document: vscode.TextDocument, f: (s: vscode.TextLine) => boolean): vscode.TextLine[] {
@ -167,6 +160,7 @@ export default class GLSLProvider implements vscode.CodeActionProvider {
return out
}
// Calculates the start and end character positions to underline
private calcRange(document: vscode.TextDocument, lineNum: number): vscode.Range {
const line = document.lineAt(lineNum - 1).text
const trimmed = line.leftTrim()

View file

@ -1,49 +0,0 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import GLSLProvider from './glslProvider';
export class IncludeManager {
private readonly queue: null[] = []
private readonly path: string;
constructor(path: string) {
this.path = path
}
public push() {
this.queue.push(null)
if (this.queue.length === 1) {
this.mergeFiles()
}
}
private async mergeFiles() {
while (this.queue.length > 0) {
// WIP
/* this.queue.pop()
let text = ''
console.log('yes')
await fs.readFile(GLSLProvider.getTempFilePath(this.path), (err: NodeJS.ErrnoException, data: Buffer) => {
if (err) {
resolve(err)
console.log(err)
return
}
text += data
})
console.log(text) */
}
}
}
export class IncludeHolder {
public managers: { [file: string]: IncludeManager } = {}
public add(file: vscode.Uri) {
if (!this.managers.hasOwnProperty(file.path)) {
this.managers[file.path] = new IncludeManager(file.path)
}
}
public get = (file: vscode.Uri) => this.managers[file.path]
}

View file

@ -3,6 +3,7 @@
"extends": ["tslint:recommended"],
"rules": {
"quotemark": [true, "single"],
"comment-format": false,
"semicolon": false,
"ordered-imports": false,
"object-literal-sort-keys": false,