REJOICE FOR LINTING WORKS. Just no includes support yet

This commit is contained in:
Noah Santschi-Cooney 2018-06-10 21:35:23 +01:00
parent 7775b75411
commit 87759b4b2d
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
6 changed files with 77 additions and 17 deletions

View file

@ -17,7 +17,8 @@
"compile:server": "cd server && npm run installServer && cd .. && tsc -p server/tsconfig.json",
"watch:client": "tsc -w -p client/tsconfig.json",
"watch:server": "cd server && npm run installServer && cd .. && tsc -w -p server/tsconfig.json",
"lint": "cd server && npm run lint && cd ../client && npm run lint"
"lint": "cd server && npm run lint && cd ../client && npm run lint",
"fix": "tslint -c server/tslint.json --fix server/src/**/*.ts && tslint -c client/tslint.json --fix client/src/**/*.ts"
},
"devDependencies": {
"@types/node": "^7.0.43",

View file

@ -6,10 +6,6 @@ export class Config {
constructor(mcPath: string, glslangPath: string) {
this.minecraftPath = join(mcPath, 'shaderpacks')
this.glslangPath = glslangPath
}
public onChange(c: Config) {
Object.assign(this, c)
this.glslangPath = glslangPath || 'glslangValidator'
}
}

16
server/src/global.ts Normal file
View file

@ -0,0 +1,16 @@
declare global {
interface String {
leftTrim: () => string
rightTrim: () => string
}
}
String.prototype.leftTrim = function(): string {
return this.replace(/^\s+/,'')
}
String.prototype.rightTrim = function(): string {
return this.replace(/\s+$/, '')
}
export {}

View file

@ -1,6 +1,54 @@
import * as vsclang from 'vscode-languageserver'
import { conf } from './server'
import { conf, connection, documents } from './server'
import './global'
import { TextDocument, Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver';
import { exec } from 'child_process'
export function preprocess(document: vsclang.TextDocument) {
return
const reDiag = /(ERROR|WARNING): (?:\d):(\d+): '(?:.*)' : (.+)/
const filters = [
/(No code generated)/,
/(compilation terminated)/,
]
const matchesFilters = (s: string) => filters.some(reg => reg.test(s))
const filterMatches = (output: string) => output
.split('\n')
.filter(s => s.length > 1 && !matchesFilters(s))
.map(s => s.match(reDiag))
.filter(match => match && match.length === 4)
export function preprocess(document: TextDocument) {
if (conf.minecraftPath === 'shaderpacks') return
//const root = document.uri.replace(/^file:\/\//, '').replace(conf.minecraftPath, '').replace(path.basename(document.uri), '')
lint(document.getText(), document.uri)
}
function lint(text: string, uri: string) {
const child = exec(`${conf.glslangPath} --stdin -S frag`, (error, out, err) => {
const diagnostics: Diagnostic[] = []
const matches = filterMatches(out) as RegExpMatchArray[]
matches.forEach((match) => {
const [type, line, msg] = match.slice(1)
diagnostics.push({
severity: type === 'ERROR' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,
range: calcRange(parseInt(line), uri),
message: msg,
source: 'mc-glsl'
})
})
connection.sendDiagnostics({uri, diagnostics})
})
child.stdin.write(text)
child.stdin.end()
}
function calcRange(lineNum: number, uri: string): Range {
const line = documents.get(uri).getText().split('\n')[lineNum - 1]
return Range.create(lineNum - 1, line.length - line.leftTrim().length, lineNum - 1, prepareLine(line).length)
}
function prepareLine(line: string): string {
return line.slice(0, line.indexOf('//')).rightTrim()
}

View file

@ -3,13 +3,13 @@ import { Config } from './config'
import { completions } from './completionProvider';
import { preprocess } from './linter';
const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process));
export const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process));
const documents = new vsclang.TextDocuments();
export const documents = new vsclang.TextDocuments();
documents.listen(connection);
export const conf = new Config('', '')
export let conf = new Config('', '')
connection.onInitialize((params): vsclang.InitializeResult => {
return {
@ -27,7 +27,8 @@ documents.onDidChangeContent((change) => {
});
connection.onDidChangeConfiguration((change) => {
conf.onChange(change.settings.mcglsl as Config)
const temp = change.settings.mcglsl as Config
conf = new Config(temp.minecraftPath, temp.glslangPath)
documents.all().forEach(preprocess);
});

View file

@ -8,9 +8,7 @@
],
"sourceMap": true,
"rootDir": "src",
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true
"strict": true
},
"exclude": [
"node_modules",