mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-08-31 05:47:22 +00:00
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:
parent
9955958481
commit
87f76782c1
4 changed files with 9 additions and 85 deletions
|
@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
|
|
|
@ -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]
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
"extends": ["tslint:recommended"],
|
||||
"rules": {
|
||||
"quotemark": [true, "single"],
|
||||
"comment-format": false,
|
||||
"semicolon": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue