diff --git a/src/fileDescriptors.ts b/src/fileDescriptors.ts deleted file mode 100644 index 8c24b2e..0000000 --- a/src/fileDescriptors.ts +++ /dev/null @@ -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] - } - } - } -} \ No newline at end of file diff --git a/src/linter/glslProvider.ts b/src/linter/glslProvider.ts index a78d903..c72c968 100644 --- a/src/linter/glslProvider.ts +++ b/src/linter/glslProvider.ts @@ -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() diff --git a/src/linter/includeManager.ts b/src/linter/includeManager.ts deleted file mode 100644 index ef90c89..0000000 --- a/src/linter/includeManager.ts +++ /dev/null @@ -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] -} \ No newline at end of file diff --git a/tslint.json b/tslint.json index 759ba4a..6aa4cc8 100644 --- a/tslint.json +++ b/tslint.json @@ -3,6 +3,7 @@ "extends": ["tslint:recommended"], "rules": { "quotemark": [true, "single"], + "comment-format": false, "semicolon": false, "ordered-imports": false, "object-literal-sort-keys": false,